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_convert.pass.cpp
blob13059ca3a2dad2eb5274acf6dc856d1a6fa7f61c
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 // template<class U1, class U2> constexpr
15 // const pair& operator=(const pair<U1, U2>& p) const;
17 #include <cassert>
18 #include <utility>
20 #include "test_macros.h"
21 #include "copy_move_types.h"
23 // Constraints:
24 // is_assignable_v<const first_type&, const U1&> is true, and
25 // is_assignable_v<const second_type&, const U2&> is true.
27 // clang-format off
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>&>);
44 // clang-format on
46 constexpr bool test() {
47 // reference types
49 int i1 = 1;
50 int i2 = 2;
51 long j1 = 3;
52 long j2 = 4;
53 const std::pair<int&, int&> p1{i1, i2};
54 const std::pair<long&, long&> p2{j1, j2};
55 p2 = p1;
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};
64 p2 = p1;
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{};
73 t2 = t1;
74 assert(t2.first.v.constCopyAssign == 1);
75 assert(t2.second.v.constCopyAssign == 1);
78 return true;
81 int main(int, char**) {
82 test();
83 // gcc cannot have mutable member in constant expression
84 #if !defined(TEST_COMPILER_GCC)
85 static_assert(test());
86 #endif
87 return 0;