]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.same/1.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / std / concepts / concepts.lang / concept.same / 1.cc
CommitLineData
a945c346 1// Copyright (C) 2019-2024 Free Software Foundation, Inc.
cfc219ae
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
d4ac20b0 18// { dg-do compile { target c++20 } }
cfc219ae
JW
19
20#include <concepts>
21
22static_assert( std::same_as<int, int> );
23static_assert( !std::same_as<int&, int> );
24static_assert( !std::same_as<int, int&> );
25static_assert( !std::same_as<int&&, int&> );
26static_assert( !std::same_as<const int, int> );
27static_assert( std::same_as<const int, const int> );
28
29struct A { };
30static_assert( std::same_as<A, A> );
31static_assert( !std::same_as<A, const A> );
32static_assert( std::same_as<A const, const A> );
33static_assert( !std::same_as<volatile A, const A> );
34
35struct B : A { };
36static_assert( !std::same_as<A, B> );
37
38template<typename T, typename U>
39 constexpr int
40 check_subsumption()
41 { return 0; }
42
43template<typename T, typename U>
44 requires std::same_as<T, U>
45 constexpr int
46 check_subsumption()
47 { return 1; }
48
49template<typename T, typename U>
50 requires std::same_as<U, T> && std::is_const_v<T>
51 constexpr int
52 check_subsumption()
53 { return 2; }
54
55template<typename T, typename U>
56 requires std::same_as<U, T> && std::is_volatile_v<T>
57 constexpr int
58 check_subsumption()
59 { return 3; }
60
61static_assert( check_subsumption<short, long>() == 0 );
62static_assert( check_subsumption<unsigned, unsigned>() == 1 );
63// These will be ambiguous if same_as<T,U> doesn't subsume same_as<U,T>:
64static_assert( check_subsumption<const char, const char>() == 2 );
65static_assert( check_subsumption<volatile int, volatile int>() == 3 );