summaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/libstdc++-prettyprinters/shared_ptr.cc
blob: bc2c9c5277f379c8ccf384af394de0e629cbe5fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// { dg-do run }
// { dg-options "-std=gnu++11 -g -O0" }

// Copyright (C) 2012-2016 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3.  If not see
// <http://www.gnu.org/licenses/>.

#include <memory>
#include <iostream>

template<class T>
void
placeholder(const T &s)
{
  std::cout << s;
}

template<class T>
void
use(const T &p)
{
  placeholder(&p);
}

struct deleter { void operator()(int*) {} };

std::shared_ptr<int> make(uintptr_t p)
{
  return std::shared_ptr<int>(reinterpret_cast<int*>(p), deleter());
}

int
main()
{
  typedef std::shared_ptr<int> shared;
  typedef std::weak_ptr<int> weak;

  shared esp;
// { dg-final { note-test esp "std::shared_ptr (empty) 0x0" } }
  weak ewp1;
// { dg-final { note-test ewp1 "std::weak_ptr (empty) 0x0" } }
  weak ewp2 = esp;
// { dg-final { note-test ewp2 "std::weak_ptr (empty) 0x0" } }

  shared sp1 = make(0x12345678);
  shared sp2 = sp1;
// { dg-final { note-test sp1 "std::shared_ptr (count 2, weak 0) 0x12345678" } }

  shared sp3 = make(0x12344321);
  weak sp4 = sp3;
  weak wp1 = sp3;
// { dg-final { note-test wp1 "std::weak_ptr (count 1, weak 2) 0x12344321" } }

  shared sp5 = make(0x56788765);
  weak wp2 = sp5;
  sp5.reset();
// { dg-final { note-test wp2 "std::weak_ptr (expired, weak 1) 0x56788765" } }

  placeholder(""); // Mark SPOT
  use(esp);
  use(ewp1);
  use(ewp2);
  use(sp1);
  use(wp1);
  use(wp2);

  return 0;
}

// { dg-final { gdb-test SPOT } }