Home | History | Annotate | Download | only in forward
      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 #include "test_macros.h"
     24 
     25 class A
     26 {
     27     A(const A&);
     28     A& operator=(const A&);
     29 public:
     30 
     31     A() {}
     32 #if TEST_STD_VER >= 11
     33     A(A&&) {}
     34 #endif
     35 };
     36 
     37 struct legacy
     38 {
     39     legacy() {}
     40     legacy(const legacy&);
     41 };
     42 
     43 int main()
     44 {
     45     int i = 0;
     46     const int ci = 0;
     47 
     48     legacy l;
     49     A a;
     50     const A ca;
     51 
     52 #if TEST_STD_VER >= 11
     53     static_assert((std::is_same<decltype(std::move_if_noexcept(i)), int&&>::value), "");
     54     static_assert((std::is_same<decltype(std::move_if_noexcept(ci)), const int&&>::value), "");
     55     static_assert((std::is_same<decltype(std::move_if_noexcept(a)), A&&>::value), "");
     56     static_assert((std::is_same<decltype(std::move_if_noexcept(ca)), const A&&>::value), "");
     57     static_assert((std::is_same<decltype(std::move_if_noexcept(l)), const legacy&>::value), "");
     58 #else  // C++ < 11
     59     // In C++03 libc++ #define's decltype to be __decltype on clang and
     60     // __typeof__ for other compilers. __typeof__ does not deduce the reference
     61     // qualifiers and will cause this test to fail.
     62     static_assert((std::is_same<decltype(std::move_if_noexcept(i)), const int&>::value), "");
     63     static_assert((std::is_same<decltype(std::move_if_noexcept(ci)), const int&>::value), "");
     64     static_assert((std::is_same<decltype(std::move_if_noexcept(a)), const A&>::value), "");
     65     static_assert((std::is_same<decltype(std::move_if_noexcept(ca)), const A&>::value), "");
     66     static_assert((std::is_same<decltype(std::move_if_noexcept(l)), const legacy&>::value), "");
     67 #endif
     68 
     69 #if TEST_STD_VER > 11
     70     constexpr int i1 = 23;
     71     constexpr int i2 = std::move_if_noexcept(i1);
     72     static_assert(i2 == 23, "" );
     73 #endif
     74 
     75 }
     76