• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // <utility>
11 
12 // template <class T>
13 //     typename conditional
14 //     <
15 //         !is_nothrow_move_constructible<T>::value && is_copy_constructible<T>::value,
16 //         const T&,
17 //         T&&
18 //     >::type
19 //     move_if_noexcept(T& x);
20 
21 #include <utility>
22 
23 class A
24 {
25     A(const A&);
26     A& operator=(const A&);
27 public:
28 
A()29     A() {}
30 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
A(A &&)31     A(A&&) {}
32 #endif
33 };
34 
35 struct legacy
36 {
legacylegacy37     legacy() {}
38     legacy(const legacy&);
39 };
40 
main()41 int main()
42 {
43     int i = 0;
44     const int ci = 0;
45 
46     legacy l;
47     A a;
48     const A ca;
49 
50 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
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 #else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
56     static_assert((std::is_same<decltype(std::move_if_noexcept(i)), const int>::value), "");
57     static_assert((std::is_same<decltype(std::move_if_noexcept(ci)), const int>::value), "");
58     static_assert((std::is_same<decltype(std::move_if_noexcept(a)), const A>::value), "");
59     static_assert((std::is_same<decltype(std::move_if_noexcept(ca)), const A>::value), "");
60 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
61     static_assert((std::is_same<decltype(std::move_if_noexcept(l)), const legacy&>::value), "");
62 
63 #if _LIBCPP_STD_VER > 11
64     constexpr int i1 = 23;
65     constexpr int i2 = std::move_if_noexcept(i1);
66     static_assert(i2 == 23, "" );
67 #endif
68 
69 }
70