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 <utility> 23 24 #include "test_macros.h" 25 26 class A 27 { 28 A(const A&); 29 A& operator=(const A&); 30 public: 31 32 A() {} 33 A(A&&) {} 34 }; 35 36 struct legacy 37 { 38 legacy() {} 39 legacy(const legacy&); 40 }; 41 42 int main(int, char**) 43 { 44 int i = 0; 45 const int ci = 0; 46 47 legacy l; 48 A a; 49 const A ca; 50 51 static_assert((std::is_same<decltype(std::move_if_noexcept(i)), int&&>::value), ""); 52 static_assert((std::is_same<decltype(std::move_if_noexcept(ci)), const int&&>::value), ""); 53 static_assert((std::is_same<decltype(std::move_if_noexcept(a)), A&&>::value), ""); 54 static_assert((std::is_same<decltype(std::move_if_noexcept(ca)), const A&&>::value), ""); 55 static_assert((std::is_same<decltype(std::move_if_noexcept(l)), const legacy&>::value), ""); 56 57 #if TEST_STD_VER > 11 58 constexpr int i1 = 23; 59 constexpr int i2 = std::move_if_noexcept(i1); 60 static_assert(i2 == 23, "" ); 61 #endif 62 63 64 return 0; 65 } 66