]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/20_util/shared_ptr/observers/owner_before.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 20_util / shared_ptr / observers / owner_before.cc
CommitLineData
4415f7a5 1// { dg-options "-std=gnu++11" }
8dd5e93a 2
5624e564 3// Copyright (C) 2008-2015 Free Software Foundation, Inc.
8dd5e93a
JW
4//
5// This file is part of the GNU ISO C++ Library. This library is free
6// software; you can redistribute it and/or modify it under the
7// terms of the GNU General Public License as published by the
748086b7 8// Free Software Foundation; either version 3, or (at your option)
8dd5e93a
JW
9// any later version.
10
11// This library is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15
16// You should have received a copy of the GNU General Public License along
748086b7
JJ
17// with this library; see the file COPYING3. If not see
18// <http://www.gnu.org/licenses/>.
8dd5e93a
JW
19
20// 20.8.13.2 Template class shared_ptr [util.smartptr.shared]
21
22#include <memory>
23#include <testsuite_hooks.h>
24
25struct A
26{
27 int i;
28 virtual ~A() { }
29};
30
31struct B : A
32{
33};
34
35// 20.6.6.2.5 shared_ptr observers [util.smartptr.shared.obs]
36
37void
38test01()
39{
40 bool test __attribute__((unused)) = true;
41
42 // test empty shared_ptrs compare equivalent
43 std::shared_ptr<A> p1;
44 std::shared_ptr<B> p2;
45 VERIFY( !p1.owner_before(p2) && !p2.owner_before(p1) );
46}
47
48
49// Construction from pointer
50void
51test02()
52{
53 bool test __attribute__((unused)) = true;
54
55 std::shared_ptr<A> a0;
56
57 std::shared_ptr<A> a1(new A);
58 VERIFY( a1.owner_before(a0) || a0.owner_before(a1) );
59 VERIFY( !(a1.owner_before(a0) && a0.owner_before(a1)) );
60
61 std::shared_ptr<B> b1(new B);
62 VERIFY( a1.owner_before(b1) || b1.owner_before(a1) );
63 VERIFY( !(a1.owner_before(b1) && b1.owner_before(a1)) );
64
65 std::shared_ptr<A> a2(a1);
66 VERIFY( !a1.owner_before(a2) && !a2.owner_before(a1) );
67 a2 = b1;
68 VERIFY( !b1.owner_before(a2) && !a2.owner_before(b1) );
69
70 std::weak_ptr<A> w1(a1);
71 VERIFY( !a1.owner_before(w1) && !w1.owner_before(a1) );
72 std::weak_ptr<A> w2(a2);
73 VERIFY( !b1.owner_before(w2) && !w2.owner_before(b1) );
74}
75
76// Aliasing
77void
78test03()
79{
80 bool test __attribute__((unused)) = true;
81
82 std::shared_ptr<A> p1(new A());
83 std::shared_ptr<int> p2(p1, &p1->i);
84 VERIFY( !p1.owner_before(p2) && !p2.owner_before(p1) );
85}
86
87int
88main()
89{
90 test01();
91 test02();
92 test03();
93 return 0;
94}