]> 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-2020 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::constructible_from<void> );
24 static_assert( !std::constructible_from<void, void> );
25 static_assert( std::constructible_from<void*, int*> );
26 static_assert( !std::constructible_from<void*, const int*> );
27 static_assert( std::constructible_from<const void*, const int*> );
28 static_assert( std::constructible_from<char> );
29 static_assert( std::constructible_from<float> );
30 static_assert( std::constructible_from<float, float> );
31 static_assert( std::constructible_from<float, double> );
32 static_assert( std::constructible_from<int*> );
33 static_assert( std::constructible_from<int*, int*> );
34 static_assert( !std::constructible_from<int&> );
35 static_assert( std::constructible_from<int&, int&> );
36 static_assert( !std::constructible_from<int&&> );
37 static_assert( std::constructible_from<int&&, int> );
38 static_assert( !std::constructible_from<const int&> );
39 static_assert( std::constructible_from<const int&, int> );
40 static_assert( std::constructible_from<const int&, int&> );
41 static_assert( std::constructible_from<const int&, const int> );
42 static_assert( std::constructible_from<const int&, const int&> );
43 static_assert( !std::constructible_from<const int&, int, int> );
44 static_assert( !std::constructible_from<int[]> );
45 static_assert( std::constructible_from<int[2]> );
46 static_assert( !std::constructible_from<int()> );
47 static_assert( std::constructible_from<int(*)()> );
48 static_assert( std::constructible_from<int(*)(), std::nullptr_t> );
49 static_assert( std::constructible_from<int(*)(), int(*)() noexcept> );
50 static_assert( std::constructible_from<int(*)(), int(&)() noexcept> );
51 static_assert( !std::constructible_from<int(&)()> );
52 static_assert( std::constructible_from<int(&)(), int(&)() noexcept> );
53
54 enum E { };
55 static_assert( std::constructible_from<E> );
56 static_assert( std::constructible_from<E, E&> );
57 enum class CE { };
58 static_assert( std::constructible_from<CE> );
59 static_assert( std::constructible_from<CE, CE&> );
60 struct A { };
61 static_assert( std::constructible_from<A> );
62 static_assert( std::constructible_from<A, A> );
63 static_assert( std::constructible_from<A, A&> );
64 static_assert( std::constructible_from<A, const A&> );
65 union B { };
66 static_assert( std::constructible_from<B> );
67 static_assert( std::constructible_from<B, B> );
68 static_assert( std::constructible_from<B, B&> );
69 static_assert( std::constructible_from<B, const B&> );
70
71 struct C
72 {
73 C(void* = nullptr) { }
74 ~C() noexcept(false) { }
75 };
76 static_assert( !std::constructible_from<C> );
77 static_assert( !std::constructible_from<C, void*> );
78 static_assert( !std::constructible_from<C, std::nullptr_t> );
79
80 class D
81 {
82 public:
83 D() { }
84 D(int) { }
85 private:
86 ~D() { }
87 };
88 static_assert( !std::constructible_from<D> );
89 static_assert( !std::constructible_from<D, int> );