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