]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/20_util/weak_ptr/observers/owner_before.cc
Add random numbers and fix some bugs.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 20_util / weak_ptr / observers / owner_before.cc
CommitLineData
52066eae 1// { dg-do run { target c++11 } }
7cc9022f 2// { dg-require-effective-target hosted }
8dd5e93a 3
a945c346 4// Copyright (C) 2008-2024 Free Software Foundation, Inc.
8dd5e93a
JW
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
748086b7 9// Free Software Foundation; either version 3, or (at your option)
8dd5e93a
JW
10// any later version.
11
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.
16
17// You should have received a copy of the GNU General Public License along
748086b7
JJ
18// with this library; see the file COPYING3. If not see
19// <http://www.gnu.org/licenses/>.
8dd5e93a
JW
20
21// 20.8.13.3 Template class weak_ptr [util.smartptr.weak]
22
23#include <memory>
24#include <testsuite_hooks.h>
25
26struct A { };
27struct B { };
28
29// 20.6.6.3.5 weak_ptr observers [util.smartptr.weak.obs]
30
d08606ce 31void
8dd5e93a
JW
32test01()
33{
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) );
38
39 std::shared_ptr<B> p3;
40 VERIFY( !p1.owner_before(p3) && !p3.owner_before(p1) );
41
d08606ce
JW
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)), "" );
8dd5e93a
JW
46}
47
48
d08606ce 49void
8dd5e93a
JW
50test02()
51{
52 std::shared_ptr<A> a0;
53 std::weak_ptr<A> w0(a0);
54
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) );
58
59 VERIFY( w1.owner_before(w0) || w0.owner_before(w1) );
60 VERIFY( !(w1.owner_before(w0) && w0.owner_before(w1)) );
61
62 VERIFY( w1.owner_before(a0) || a0.owner_before(w1) );
63 VERIFY( !(w1.owner_before(a0) && a0.owner_before(w1)) );
64
65 std::shared_ptr<B> b1(new B);
66 VERIFY( w1.owner_before(b1) || b1.owner_before(w1) );
8dd5e93a
JW
67}
68
69int
70main()
71{
72 test01();
73 test02();
74 return 0;
75}