Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / utilities / utility / pairs / pairs.pair / assign_pair_cxx03.pass.cpp
blob2444131b02a0cf6cb920de4da2b6cf60aa9ba8dd
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 // REQUIRES: c++03
11 // <utility>
13 // template <class T1, class T2> struct pair
15 // pair& operator=(pair const& p);
17 #include <utility>
18 #include <memory>
19 #include <cassert>
21 #include "test_macros.h"
23 struct NonAssignable {
24 NonAssignable() {}
25 private:
26 NonAssignable& operator=(NonAssignable const&);
29 struct Incomplete;
30 extern Incomplete inc_obj;
32 struct ConstructibleFromInt {
33 ConstructibleFromInt() : value(-1) { }
34 explicit ConstructibleFromInt(int v) : value(v) { }
35 int value;
38 int main(int, char**)
41 // Test that we don't constrain the assignment operator in C++03 mode.
42 // Since we don't have access control SFINAE having pair evaluate SFINAE
43 // may cause a hard error.
44 typedef std::pair<int, NonAssignable> P;
45 static_assert(std::is_copy_assignable<P>::value, "");
48 typedef std::pair<int, Incomplete&> P;
49 static_assert(std::is_copy_assignable<P>::value, "");
50 P p(42, inc_obj);
51 assert(&p.second == &inc_obj);
54 // The type is constructible from int, but not assignable from int.
55 // This ensures that operator=(pair const&) can be used in conjunction with
56 // pair(pair<U, V> const&) to mimic operator=(pair<U, V> const&) in C++03.
57 // This is weird but valid in C++03.
58 std::pair<ConstructibleFromInt, char> p;
59 std::pair<int, char> from(11, 'x');
60 p = from;
61 assert(p.first.value == 11);
62 assert(p.second == 'x');
65 return 0;
68 struct Incomplete {};
69 Incomplete inc_obj;