Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / utilities / utility / pairs / pairs.pair / ctor.move.pass.cpp
blob71333105439f90410d14a67781422e6eab33726c
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
11 // <utility>
13 // template <class T1, class T2> struct pair
15 // pair(pair&&) = default;
17 #include <cassert>
18 #include <memory>
19 #include <type_traits>
20 #include <utility>
22 #include "test_macros.h"
24 struct Dummy {
25 Dummy(Dummy const&) = delete;
26 Dummy(Dummy &&) = default;
29 struct NotCopyOrMoveConstructible {
30 NotCopyOrMoveConstructible() = default;
31 NotCopyOrMoveConstructible(NotCopyOrMoveConstructible const&) = delete;
32 NotCopyOrMoveConstructible(NotCopyOrMoveConstructible&&) = delete;
35 int main(int, char**)
38 typedef std::pair<int, short> P1;
39 static_assert(std::is_move_constructible<P1>::value, "");
40 P1 p1(3, static_cast<short>(4));
41 P1 p2 = std::move(p1);
42 assert(p2.first == 3);
43 assert(p2.second == 4);
46 using P = std::pair<Dummy, int>;
47 static_assert(!std::is_copy_constructible<P>::value, "");
48 static_assert(std::is_move_constructible<P>::value, "");
51 // When constructing a pair containing a reference, we only bind the
52 // reference, so it doesn't matter whether the type is or isn't
53 // copy/move constructible.
55 using P = std::pair<NotCopyOrMoveConstructible&, int>;
56 static_assert(std::is_move_constructible<P>::value, "");
58 NotCopyOrMoveConstructible obj;
59 P p2{obj, 3};
60 P p1(std::move(p2));
61 assert(&p1.first == &obj);
62 assert(&p2.first == &obj);
65 using P = std::pair<NotCopyOrMoveConstructible&&, int>;
66 static_assert(std::is_move_constructible<P>::value, "");
68 NotCopyOrMoveConstructible obj;
69 P p2{std::move(obj), 3};
70 P p1(std::move(p2));
71 assert(&p1.first == &obj);
72 assert(&p2.first == &obj);
76 return 0;