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=(pair&& p) const;
19 #include "test_macros.h"
20 #include "copy_move_types.h"
23 // is_assignable<const first_type&, first_type> is true and
24 // is_assignable<const second_type&, second_type> is true.
27 static_assert(std::is_assignable_v
<const std::pair
<int&&, int&&>&,
28 std::pair
<int&&, int&&>&&>);
29 static_assert(!std::is_assignable_v
<const std::pair
<int, int>&,
30 std::pair
<int, int>&&>);
31 static_assert(!std::is_assignable_v
<const std::pair
<int, int&&>&,
32 std::pair
<int, int&&>&&>);
33 static_assert(!std::is_assignable_v
<const std::pair
<int&&, int>&,
34 std::pair
<int&&, int>&&>);
36 static_assert(std::is_assignable_v
<const std::pair
<ConstMoveAssign
, ConstMoveAssign
>&,
37 std::pair
<ConstMoveAssign
, ConstMoveAssign
>&&>);
38 static_assert(!std::is_assignable_v
<const std::pair
<MoveAssign
, MoveAssign
>&,
39 std::pair
<MoveAssign
, MoveAssign
>&&>);
43 constexpr bool test() {
50 std::pair
<int&&, double&&> p1
{std::move(i1
), std::move(d1
)};
51 const std::pair
<int&&, double&&> p2
{std::move(i2
), std::move(d2
)};
53 assert(p2
.first
== 1);
54 assert(p2
.second
== 3.0);
57 // user defined const move assignment
59 std::pair
<ConstMoveAssign
, ConstMoveAssign
> p1
{1, 2};
60 const std::pair
<ConstMoveAssign
, ConstMoveAssign
> 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
.constMoveAssign
== 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());