brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.6 KiB · 0ae7340 Raw
67 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: c++03 && !stdlib=libc++10 11// <utility>12 13// template <class T>14//     typename conditional15//     <16//         !is_nothrow_move_constructible<T>::value && is_copy_constructible<T>::value,17//         const T&,18//         T&&19//     >::type20//     move_if_noexcept(T& x);21 22#include <type_traits>23#include <utility>24 25#include "test_macros.h"26 27class A28{29    A(const A&);30    A& operator=(const A&);31public:32 33    A() {}34    A(A&&) {}35};36 37struct legacy38{39    legacy() {}40    legacy(const legacy&);41};42 43int 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 > 1159    constexpr int i1 = 23;60    constexpr int i2 = std::move_if_noexcept(i1);61    static_assert(i2 == 23, "" );62#endif63 64 65  return 0;66}67