PR libstdc++/87278 restore support for std::make_shared<volatile T>()
[official-gcc.git] / libstdc++-v3 / testsuite / 20_util / shared_ptr / observers / owner_before.cc
blobd82d8054439b3ac9547670e2840aa8ef1cdbf1f6
1 // { dg-do run { target c++11 } }
3 // Copyright (C) 2008-2018 Free Software Foundation, Inc.
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
8 // Free Software Foundation; either version 3, or (at your option)
9 // any later version.
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.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
20 // 20.8.13.2 Template class shared_ptr [util.smartptr.shared]
22 #include <memory>
23 #include <testsuite_hooks.h>
25 struct A
27 int i;
28 virtual ~A() { }
31 struct B : A
35 // 20.6.6.2.5 shared_ptr observers [util.smartptr.shared.obs]
37 void
38 test01()
40 // test empty shared_ptrs compare equivalent
41 std::shared_ptr<A> p1;
42 std::shared_ptr<B> p2;
43 VERIFY( !p1.owner_before(p2) && !p2.owner_before(p1) );
47 // Construction from pointer
48 void
49 test02()
51 std::shared_ptr<A> a0;
53 std::shared_ptr<A> a1(new A);
54 VERIFY( a1.owner_before(a0) || a0.owner_before(a1) );
55 VERIFY( !(a1.owner_before(a0) && a0.owner_before(a1)) );
57 std::shared_ptr<B> b1(new B);
58 VERIFY( a1.owner_before(b1) || b1.owner_before(a1) );
59 VERIFY( !(a1.owner_before(b1) && b1.owner_before(a1)) );
61 std::shared_ptr<A> a2(a1);
62 VERIFY( !a1.owner_before(a2) && !a2.owner_before(a1) );
63 a2 = b1;
64 VERIFY( !b1.owner_before(a2) && !a2.owner_before(b1) );
66 std::weak_ptr<A> w1(a1);
67 VERIFY( !a1.owner_before(w1) && !w1.owner_before(a1) );
68 std::weak_ptr<A> w2(a2);
69 VERIFY( !b1.owner_before(w2) && !w2.owner_before(b1) );
71 static_assert( noexcept(a1.owner_before(a0)), "" );
72 static_assert( noexcept(a1.owner_before(b1)), "" );
73 static_assert( noexcept(b1.owner_before(a1)), "" );
74 static_assert( noexcept(a1.owner_before(w1)), "" );
75 static_assert( noexcept(b1.owner_before(w1)), "" );
78 // Aliasing
79 void
80 test03()
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) );
87 int
88 main()
90 test01();
91 test02();
92 test03();
93 return 0;