1 //===----------------------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
12 // UNSUPPORTED: c++98, c++03
15 #include <type_traits>
18 #include "test_macros.h"
22 move_only(const move_only&);
23 move_only& operator=(const move_only&);
25 move_only(move_only&&) {}
26 move_only& operator=(move_only&&) {return *this;}
31 move_only source() {return move_only();}
32 const move_only csource() {return move_only();}
34 void test(move_only) {}
39 template <class QualInt>
40 QualInt get() noexcept { return static_cast<QualInt>(x); }
48 A(const A&) {++copy_ctor;}
50 A& operator=(const A&) = delete;
53 constexpr bool test_constexpr_move() {
57 return std::move(y) == 42
58 && std::move(cy) == 42
59 && std::move(static_cast<int&&>(y)) == 42
60 && std::move(static_cast<int const&&>(y)) == 42;
68 { // Test return type and noexcept.
69 static_assert(std::is_same<decltype(std::move(x)), int&&>::value, "");
70 static_assert(noexcept(std::move(x)), "");
71 static_assert(std::is_same<decltype(std::move(cx)), const int&&>::value, "");
72 static_assert(noexcept(std::move(cx)), "");
73 static_assert(std::is_same<decltype(std::move(42)), int&&>::value, "");
74 static_assert(noexcept(std::move(42)), "");
75 static_assert(std::is_same<decltype(std::move(get<const int&&>())), const int&&>::value, "");
76 static_assert(noexcept(std::move(get<int const&&>())), "");
78 { // test copy and move semantics
82 assert(copy_ctor == 0);
83 assert(move_ctor == 0);
86 assert(copy_ctor == 1);
87 assert(move_ctor == 0);
90 assert(copy_ctor == 1);
91 assert(move_ctor == 1);
94 assert(copy_ctor == 2);
95 assert(move_ctor == 1);
98 assert(copy_ctor == 3);
99 assert(move_ctor == 1);
101 { // test on a move only type
106 #if TEST_STD_VER > 11
108 constexpr int y = 42;
109 static_assert(std::move(y) == 42, "");
110 static_assert(test_constexpr_move(), "");
113 #if TEST_STD_VER == 11 && defined(_LIBCPP_VERSION)
114 // Test that std::forward is constexpr in C++11. This is an extension
115 // provided by both libc++ and libstdc++.
117 constexpr int y = 42;
118 static_assert(std::move(y) == 42, "");