]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/unique_ptr/cons/lwg2905.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 20_util / unique_ptr / cons / lwg2905.cc
1 // Copyright (C) 2017-2023 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++11 } }
19
20 #include <memory>
21
22 template<typename T, typename D, typename P, typename E>
23 constexpr bool check()
24 { return std::is_constructible<std::unique_ptr<T, D>, P, E>::value; }
25
26 struct Del { void operator()(void*) const { } };
27
28 static_assert( ! check<int, Del&, int*, Del>(), "" );
29 static_assert( check<int, Del&, int*, Del&>(), "" );
30 static_assert( check<int, const Del&, int*, Del&>(), "" );
31 static_assert( ! check<int, Del&, int*, const Del&>(), "" );
32 static_assert( check<int, Del, int*, const Del&>(), "" );
33 static_assert( check<int, Del, int*, Del>(), "" );
34
35 static_assert( ! check<int[], Del&, int*, Del>(), "" );
36 static_assert( check<int[], Del&, int*, Del&>(), "" );
37 static_assert( check<int[], const Del&, int*, Del&>(), "" );
38 static_assert( ! check<int[], Del&, int*, const Del&>(), "" );
39 static_assert( check<int[], Del, int*, const Del&>(), "" );
40 static_assert( check<int[], Del, int*, Del>(), "" );
41
42 struct DelNoCopy {
43 DelNoCopy() = default;
44 DelNoCopy(const DelNoCopy&) = delete;
45 DelNoCopy(DelNoCopy&&) = default;
46 void operator()(void*) const { }
47 };
48
49 static_assert( ! check<int, DelNoCopy&, int*, DelNoCopy>(), "" );
50 static_assert( check<int, DelNoCopy&, int*, DelNoCopy&>(), "" );
51 static_assert( check<int, const DelNoCopy&, int*, DelNoCopy&>(), "" );
52 static_assert( ! check<int, DelNoCopy&, int*, const DelNoCopy&>(), "" );
53 static_assert( ! check<int, DelNoCopy, int*, const DelNoCopy&>(), "" );
54 static_assert( check<int, DelNoCopy, int*, DelNoCopy>(), "" );
55
56 static_assert( ! check<int[], DelNoCopy&, int*, DelNoCopy>(), "" );
57 static_assert( check<int[], DelNoCopy&, int*, DelNoCopy&>(), "" );
58 static_assert( check<int[], const DelNoCopy&, int*, DelNoCopy&>(), "" );
59 static_assert( ! check<int[], DelNoCopy&, int*, const DelNoCopy&>(), "" );
60 static_assert( ! check<int[], DelNoCopy, int*, const DelNoCopy&>(), "" );
61 static_assert( check<int[], DelNoCopy, int*, DelNoCopy>(), "" );
62
63 struct Base { virtual ~Base() { } };
64 struct Derived : Base { };
65
66 static_assert( ! check<Base[], Del&, Base*, Del>(), "" );
67 static_assert( check<Base[], Del&, Base*, Del&>(), "" );
68 static_assert( check<Base[], const Del&, Base*, Del&>(), "" );
69 static_assert( ! check<Base[], Del&, Base*, const Del&>(), "" );
70 static_assert( check<Base[], Del, Base*, const Del&>(), "" );
71 static_assert( check<Base[], Del, Base*, Del>(), "" );
72
73 static_assert( ! check<Base[], Del&, Derived*, Del>(), "" );
74 static_assert( ! check<Base[], Del&, Derived*, Del&>(), "" );
75 static_assert( ! check<Base[], const Del&, Derived*, Del&>(), "" );
76 static_assert( ! check<Base[], Del&, Derived*, const Del&>(), "" );
77 static_assert( ! check<Base[], Del, Derived*, const Del&>(), "" );
78 static_assert( ! check<Base[], Del, Derived*, Del>(), "" );