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 //===----------------------------------------------------------------------===//
8
9 // UNSUPPORTED: c++03 && !stdlib=libc++
10
11 // <utility>
12
13 // template <class T>
14 // typename conditional
15 // <
16 // !is_nothrow_move_constructible<T>::value && is_copy_constructible<T>::value,
17 // const T&,
18 // T&&
19 // >::type
20 // move_if_noexcept(T& x);
21
22 #include <type_traits>
23 #include <utility>
24
25 #include "test_macros.h"
26
27 class A
28 {
29 A(const A&);
30 A& operator=(const A&);
31 public:
32
A()33 A() {}
A(A &&)34 A(A&&) {}
35 };
36
37 struct legacy
38 {
legacylegacy39 legacy() {}
40 legacy(const legacy&);
41 };
42
main(int,char **)43 int main(int, char**)
44 {
45 int i = 0;
46 const int ci = 0;
47
48 legacy l;
49 A a;
50 const A ca;
51
52 static_assert((std::is_same<decltype(std::move_if_noexcept(i)), int&&>::value), "");
53 static_assert((std::is_same<decltype(std::move_if_noexcept(ci)), const int&&>::value), "");
54 static_assert((std::is_same<decltype(std::move_if_noexcept(a)), A&&>::value), "");
55 static_assert((std::is_same<decltype(std::move_if_noexcept(ca)), const A&&>::value), "");
56 static_assert((std::is_same<decltype(std::move_if_noexcept(l)), const legacy&>::value), "");
57
58 #if TEST_STD_VER > 11
59 constexpr int i1 = 23;
60 constexpr int i2 = std::move_if_noexcept(i1);
61 static_assert(i2 == 23, "" );
62 #endif
63
64
65 return 0;
66 }
67