Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / utilities / utility / pairs / pairs.pair / assign_const_copy_pair.pass.cpp
blob52468bd67444a4067916564af373d4ffd9da9aa3
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=(const pair& p) const;
16 #include <cassert>
17 #include <utility>
19 #include "test_macros.h"
20 #include "copy_move_types.h"
22 // Constraints:
23 // is_copy_assignable<const first_type> is true and
24 // is_copy_assignable<const second_type> is true.
26 // clang-format off
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>&>);
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 const std::pair<int&, double&> p1{i1, d1};
51 const std::pair<int&, double&> p2{i2, d2};
52 p2 = p1;
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};
61 p2 = 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 = t1;
71 assert(t2.first.constCopyAssign == 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;