]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.assignable/1.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / std / concepts / concepts.lang / concept.assignable / 1.cc
1 // Copyright (C) 2019-2021 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 <concepts>
22
23 static_assert( !std::assignable_from<void, void> );
24 static_assert( !std::assignable_from<void*, int*> );
25 static_assert( std::assignable_from<void*&, int*> );
26 static_assert( !std::assignable_from<void*&, const int*> );
27 static_assert( std::assignable_from<const void*&, const int*> );
28 static_assert( !std::assignable_from<char, char> );
29 static_assert( std::assignable_from<char&, char> );
30 static_assert( !std::assignable_from<float, float> );
31 static_assert( std::assignable_from<float&, double> );
32 static_assert( std::assignable_from<int*&, int*> );
33 static_assert( std::assignable_from<int&, int&> );
34 static_assert( std::assignable_from<int&, int&&> );
35 static_assert( !std::assignable_from<int&&, int> );
36 static_assert( !std::assignable_from<const int&, int> );
37 static_assert( !std::assignable_from<const int&, int&> );
38 static_assert( !std::assignable_from<const int&, const int> );
39 static_assert( !std::assignable_from<const int&, const int&> );
40 static_assert( !std::assignable_from<int(&)[], int(&)[]> );
41 static_assert( !std::assignable_from<int(&)[], int> );
42 static_assert( !std::assignable_from<int(&)[2], int(&)[2]> );
43 static_assert( !std::assignable_from<int(), int()> );
44 static_assert( !std::assignable_from<int(*)(), int(*)()> );
45 static_assert( std::assignable_from<int(*&)(), int(*)()> );
46 static_assert( std::assignable_from<int(*&)(), std::nullptr_t> );
47 static_assert( std::assignable_from<int(*&)(), int(*)() noexcept> );
48 static_assert( std::assignable_from<int(*&)(), int(&)() noexcept> );
49 static_assert( !std::assignable_from<int(&)(), std::nullptr_t> );
50 static_assert( !std::assignable_from<int(&)(), int(&)() noexcept> );
51
52 enum E { };
53 static_assert( !std::assignable_from<E, E> );
54 static_assert( std::assignable_from<E&, E> );
55 static_assert( std::assignable_from<E&, E&> );
56 static_assert( std::assignable_from<E&, const E&> );
57 static_assert( !std::assignable_from<const E&, const E&> );
58 enum class CE { };
59 static_assert( !std::assignable_from<CE, CE> );
60 static_assert( std::assignable_from<CE&, CE&> );
61 static_assert( std::assignable_from<CE&, const CE&> );
62 static_assert( !std::assignable_from<const CE&, const CE&> );
63 struct A { };
64 static_assert( !std::assignable_from<A, A> );
65 static_assert( std::assignable_from<A&, A> );
66 static_assert( !std::assignable_from<A, A&> );
67 static_assert( std::assignable_from<A&, const A&> );
68 union B { };
69 static_assert( !std::assignable_from<B, B> );
70 static_assert( std::assignable_from<B&, B> );
71 static_assert( !std::assignable_from<B, B&> );
72 static_assert( std::assignable_from<B&, const B&> );
73
74 struct C
75 {
76 C(int) { }
77 C& operator=(const C&) { return *this; }
78 C& operator=(int) { return *this; }
79 void operator=(void*) { }
80 };
81 static_assert( std::assignable_from<C&, C> );
82 static_assert( std::assignable_from<C&, const C&> );
83 static_assert( std::assignable_from<C&, int> );
84 static_assert( !std::assignable_from<C&, void*> );
85 static_assert( !std::assignable_from<C&, std::nullptr_t> );