]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/18_support/comparisons/object/lwg3530.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 18_support / comparisons / object / lwg3530.cc
1 // Copyright (C) 2020-2022 Free Software Foundation, Inc.
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
18 // { dg-options "-std=gnu++2a" }
19 // { dg-do compile { target c++2a } }
20
21 #include <compare>
22
23 template<typename C, typename T, typename U>
24 concept comparable = requires (const C& cmp, const T& t, const U& u) {
25 cmp(t, u);
26 };
27
28 void
29 test01()
30 {
31 struct X
32 {
33 operator int() const { return 0; }
34 operator long*() const { return nullptr; }
35 } x;
36
37 // Not three-way-comparable because of ambiguous conversion to int or long*:
38 static_assert( ! std::three_way_comparable<X> );
39
40 // And therefore X is not three-way-comparable-with anything else
41 // (because std::three_way_comparable_with<X, Y> requires that both
42 // three_way_comparable<X> and three_way_comparable<Y> are true).
43 static_assert( ! std::three_way_comparable_with<X, long*> );
44
45 long l;
46 // But <=> is valid and resolves to a builtin operator comparing pointers:
47 [[maybe_unused]] auto c = &l <=> x;
48
49 // But LWG 3530 says std::compare_three_way should not be usable:
50 static_assert( ! comparable<std::compare_three_way, long*, X> );
51 static_assert( ! comparable<std::compare_three_way, X, long*> );
52 }