1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14, c++17
12 // concept copy_constructible;
15 #include <type_traits>
17 #include "type_classification/moveconstructible.h"
19 // Tests in this namespace are shared with moveconstructible.pass.cpp
20 // There are some interesting differences, so it's best if they're tested here
22 namespace MoveConstructibleTests
{
23 static_assert(std::copy_constructible
<int>);
24 static_assert(std::copy_constructible
<int*>);
25 static_assert(std::copy_constructible
<int&>);
26 static_assert(std::copy_constructible
<const int>);
27 static_assert(std::copy_constructible
<const int&>);
28 static_assert(std::copy_constructible
<volatile int>);
29 static_assert(std::copy_constructible
<volatile int&>);
30 static_assert(std::copy_constructible
<int (*)()>);
31 static_assert(std::copy_constructible
<int (&)()>);
32 static_assert(std::copy_constructible
<HasDefaultOps
>);
33 static_assert(std::copy_constructible
<const CustomMoveCtor
&>);
34 static_assert(std::copy_constructible
<volatile CustomMoveCtor
&>);
35 static_assert(std::copy_constructible
<const CustomMoveAssign
&>);
36 static_assert(std::copy_constructible
<volatile CustomMoveAssign
&>);
37 static_assert(std::copy_constructible
<int HasDefaultOps::*>);
38 static_assert(std::copy_constructible
<void (HasDefaultOps::*)(int)>);
39 static_assert(std::copy_constructible
<MemberLvalueReference
>);
41 static_assert(!std::copy_constructible
<void>);
42 static_assert(!std::copy_constructible
<CustomMoveAssign
>);
43 static_assert(!std::copy_constructible
<const CustomMoveCtor
>);
44 static_assert(!std::copy_constructible
<volatile CustomMoveCtor
>);
45 static_assert(!std::copy_constructible
<const CustomMoveAssign
>);
46 static_assert(!std::copy_constructible
<volatile CustomMoveAssign
>);
47 static_assert(!std::copy_constructible
<int[10]>);
48 static_assert(!std::copy_constructible
<DeletedMoveCtor
>);
49 static_assert(!std::copy_constructible
<ImplicitlyDeletedMoveCtor
>);
50 static_assert(!std::copy_constructible
<DeletedMoveAssign
>);
51 static_assert(!std::copy_constructible
<ImplicitlyDeletedMoveAssign
>);
53 static_assert(std::copy_constructible
<DeletedMoveCtor
&>);
54 static_assert(std::copy_constructible
<const DeletedMoveCtor
&>);
55 static_assert(std::copy_constructible
<ImplicitlyDeletedMoveCtor
&>);
56 static_assert(std::copy_constructible
<const ImplicitlyDeletedMoveCtor
&>);
57 static_assert(std::copy_constructible
<DeletedMoveAssign
&>);
58 static_assert(std::copy_constructible
<const DeletedMoveAssign
&>);
59 static_assert(std::copy_constructible
<ImplicitlyDeletedMoveAssign
&>);
60 static_assert(std::copy_constructible
<const ImplicitlyDeletedMoveAssign
&>);
62 // different to moveconstructible.pass.cpp
63 static_assert(!std::copy_constructible
<int&&>);
64 static_assert(!std::copy_constructible
<const int&&>);
65 static_assert(!std::copy_constructible
<volatile int&&>);
66 static_assert(!std::copy_constructible
<CustomMoveCtor
>);
67 static_assert(!std::copy_constructible
<MoveOnly
>);
68 static_assert(!std::copy_constructible
<const CustomMoveCtor
&&>);
69 static_assert(!std::copy_constructible
<volatile CustomMoveCtor
&&>);
70 static_assert(!std::copy_constructible
<const CustomMoveAssign
&&>);
71 static_assert(!std::copy_constructible
<volatile CustomMoveAssign
&&>);
72 static_assert(!std::copy_constructible
<DeletedMoveCtor
&&>);
73 static_assert(!std::copy_constructible
<const DeletedMoveCtor
&&>);
74 static_assert(!std::copy_constructible
<ImplicitlyDeletedMoveCtor
&&>);
75 static_assert(!std::copy_constructible
<const ImplicitlyDeletedMoveCtor
&&>);
76 static_assert(!std::copy_constructible
<DeletedMoveAssign
&&>);
77 static_assert(!std::copy_constructible
<const DeletedMoveAssign
&&>);
78 static_assert(!std::copy_constructible
<ImplicitlyDeletedMoveAssign
&&>);
79 static_assert(!std::copy_constructible
<const ImplicitlyDeletedMoveAssign
&&>);
80 static_assert(!std::copy_constructible
<MemberRvalueReference
>);
81 } // namespace MoveConstructibleTests
83 namespace CopyConstructibleTests
{
84 struct CopyCtorUserDefined
{
85 CopyCtorUserDefined(CopyCtorUserDefined
&&) noexcept
= default;
86 CopyCtorUserDefined(const CopyCtorUserDefined
&);
88 static_assert(std::copy_constructible
<CopyCtorUserDefined
>);
90 struct CopyAssignUserDefined
{
91 CopyAssignUserDefined
& operator=(CopyAssignUserDefined
&&) noexcept
= default;
92 CopyAssignUserDefined
& operator=(const CopyAssignUserDefined
&);
94 static_assert(!std::copy_constructible
<CopyAssignUserDefined
>);
96 struct CopyCtorAndAssignUserDefined
{
97 CopyCtorAndAssignUserDefined(CopyCtorAndAssignUserDefined
&&) noexcept
=
99 CopyCtorAndAssignUserDefined(const CopyCtorAndAssignUserDefined
&);
100 CopyCtorAndAssignUserDefined
&
101 operator=(CopyCtorAndAssignUserDefined
&&) noexcept
= default;
102 CopyCtorAndAssignUserDefined
& operator=(const CopyCtorAndAssignUserDefined
&);
104 static_assert(std::copy_constructible
<CopyCtorAndAssignUserDefined
>);
106 struct CopyCtorDeleted
{
107 CopyCtorDeleted(CopyCtorDeleted
&&) noexcept
= default;
108 CopyCtorDeleted(const CopyCtorDeleted
&) = delete;
110 static_assert(!std::copy_constructible
<CopyCtorDeleted
>);
112 struct CopyAssignDeleted
{
113 CopyAssignDeleted(CopyAssignDeleted
&&) noexcept
= default;
114 CopyAssignDeleted(const CopyAssignDeleted
&) = delete;
116 static_assert(!std::copy_constructible
<CopyAssignDeleted
>);
118 struct CopyCtorHasMutableRef
{
119 CopyCtorHasMutableRef(CopyCtorHasMutableRef
&&) noexcept
= default;
120 CopyCtorHasMutableRef(CopyCtorHasMutableRef
&) = default;
122 static_assert(!std::copy_constructible
<CopyCtorHasMutableRef
>);
124 struct CopyCtorProhibitsMutableRef
{
125 CopyCtorProhibitsMutableRef(CopyCtorProhibitsMutableRef
&&) noexcept
= default;
126 CopyCtorProhibitsMutableRef(const CopyCtorProhibitsMutableRef
&) = default;
127 CopyCtorProhibitsMutableRef(CopyCtorProhibitsMutableRef
&) = delete;
129 static_assert(!std::copy_constructible
<CopyCtorProhibitsMutableRef
>);
131 struct CopyAssignHasMutableRef
{
132 CopyAssignHasMutableRef
&
133 operator=(CopyAssignHasMutableRef
&&) noexcept
= default;
134 CopyAssignHasMutableRef
& operator=(CopyAssignHasMutableRef
&) = default;
136 static_assert(!std::copy_constructible
<CopyAssignHasMutableRef
>);
138 struct CopyAssignProhibitsMutableRef
{
139 CopyAssignProhibitsMutableRef
&
140 operator=(CopyAssignProhibitsMutableRef
&&) noexcept
= default;
141 CopyAssignProhibitsMutableRef
&
142 operator=(const CopyAssignProhibitsMutableRef
&) = default;
143 CopyAssignProhibitsMutableRef
&
144 operator=(CopyAssignProhibitsMutableRef
&) = delete;
146 static_assert(!std::copy_constructible
<CopyAssignProhibitsMutableRef
>);
148 struct CopyCtorOnly
{
149 CopyCtorOnly(CopyCtorOnly
&&) noexcept
= delete;
150 CopyCtorOnly(const CopyCtorOnly
&) = default;
152 static_assert(!std::copy_constructible
<CopyCtorOnly
>);
154 struct CopyAssignOnly
{
155 CopyAssignOnly
& operator=(CopyAssignOnly
&&) noexcept
= delete;
156 CopyAssignOnly
& operator=(const CopyAssignOnly
&) = default;
158 static_assert(!std::copy_constructible
<CopyAssignOnly
>);
161 CopyOnly(CopyOnly
&&) noexcept
= delete;
162 CopyOnly(const CopyOnly
&) = default;
164 CopyOnly
& operator=(CopyOnly
&&) noexcept
= delete;
165 CopyOnly
& operator=(const CopyOnly
&) = default;
167 static_assert(!std::copy_constructible
<CopyOnly
>);
169 struct ExplicitlyCopyable
{
170 ExplicitlyCopyable(ExplicitlyCopyable
&&) = default;
171 explicit ExplicitlyCopyable(const ExplicitlyCopyable
&);
173 static_assert(!std::copy_constructible
<ExplicitlyCopyable
>);
174 } // namespace CopyConstructibleTests