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 // constexpr const pair& operator=(const pair& p) const;
19 #include "test_macros.h"
20 #include "copy_move_types.h"
23 // is_copy_assignable<const first_type> is true and
24 // is_copy_assignable<const second_type> is true.
27 static_assert(std::is_assignable_v
<const std::pair
<int&, int&>&,
28 const std::pair
<int&, int&>&>);
29 static_assert(!std::is_assignable_v
<const std::pair
<int, int>&,
30 const std::pair
<int, int>&>);
31 static_assert(!std::is_assignable_v
<const std::pair
<int, int&>&,
32 const std::pair
<int, int&>&>);
33 static_assert(!std::is_assignable_v
<const std::pair
<int&, int>&,
34 const std::pair
<int&, int>&>);
36 static_assert(std::is_assignable_v
<const std::pair
<ConstCopyAssign
, ConstCopyAssign
>&,
37 const std::pair
<ConstCopyAssign
, ConstCopyAssign
>&>);
38 static_assert(!std::is_assignable_v
<const std::pair
<CopyAssign
, CopyAssign
>&,
39 const std::pair
<CopyAssign
, CopyAssign
>&>);
43 constexpr bool test() {
50 const std::pair
<int&, double&> p1
{i1
, d1
};
51 const std::pair
<int&, double&> p2
{i2
, d2
};
53 assert(p2
.first
== 1);
54 assert(p2
.second
== 3.0);
57 // user defined const copy assignment
59 const std::pair
<ConstCopyAssign
, ConstCopyAssign
> p1
{1, 2};
60 const std::pair
<ConstCopyAssign
, ConstCopyAssign
> p2
{3, 4};
62 assert(p2
.first
.val
== 1);
63 assert(p2
.second
.val
== 2);
66 // The correct assignment operator of the underlying type is used
68 std::pair
<TracedAssignment
, const TracedAssignment
> t1
{};
69 const std::pair
<TracedAssignment
, const TracedAssignment
> t2
{};
71 assert(t2
.first
.constCopyAssign
== 1);
72 assert(t2
.second
.constCopyAssign
== 1);
78 int main(int, char**) {
80 // gcc cannot have mutable member in constant expression
81 #if !defined(TEST_COMPILER_GCC)
82 static_assert(test());