]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/shared_ptr/comparison/cmp_c++20.cc
1 // Copyright (C) 2020-2023 Free Software Foundation, Inc.
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)
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.
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/>.
18 // { dg-options "-std=gnu++2a" }
19 // { dg-do run { target c++2a } }
20 // { dg-require-effective-target hosted }
23 #include <testsuite_hooks.h>
28 std::shared_ptr
<int> p0
, p00
;
30 VERIFY( !(p0
< p00
) );
31 VERIFY( !(p0
> p00
) );
34 VERIFY( std::is_eq(p0
<=> p00
) );
36 std::shared_ptr
<int> p1(new int(1));
42 VERIFY( std::is_eq(p1
<=> p1
) );
44 std::shared_ptr
<int> p11
= p1
;
46 VERIFY( !(p11
< p1
) );
47 VERIFY( !(p11
> p1
) );
50 VERIFY( std::is_eq(p11
<=> p1
) );
52 std::shared_ptr
<const int> p2(new int(1));
55 VERIFY( (p1
< p2
) || (p1
> p2
) );
56 VERIFY( (p1
<= p2
) || (p1
>= p2
) );
57 VERIFY( std::is_neq(p1
<=> p2
) );
62 VERIFY( !(p1
<= p0
) );
64 VERIFY( std::is_gt(p1
<=> p0
) );
65 VERIFY( std::is_lt(p0
<=> p1
) );
71 std::shared_ptr
<int> p0
;
72 VERIFY( p0
== nullptr );
73 VERIFY( !(p0
< nullptr) );
74 VERIFY( !(p0
> nullptr) );
75 VERIFY( p0
<= nullptr );
76 VERIFY( p0
>= nullptr );
77 VERIFY( std::is_eq(p0
<=> nullptr) );
79 VERIFY( nullptr == p0
);
80 VERIFY( !(nullptr < p0
) );
81 VERIFY( !(nullptr > p0
) );
82 VERIFY( nullptr <= p0
);
83 VERIFY( nullptr >= p0
);
84 VERIFY( std::is_eq(nullptr <=> p0
) );
86 std::shared_ptr
<int> p1(new int(1));
87 VERIFY( p1
!= nullptr );
88 VERIFY( !(p1
< nullptr) );
89 VERIFY( p1
> nullptr );
90 VERIFY( !(p1
<= nullptr) );
91 VERIFY( p1
>= nullptr );
92 VERIFY( std::is_gt(p1
<=> nullptr) );
94 VERIFY( nullptr != p1
);
95 VERIFY( nullptr < p1
);
96 VERIFY( !(nullptr > p1
) );
97 VERIFY( nullptr <= p1
);
98 VERIFY( !(nullptr >= p1
) );
99 VERIFY( std::is_lt(nullptr <=> p1
) );