]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/20_util/shared_ptr/comparison/cmp_c++20.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 20_util / shared_ptr / comparison / cmp_c++20.cc
CommitLineData
a945c346 1// Copyright (C) 2020-2024 Free Software Foundation, Inc.
f5fa62ed
JW
2//
3// This file is part of the GNU ISO C++ Library. This library is free
4// software; you can redistribute it and/or modify it under the
5// terms of the GNU General Public License as published by the
6// Free Software Foundation; either version 3, or (at your option)
7// any later version.
8
9// This library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License along
15// with this library; see the file COPYING3. If not see
16// <http://www.gnu.org/licenses/>.
17
6d0b43f5 18// { dg-do run { target c++20 } }
7cc9022f 19// { dg-require-effective-target hosted }
f5fa62ed
JW
20
21#include <memory>
22#include <testsuite_hooks.h>
23
24void
25test01()
26{
27 std::shared_ptr<int> p0, p00;
28 VERIFY( p0 == p00 );
29 VERIFY( !(p0 < p00) );
30 VERIFY( !(p0 > p00) );
31 VERIFY( p0 <= p00 );
32 VERIFY( p0 >= p00 );
33 VERIFY( std::is_eq(p0 <=> p00) );
34
35 std::shared_ptr<int> p1(new int(1));
36 VERIFY( p1 == p1 );
37 VERIFY( !(p1 < p1) );
38 VERIFY( !(p1 > p1) );
39 VERIFY( p1 <= p1 );
40 VERIFY( p1 >= p1 );
41 VERIFY( std::is_eq(p1 <=> p1) );
42
43 std::shared_ptr<int> p11 = p1;
44 VERIFY( p11 == p1 );
45 VERIFY( !(p11 < p1) );
46 VERIFY( !(p11 > p1) );
47 VERIFY( p11 <= p1 );
48 VERIFY( p11 >= p1 );
49 VERIFY( std::is_eq(p11 <=> p1) );
50
51 std::shared_ptr<const int> p2(new int(1));
52 VERIFY( p1 >= p1 );
53 VERIFY( p1 != p2 );
54 VERIFY( (p1 < p2) || (p1 > p2) );
55 VERIFY( (p1 <= p2) || (p1 >= p2) );
56 VERIFY( std::is_neq(p1 <=> p2) );
57
58 VERIFY( p1 != p0 );
59 VERIFY( !(p1 < p0) );
60 VERIFY( p1 > p0 );
61 VERIFY( !(p1 <= p0) );
62 VERIFY( p1 >= p0 );
63 VERIFY( std::is_gt(p1 <=> p0) );
64 VERIFY( std::is_lt(p0 <=> p1) );
65}
66
67void
68test02()
69{
70 std::shared_ptr<int> p0;
71 VERIFY( p0 == nullptr );
72 VERIFY( !(p0 < nullptr) );
73 VERIFY( !(p0 > nullptr) );
74 VERIFY( p0 <= nullptr );
75 VERIFY( p0 >= nullptr );
76 VERIFY( std::is_eq(p0 <=> nullptr) );
77
78 VERIFY( nullptr == p0 );
79 VERIFY( !(nullptr < p0) );
80 VERIFY( !(nullptr > p0) );
81 VERIFY( nullptr <= p0 );
82 VERIFY( nullptr >= p0 );
83 VERIFY( std::is_eq(nullptr <=> p0) );
84
85 std::shared_ptr<int> p1(new int(1));
86 VERIFY( p1 != nullptr );
87 VERIFY( !(p1 < nullptr) );
88 VERIFY( p1 > nullptr );
89 VERIFY( !(p1 <= nullptr) );
90 VERIFY( p1 >= nullptr );
91 VERIFY( std::is_gt(p1 <=> nullptr) );
92
93 VERIFY( nullptr != p1 );
94 VERIFY( nullptr < p1 );
95 VERIFY( !(nullptr > p1) );
96 VERIFY( nullptr <= p1 );
97 VERIFY( !(nullptr >= p1) );
98 VERIFY( std::is_lt(nullptr <=> p1) );
99}
100
101int
102main()
103{
104 test01();
105 test02();
106}