| 1 |
//===----------------------------------------------------------------------===// |
| 2 |
// |
| 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 |
| 6 |
// |
| 7 |
//===----------------------------------------------------------------------===// |
| 8 |
|
| 9 |
// UNSUPPORTED: c++03, c++11, c++14, c++17 |
| 10 |
|
| 11 |
// template<class T> |
| 12 |
// concept copy_constructible; |
| 13 |
|
| 14 |
#include <concepts> |
| 15 |
#include <type_traits> |
| 16 |
|
| 17 |
#include "type_classification/moveconstructible.h" |
| 18 |
|
| 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 |
| 21 |
// too. |
| 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>); |
| 40 |
|
| 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>); |
| 52 |
|
| 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&>); |
| 61 |
|
| 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 |
| 82 |
|
| 83 |
namespace CopyConstructibleTests { |
| 84 |
struct CopyCtorUserDefined { |
| 85 |
CopyCtorUserDefined(CopyCtorUserDefined&&) noexcept = default; |
| 86 |
CopyCtorUserDefined(const CopyCtorUserDefined&); |
| 87 |
}; |
| 88 |
static_assert(std::copy_constructible<CopyCtorUserDefined>); |
| 89 |
|
| 90 |
struct CopyAssignUserDefined { |
| 91 |
CopyAssignUserDefined& operator=(CopyAssignUserDefined&&) noexcept = default; |
| 92 |
CopyAssignUserDefined& operator=(const CopyAssignUserDefined&); |
| 93 |
}; |
| 94 |
static_assert(!std::copy_constructible<CopyAssignUserDefined>); |
| 95 |
|
| 96 |
struct CopyCtorAndAssignUserDefined { |
| 97 |
CopyCtorAndAssignUserDefined(CopyCtorAndAssignUserDefined&&) noexcept = |
| 98 |
default; |
| 99 |
CopyCtorAndAssignUserDefined(const CopyCtorAndAssignUserDefined&); |
| 100 |
CopyCtorAndAssignUserDefined& |
| 101 |
operator=(CopyCtorAndAssignUserDefined&&) noexcept = default; |
| 102 |
CopyCtorAndAssignUserDefined& operator=(const CopyCtorAndAssignUserDefined&); |
| 103 |
}; |
| 104 |
static_assert(std::copy_constructible<CopyCtorAndAssignUserDefined>); |
| 105 |
|
| 106 |
struct CopyCtorDeleted { |
| 107 |
CopyCtorDeleted(CopyCtorDeleted&&) noexcept = default; |
| 108 |
CopyCtorDeleted(const CopyCtorDeleted&) = delete; |
| 109 |
}; |
| 110 |
static_assert(!std::copy_constructible<CopyCtorDeleted>); |
| 111 |
|
| 112 |
struct CopyAssignDeleted { |
| 113 |
CopyAssignDeleted(CopyAssignDeleted&&) noexcept = default; |
| 114 |
CopyAssignDeleted(const CopyAssignDeleted&) = delete; |
| 115 |
}; |
| 116 |
static_assert(!std::copy_constructible<CopyAssignDeleted>); |
| 117 |
|
| 118 |
struct CopyCtorHasMutableRef { |
| 119 |
CopyCtorHasMutableRef(CopyCtorHasMutableRef&&) noexcept = default; |
| 120 |
CopyCtorHasMutableRef(CopyCtorHasMutableRef&) = default; |
| 121 |
}; |
| 122 |
static_assert(!std::copy_constructible<CopyCtorHasMutableRef>); |
| 123 |
|
| 124 |
struct CopyCtorProhibitsMutableRef { |
| 125 |
CopyCtorProhibitsMutableRef(CopyCtorProhibitsMutableRef&&) noexcept = default; |
| 126 |
CopyCtorProhibitsMutableRef(const CopyCtorProhibitsMutableRef&) = default; |
| 127 |
CopyCtorProhibitsMutableRef(CopyCtorProhibitsMutableRef&) = delete; |
| 128 |
}; |
| 129 |
static_assert(!std::copy_constructible<CopyCtorProhibitsMutableRef>); |
| 130 |
|
| 131 |
struct CopyAssignHasMutableRef { |
| 132 |
CopyAssignHasMutableRef& |
| 133 |
operator=(CopyAssignHasMutableRef&&) noexcept = default; |
| 134 |
CopyAssignHasMutableRef& operator=(CopyAssignHasMutableRef&) = default; |
| 135 |
}; |
| 136 |
static_assert(!std::copy_constructible<CopyAssignHasMutableRef>); |
| 137 |
|
| 138 |
struct CopyAssignProhibitsMutableRef { |
| 139 |
CopyAssignProhibitsMutableRef& |
| 140 |
operator=(CopyAssignProhibitsMutableRef&&) noexcept = default; |
| 141 |
CopyAssignProhibitsMutableRef& |
| 142 |
operator=(const CopyAssignProhibitsMutableRef&) = default; |
| 143 |
CopyAssignProhibitsMutableRef& |
| 144 |
operator=(CopyAssignProhibitsMutableRef&) = delete; |
| 145 |
}; |
| 146 |
static_assert(!std::copy_constructible<CopyAssignProhibitsMutableRef>); |
| 147 |
|
| 148 |
struct CopyCtorOnly { |
| 149 |
CopyCtorOnly(CopyCtorOnly&&) noexcept = delete; |
| 150 |
CopyCtorOnly(const CopyCtorOnly&) = default; |
| 151 |
}; |
| 152 |
static_assert(!std::copy_constructible<CopyCtorOnly>); |
| 153 |
|
| 154 |
struct CopyAssignOnly { |
| 155 |
CopyAssignOnly& operator=(CopyAssignOnly&&) noexcept = delete; |
| 156 |
CopyAssignOnly& operator=(const CopyAssignOnly&) = default; |
| 157 |
}; |
| 158 |
static_assert(!std::copy_constructible<CopyAssignOnly>); |
| 159 |
|
| 160 |
struct CopyOnly { |
| 161 |
CopyOnly(CopyOnly&&) noexcept = delete; |
| 162 |
CopyOnly(const CopyOnly&) = default; |
| 163 |
|
| 164 |
CopyOnly& operator=(CopyOnly&&) noexcept = delete; |
| 165 |
CopyOnly& operator=(const CopyOnly&) = default; |
| 166 |
}; |
| 167 |
static_assert(!std::copy_constructible<CopyOnly>); |
| 168 |
|
| 169 |
struct ExplicitlyCopyable { |
| 170 |
ExplicitlyCopyable(ExplicitlyCopyable&&) = default; |
| 171 |
explicit ExplicitlyCopyable(const ExplicitlyCopyable&); |
| 172 |
}; |
| 173 |
static_assert(!std::copy_constructible<ExplicitlyCopyable>); |
| 174 |
} // namespace CopyConstructibleTests |