Daily bump.
[official-gcc.git] / libstdc++-v3 / testsuite / 20_util / weak_ptr / observers / owner_before.cc
blobbda071809b0e7e27a4b0203762d7685ee3fd7cd3
1 // { dg-do run { target c++11 } }
2 // { dg-require-effective-target hosted }
4 // Copyright (C) 2008-2024 Free Software Foundation, Inc.
5 //
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 3, or (at your option)
10 // any later version.
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING3. If not see
19 // <http://www.gnu.org/licenses/>.
21 // 20.8.13.3 Template class weak_ptr [util.smartptr.weak]
23 #include <memory>
24 #include <testsuite_hooks.h>
26 struct A { };
27 struct B { };
29 // 20.6.6.3.5 weak_ptr observers [util.smartptr.weak.obs]
31 void
32 test01()
34 // test empty weak_ptrs compare equivalent
35 std::weak_ptr<A> p1;
36 std::weak_ptr<B> p2;
37 VERIFY( !p1.owner_before(p2) && !p2.owner_before(p1) );
39 std::shared_ptr<B> p3;
40 VERIFY( !p1.owner_before(p3) && !p3.owner_before(p1) );
42 static_assert( noexcept(p1.owner_before(p1)), "" );
43 static_assert( noexcept(p1.owner_before(p2)), "" );
44 static_assert( noexcept(p1.owner_before(p3)), "" );
45 static_assert( noexcept(p2.owner_before(p1)), "" );
49 void
50 test02()
52 std::shared_ptr<A> a0;
53 std::weak_ptr<A> w0(a0);
55 std::shared_ptr<A> a1(new A);
56 std::weak_ptr<A> w1(a1);
57 VERIFY( !a1.owner_before(w1) && !w1.owner_before(a1) );
59 VERIFY( w1.owner_before(w0) || w0.owner_before(w1) );
60 VERIFY( !(w1.owner_before(w0) && w0.owner_before(w1)) );
62 VERIFY( w1.owner_before(a0) || a0.owner_before(w1) );
63 VERIFY( !(w1.owner_before(a0) && a0.owner_before(w1)) );
65 std::shared_ptr<B> b1(new B);
66 VERIFY( w1.owner_before(b1) || b1.owner_before(w1) );
69 int
70 main()
72 test01();
73 test02();
74 return 0;