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 //===----------------------------------------------------------------------===//
13 // template <class T1, class T2> struct pair
15 // pair& operator=(pair const& p);
21 #include "test_macros.h"
22 #include "archetypes.h"
27 TEST_CONSTEXPR_CXX20
CountAssign() = default;
28 TEST_CONSTEXPR_CXX20 CountAssign
& operator=(CountAssign
const&) {
32 TEST_CONSTEXPR_CXX20 CountAssign
& operator=(CountAssign
&&) {
39 extern Incomplete inc_obj
;
41 TEST_CONSTEXPR_CXX20
bool test() {
43 typedef std::pair
<ConstexprTestTypes::CopyOnly
, int> P
;
44 const P
p1(ConstexprTestTypes::CopyOnly(), short{4});
47 assert(p2
.second
== 4);
50 using P
= std::pair
<int&, int&&>;
55 P
p1(x
, std::move(y
));
56 P
p2(x2
, std::move(y2
));
58 assert(p1
.first
== x2
);
59 assert(p1
.second
== y2
);
62 using P
= std::pair
<int, ConstexprTestTypes::NonCopyable
>;
63 static_assert(!std::is_copy_assignable
<P
>::value
, "");
66 using P
= std::pair
<CountAssign
, ConstexprTestTypes::Copyable
>;
67 static_assert(std::is_copy_assignable
<P
>::value
, "");
71 assert(p
.first
.copied
== 1);
72 assert(p
.first
.moved
== 0);
73 assert(p2
.first
.copied
== 0);
74 assert(p2
.first
.moved
== 0);
77 using P
= std::pair
<int, ConstexprTestTypes::MoveAssignOnly
>;
78 static_assert(!std::is_copy_assignable
<P
>::value
, "");
81 using P
= std::pair
<int, std::unique_ptr
<int> >;
82 static_assert(!std::is_copy_assignable
<P
>::value
, "");
85 using P
= std::pair
<int, Incomplete
&>;
86 static_assert(!std::is_copy_assignable
<P
>::value
, "");
88 assert(&p
.second
== &inc_obj
);
94 int main(int, char**) {
96 #if TEST_STD_VER >= 20
97 static_assert(test());
103 struct Incomplete
{};