xref: /llvm-project/libcxx/test/std/concepts/concepts.object/copyable.compile.pass.cpp (revision 72f0edf3f4291d2614719a8c8af21a7a62ed5d74)
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 copyable = see below;
13*24dd2d2fSChristopher Di Bella 
14*24dd2d2fSChristopher Di Bella #include <concepts>
15*24dd2d2fSChristopher Di Bella 
16*24dd2d2fSChristopher Di Bella #include <deque>
17*24dd2d2fSChristopher Di Bella #include <forward_list>
18*24dd2d2fSChristopher Di Bella #include <list>
19*24dd2d2fSChristopher Di Bella #include <map>
20*24dd2d2fSChristopher Di Bella #include <memory>
21*24dd2d2fSChristopher Di Bella #include <optional>
22*24dd2d2fSChristopher Di Bella #include <unordered_map>
23*24dd2d2fSChristopher Di Bella #include <vector>
24*24dd2d2fSChristopher Di Bella 
25*24dd2d2fSChristopher Di Bella #include "type_classification/copyable.h"
26*24dd2d2fSChristopher Di Bella 
27*24dd2d2fSChristopher Di Bella static_assert(std::copyable<int>);
28*24dd2d2fSChristopher Di Bella static_assert(std::copyable<int volatile>);
29*24dd2d2fSChristopher Di Bella static_assert(std::copyable<int*>);
30*24dd2d2fSChristopher Di Bella static_assert(std::copyable<int const*>);
31*24dd2d2fSChristopher Di Bella static_assert(std::copyable<int volatile*>);
32*24dd2d2fSChristopher Di Bella static_assert(std::copyable<int volatile const*>);
33*24dd2d2fSChristopher Di Bella static_assert(std::copyable<int (*)()>);
34*24dd2d2fSChristopher Di Bella 
35*24dd2d2fSChristopher Di Bella struct S {};
36*24dd2d2fSChristopher Di Bella static_assert(std::copyable<S>);
37*24dd2d2fSChristopher Di Bella static_assert(std::copyable<int S::*>);
38*24dd2d2fSChristopher Di Bella static_assert(std::copyable<int (S::*)()>);
39*24dd2d2fSChristopher Di Bella static_assert(std::copyable<int (S::*)() noexcept>);
40*24dd2d2fSChristopher Di Bella static_assert(std::copyable<int (S::*)() &>);
41*24dd2d2fSChristopher Di Bella static_assert(std::copyable<int (S::*)() & noexcept>);
42*24dd2d2fSChristopher Di Bella static_assert(std::copyable<int (S::*)() &&>);
43*24dd2d2fSChristopher Di Bella static_assert(std::copyable<int (S::*)() && noexcept>);
44*24dd2d2fSChristopher Di Bella static_assert(std::copyable<int (S::*)() const>);
45*24dd2d2fSChristopher Di Bella static_assert(std::copyable<int (S::*)() const noexcept>);
46*24dd2d2fSChristopher Di Bella static_assert(std::copyable<int (S::*)() const&>);
47*24dd2d2fSChristopher Di Bella static_assert(std::copyable<int (S::*)() const & noexcept>);
48*24dd2d2fSChristopher Di Bella static_assert(std::copyable<int (S::*)() const&&>);
49*24dd2d2fSChristopher Di Bella static_assert(std::copyable<int (S::*)() const && noexcept>);
50*24dd2d2fSChristopher Di Bella static_assert(std::copyable<int (S::*)() volatile>);
51*24dd2d2fSChristopher Di Bella static_assert(std::copyable<int (S::*)() volatile noexcept>);
52*24dd2d2fSChristopher Di Bella static_assert(std::copyable<int (S::*)() volatile&>);
53*24dd2d2fSChristopher Di Bella static_assert(std::copyable<int (S::*)() volatile & noexcept>);
54*24dd2d2fSChristopher Di Bella static_assert(std::copyable<int (S::*)() volatile&&>);
55*24dd2d2fSChristopher Di Bella static_assert(std::copyable<int (S::*)() volatile && noexcept>);
56*24dd2d2fSChristopher Di Bella static_assert(std::copyable<int (S::*)() const volatile>);
57*24dd2d2fSChristopher Di Bella static_assert(std::copyable<int (S::*)() const volatile noexcept>);
58*24dd2d2fSChristopher Di Bella static_assert(std::copyable<int (S::*)() const volatile&>);
59*24dd2d2fSChristopher Di Bella static_assert(std::copyable<int (S::*)() const volatile & noexcept>);
60*24dd2d2fSChristopher Di Bella static_assert(std::copyable<int (S::*)() const volatile&&>);
61*24dd2d2fSChristopher Di Bella static_assert(std::copyable<int (S::*)() const volatile && noexcept>);
62*24dd2d2fSChristopher Di Bella 
63*24dd2d2fSChristopher Di Bella static_assert(std::copyable<std::vector<int> >);
64*24dd2d2fSChristopher Di Bella static_assert(std::copyable<std::deque<int> >);
65*24dd2d2fSChristopher Di Bella static_assert(std::copyable<std::forward_list<int> >);
66*24dd2d2fSChristopher Di Bella static_assert(std::copyable<std::list<int> >);
67*24dd2d2fSChristopher Di Bella static_assert(std::copyable<std::shared_ptr<std::unique_ptr<int> > >);
68*24dd2d2fSChristopher Di Bella static_assert(std::copyable<std::optional<std::vector<int> > >);
69*24dd2d2fSChristopher Di Bella static_assert(std::copyable<std::vector<int> >);
70*24dd2d2fSChristopher Di Bella static_assert(std::copyable<std::vector<std::unique_ptr<int> > >);
71*24dd2d2fSChristopher Di Bella 
72*24dd2d2fSChristopher Di Bella static_assert(std::copyable<has_volatile_member>);
73*24dd2d2fSChristopher Di Bella static_assert(std::copyable<has_array_member>);
74*24dd2d2fSChristopher Di Bella 
75*24dd2d2fSChristopher Di Bella // Not objects
76*24dd2d2fSChristopher Di Bella static_assert(!std::copyable<void>);
77*24dd2d2fSChristopher Di Bella static_assert(!std::copyable<int&>);
78*24dd2d2fSChristopher Di Bella static_assert(!std::copyable<int const&>);
79*24dd2d2fSChristopher Di Bella static_assert(!std::copyable<int volatile&>);
80*24dd2d2fSChristopher Di Bella static_assert(!std::copyable<int const volatile&>);
81*24dd2d2fSChristopher Di Bella static_assert(!std::copyable<int&&>);
82*24dd2d2fSChristopher Di Bella static_assert(!std::copyable<int const&&>);
83*24dd2d2fSChristopher Di Bella static_assert(!std::copyable<int volatile&&>);
84*24dd2d2fSChristopher Di Bella static_assert(!std::copyable<int const volatile&&>);
85*24dd2d2fSChristopher Di Bella static_assert(!std::copyable<int()>);
86*24dd2d2fSChristopher Di Bella static_assert(!std::copyable<int (&)()>);
87*24dd2d2fSChristopher Di Bella static_assert(!std::copyable<int[5]>);
88*24dd2d2fSChristopher Di Bella 
89*24dd2d2fSChristopher Di Bella // Not copy constructible or copy assignable
90*24dd2d2fSChristopher Di Bella static_assert(!std::copyable<std::unique_ptr<int> >);
91*24dd2d2fSChristopher Di Bella 
92*24dd2d2fSChristopher Di Bella // Not assignable
93*24dd2d2fSChristopher Di Bella static_assert(!std::copyable<int const>);
94*24dd2d2fSChristopher Di Bella static_assert(!std::copyable<int const volatile>);
95*24dd2d2fSChristopher Di Bella static_assert(std::copyable<const_copy_assignment const>);
96*24dd2d2fSChristopher Di Bella static_assert(!std::copyable<volatile_copy_assignment volatile>);
97*24dd2d2fSChristopher Di Bella static_assert(std::copyable<cv_copy_assignment const volatile>);
98*24dd2d2fSChristopher Di Bella 
99*24dd2d2fSChristopher Di Bella static_assert(!std::copyable<no_copy_constructor>);
100*24dd2d2fSChristopher Di Bella static_assert(!std::copyable<no_copy_assignment>);
101*24dd2d2fSChristopher Di Bella 
102*24dd2d2fSChristopher Di Bella static_assert(std::is_copy_assignable_v<no_copy_assignment_mutable>);
103*24dd2d2fSChristopher Di Bella static_assert(!std::copyable<no_copy_assignment_mutable>);
104*24dd2d2fSChristopher Di Bella static_assert(!std::copyable<derived_from_noncopyable>);
105*24dd2d2fSChristopher Di Bella static_assert(!std::copyable<has_noncopyable>);
106*24dd2d2fSChristopher Di Bella static_assert(!std::copyable<has_const_member>);
107*24dd2d2fSChristopher Di Bella static_assert(!std::copyable<has_cv_member>);
108*24dd2d2fSChristopher Di Bella static_assert(!std::copyable<has_lvalue_reference_member>);
109*24dd2d2fSChristopher Di Bella static_assert(!std::copyable<has_rvalue_reference_member>);
110*24dd2d2fSChristopher Di Bella static_assert(!std::copyable<has_function_ref_member>);
111*24dd2d2fSChristopher Di Bella 
112*24dd2d2fSChristopher Di Bella static_assert(
113*24dd2d2fSChristopher Di Bella     !std::assignable_from<deleted_assignment_from_const_rvalue&,
114*24dd2d2fSChristopher Di Bella                           deleted_assignment_from_const_rvalue const>);
115*24dd2d2fSChristopher Di Bella static_assert(!std::copyable<deleted_assignment_from_const_rvalue>);
116