175 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: c++03, c++11, c++14, c++1710 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.cpp20// There are some interesting differences, so it's best if they're tested here21// too.22namespace MoveConstructibleTests {23static_assert(std::copy_constructible<int>);24static_assert(std::copy_constructible<int*>);25static_assert(std::copy_constructible<int&>);26static_assert(std::copy_constructible<const int>);27static_assert(std::copy_constructible<const int&>);28static_assert(std::copy_constructible<volatile int>);29static_assert(std::copy_constructible<volatile int&>);30static_assert(std::copy_constructible<int (*)()>);31static_assert(std::copy_constructible<int (&)()>);32static_assert(std::copy_constructible<HasDefaultOps>);33static_assert(std::copy_constructible<const CustomMoveCtor&>);34static_assert(std::copy_constructible<volatile CustomMoveCtor&>);35static_assert(std::copy_constructible<const CustomMoveAssign&>);36static_assert(std::copy_constructible<volatile CustomMoveAssign&>);37static_assert(std::copy_constructible<int HasDefaultOps::*>);38static_assert(std::copy_constructible<void (HasDefaultOps::*)(int)>);39static_assert(std::copy_constructible<MemberLvalueReference>);40 41static_assert(!std::copy_constructible<void>);42static_assert(!std::copy_constructible<CustomMoveAssign>);43static_assert(!std::copy_constructible<const CustomMoveCtor>);44static_assert(!std::copy_constructible<volatile CustomMoveCtor>);45static_assert(!std::copy_constructible<const CustomMoveAssign>);46static_assert(!std::copy_constructible<volatile CustomMoveAssign>);47static_assert(!std::copy_constructible<int[10]>);48static_assert(!std::copy_constructible<DeletedMoveCtor>);49static_assert(!std::copy_constructible<ImplicitlyDeletedMoveCtor>);50static_assert(!std::copy_constructible<DeletedMoveAssign>);51static_assert(!std::copy_constructible<ImplicitlyDeletedMoveAssign>);52 53static_assert(std::copy_constructible<DeletedMoveCtor&>);54static_assert(std::copy_constructible<const DeletedMoveCtor&>);55static_assert(std::copy_constructible<ImplicitlyDeletedMoveCtor&>);56static_assert(std::copy_constructible<const ImplicitlyDeletedMoveCtor&>);57static_assert(std::copy_constructible<DeletedMoveAssign&>);58static_assert(std::copy_constructible<const DeletedMoveAssign&>);59static_assert(std::copy_constructible<ImplicitlyDeletedMoveAssign&>);60static_assert(std::copy_constructible<const ImplicitlyDeletedMoveAssign&>);61 62// different to moveconstructible.pass.cpp63static_assert(!std::copy_constructible<int&&>);64static_assert(!std::copy_constructible<const int&&>);65static_assert(!std::copy_constructible<volatile int&&>);66static_assert(!std::copy_constructible<CustomMoveCtor>);67static_assert(!std::copy_constructible<MoveOnly>);68static_assert(!std::copy_constructible<const CustomMoveCtor&&>);69static_assert(!std::copy_constructible<volatile CustomMoveCtor&&>);70static_assert(!std::copy_constructible<const CustomMoveAssign&&>);71static_assert(!std::copy_constructible<volatile CustomMoveAssign&&>);72static_assert(!std::copy_constructible<DeletedMoveCtor&&>);73static_assert(!std::copy_constructible<const DeletedMoveCtor&&>);74static_assert(!std::copy_constructible<ImplicitlyDeletedMoveCtor&&>);75static_assert(!std::copy_constructible<const ImplicitlyDeletedMoveCtor&&>);76static_assert(!std::copy_constructible<DeletedMoveAssign&&>);77static_assert(!std::copy_constructible<const DeletedMoveAssign&&>);78static_assert(!std::copy_constructible<ImplicitlyDeletedMoveAssign&&>);79static_assert(!std::copy_constructible<const ImplicitlyDeletedMoveAssign&&>);80static_assert(!std::copy_constructible<MemberRvalueReference>);81} // namespace MoveConstructibleTests82 83namespace CopyConstructibleTests {84struct CopyCtorUserDefined {85 CopyCtorUserDefined(CopyCtorUserDefined&&) noexcept = default;86 CopyCtorUserDefined(const CopyCtorUserDefined&);87};88static_assert(std::copy_constructible<CopyCtorUserDefined>);89 90struct CopyAssignUserDefined {91 CopyAssignUserDefined& operator=(CopyAssignUserDefined&&) noexcept = default;92 CopyAssignUserDefined& operator=(const CopyAssignUserDefined&);93};94static_assert(!std::copy_constructible<CopyAssignUserDefined>);95 96struct CopyCtorAndAssignUserDefined {97 CopyCtorAndAssignUserDefined(CopyCtorAndAssignUserDefined&&) noexcept =98 default;99 CopyCtorAndAssignUserDefined(const CopyCtorAndAssignUserDefined&);100 CopyCtorAndAssignUserDefined&101 operator=(CopyCtorAndAssignUserDefined&&) noexcept = default;102 CopyCtorAndAssignUserDefined& operator=(const CopyCtorAndAssignUserDefined&);103};104static_assert(std::copy_constructible<CopyCtorAndAssignUserDefined>);105 106struct CopyCtorDeleted {107 CopyCtorDeleted(CopyCtorDeleted&&) noexcept = default;108 CopyCtorDeleted(const CopyCtorDeleted&) = delete;109};110static_assert(!std::copy_constructible<CopyCtorDeleted>);111 112struct CopyAssignDeleted {113 CopyAssignDeleted(CopyAssignDeleted&&) noexcept = default;114 CopyAssignDeleted(const CopyAssignDeleted&) = delete;115};116static_assert(!std::copy_constructible<CopyAssignDeleted>);117 118struct CopyCtorHasMutableRef {119 CopyCtorHasMutableRef(CopyCtorHasMutableRef&&) noexcept = default;120 CopyCtorHasMutableRef(CopyCtorHasMutableRef&) = default;121};122static_assert(!std::copy_constructible<CopyCtorHasMutableRef>);123 124struct CopyCtorProhibitsMutableRef {125 CopyCtorProhibitsMutableRef(CopyCtorProhibitsMutableRef&&) noexcept = default;126 CopyCtorProhibitsMutableRef(const CopyCtorProhibitsMutableRef&) = default;127 CopyCtorProhibitsMutableRef(CopyCtorProhibitsMutableRef&) = delete;128};129static_assert(!std::copy_constructible<CopyCtorProhibitsMutableRef>);130 131struct CopyAssignHasMutableRef {132 CopyAssignHasMutableRef&133 operator=(CopyAssignHasMutableRef&&) noexcept = default;134 CopyAssignHasMutableRef& operator=(CopyAssignHasMutableRef&) = default;135};136static_assert(!std::copy_constructible<CopyAssignHasMutableRef>);137 138struct CopyAssignProhibitsMutableRef {139 CopyAssignProhibitsMutableRef&140 operator=(CopyAssignProhibitsMutableRef&&) noexcept = default;141 CopyAssignProhibitsMutableRef&142 operator=(const CopyAssignProhibitsMutableRef&) = default;143 CopyAssignProhibitsMutableRef&144 operator=(CopyAssignProhibitsMutableRef&) = delete;145};146static_assert(!std::copy_constructible<CopyAssignProhibitsMutableRef>);147 148struct CopyCtorOnly {149 CopyCtorOnly(CopyCtorOnly&&) noexcept = delete;150 CopyCtorOnly(const CopyCtorOnly&) = default;151};152static_assert(!std::copy_constructible<CopyCtorOnly>);153 154struct CopyAssignOnly {155 CopyAssignOnly& operator=(CopyAssignOnly&&) noexcept = delete;156 CopyAssignOnly& operator=(const CopyAssignOnly&) = default;157};158static_assert(!std::copy_constructible<CopyAssignOnly>);159 160struct 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};167static_assert(!std::copy_constructible<CopyOnly>);168 169struct ExplicitlyCopyable {170 ExplicitlyCopyable(ExplicitlyCopyable&&) = default;171 explicit ExplicitlyCopyable(const ExplicitlyCopyable&);172};173static_assert(!std::copy_constructible<ExplicitlyCopyable>);174} // namespace CopyConstructibleTests175