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 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
13 // template <class T1, class T2> struct pair
14 // template<class U1, class U2> constexpr
15 // const pair& operator=(const pair<U1, U2>& p) const;
20 #include "test_macros.h"
21 #include "copy_move_types.h"
24 // is_assignable_v<const first_type&, const U1&> is true, and
25 // is_assignable_v<const second_type&, const U2&> is true.
28 static_assert( std::is_assignable_v
<const std::pair
<int&, int&>&,
29 const std::pair
<long&, long&>&>);
30 static_assert(!std::is_assignable_v
<const std::pair
<int, int>&,
31 const std::pair
<long, long>&>);
32 static_assert(!std::is_assignable_v
<const std::pair
<int, int&>&,
33 const std::pair
<long, long&>&>);
34 static_assert(!std::is_assignable_v
<const std::pair
<int&, int>&,
35 const std::pair
<long&, long>&>);
37 static_assert(std::is_assignable_v
<
38 const std::pair
<AssignableFrom
<ConstCopyAssign
>, AssignableFrom
<ConstCopyAssign
>>&,
39 const std::pair
<ConstCopyAssign
, ConstCopyAssign
>&>);
41 static_assert(!std::is_assignable_v
<
42 const std::pair
<AssignableFrom
<CopyAssign
>, AssignableFrom
<CopyAssign
>>&,
43 const std::pair
<CopyAssign
, CopyAssign
>&>);
46 constexpr bool test() {
53 const std::pair
<int&, int&> p1
{i1
, i2
};
54 const std::pair
<long&, long&> p2
{j1
, j2
};
56 assert(p2
.first
== 1);
57 assert(p2
.second
== 2);
60 // user defined const copy assignment
62 const std::pair
<ConstCopyAssign
, ConstCopyAssign
> p1
{1, 2};
63 const std::pair
<AssignableFrom
<ConstCopyAssign
>, AssignableFrom
<ConstCopyAssign
>> p2
{3, 4};
65 assert(p2
.first
.v
.val
== 1);
66 assert(p2
.second
.v
.val
== 2);
69 // The correct assignment operator of the underlying type is used
71 std::pair
<TracedAssignment
, TracedAssignment
> t1
{};
72 const std::pair
<AssignableFrom
<TracedAssignment
>, AssignableFrom
<TracedAssignment
>> t2
{};
74 assert(t2
.first
.v
.constCopyAssign
== 1);
75 assert(t2
.second
.v
.constCopyAssign
== 1);
81 int main(int, char**) {
83 // gcc cannot have mutable member in constant expression
84 #if !defined(TEST_COMPILER_GCC)
85 static_assert(test());