Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / utilities / utility / pairs / pairs.pair / assign_const_move_pair.pass.cpp
blob585d2aac0f2700c0f5a0737c2ff3557dc65ca414
1 //===----------------------------------------------------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
11 // <utility>
13 // template <class T1, class T2> struct pair
14 // constexpr const pair& operator=(pair&& p) const;
16 #include <cassert>
17 #include <utility>
19 #include "test_macros.h"
20 #include "copy_move_types.h"
22 // Constraints:
23 // is_assignable<const first_type&, first_type> is true and
24 // is_assignable<const second_type&, second_type> is true.
26 // clang-format off
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>&&>);
41 // clang-format on
43 constexpr bool test() {
44 // reference types
46 int i1 = 1;
47 int i2 = 2;
48 double d1 = 3.0;
49 double d2 = 5.0;
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)};
52 p2 = std::move(p1);
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};
61 p2 = std::move(p1);
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{};
70 t2 = std::move(t1);
71 assert(t2.first.constMoveAssign == 1);
72 assert(t2.second.constCopyAssign == 1);
75 return true;
78 int main(int, char**) {
79 test();
80 // gcc cannot have mutable member in constant expression
81 #if !defined(TEST_COMPILER_GCC)
82 static_assert(test());
83 #endif
84 return 0;