96 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// type_traits10 11// template <class T, class... Args>12// struct is_nothrow_constructible;13 14#include <type_traits>15#include "test_macros.h"16 17#include "common.h"18 19template <class T>20void test_is_nothrow_constructible()21{22 static_assert(( std::is_nothrow_constructible<T>::value), "");23#if TEST_STD_VER > 1424 static_assert(( std::is_nothrow_constructible_v<T>), "");25#endif26}27 28template <class T, class A0>29void test_is_nothrow_constructible()30{31 static_assert(( std::is_nothrow_constructible<T, A0>::value), "");32#if TEST_STD_VER > 1433 static_assert(( std::is_nothrow_constructible_v<T, A0>), "");34#endif35}36 37template <class T>38void test_is_not_nothrow_constructible()39{40 static_assert((!std::is_nothrow_constructible<T>::value), "");41#if TEST_STD_VER > 1442 static_assert((!std::is_nothrow_constructible_v<T>), "");43#endif44}45 46template <class T, class A0>47void test_is_not_nothrow_constructible()48{49 static_assert((!std::is_nothrow_constructible<T, A0>::value), "");50#if TEST_STD_VER > 1451 static_assert((!std::is_nothrow_constructible_v<T, A0>), "");52#endif53}54 55template <class T, class A0, class A1>56void test_is_not_nothrow_constructible()57{58 static_assert((!std::is_nothrow_constructible<T, A0, A1>::value), "");59#if TEST_STD_VER > 1460 static_assert((!std::is_nothrow_constructible_v<T, A0, A1>), "");61#endif62}63 64struct C65{66 C(C&); // not const67 void operator=(C&); // not const68};69 70#if TEST_STD_VER >= 1171struct Tuple {72 Tuple(Empty&&) noexcept {}73};74#endif75 76int main(int, char**)77{78 test_is_nothrow_constructible<int> ();79 test_is_nothrow_constructible<int, const int&> ();80 test_is_nothrow_constructible<Empty> ();81 test_is_nothrow_constructible<Empty, const Empty&> ();82 83 test_is_not_nothrow_constructible<A, int> ();84 test_is_not_nothrow_constructible<A, int, double> ();85 test_is_not_nothrow_constructible<A> ();86 test_is_not_nothrow_constructible<C> ();87#if TEST_STD_VER >= 1188 test_is_nothrow_constructible<Tuple &&, Empty> (); // See bug #19616.89 90 static_assert(!std::is_constructible<Tuple&, Empty>::value, "");91 test_is_not_nothrow_constructible<Tuple &, Empty> (); // See bug #19616.92#endif93 94 return 0;95}96