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