| 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 |
// type_traits |
| 10 |
|
| 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 |
|
| 19 |
template <class T> |
| 20 |
void test_is_nothrow_constructible() |
| 21 |
{ |
| 22 |
static_assert(( std::is_nothrow_constructible<T>::value), ""); |
| 23 |
#if TEST_STD_VER > 14 |
| 24 |
static_assert(( std::is_nothrow_constructible_v<T>), ""); |
| 25 |
#endif |
| 26 |
} |
| 27 |
|
| 28 |
template <class T, class A0> |
| 29 |
void test_is_nothrow_constructible() |
| 30 |
{ |
| 31 |
static_assert(( std::is_nothrow_constructible<T, A0>::value), ""); |
| 32 |
#if TEST_STD_VER > 14 |
| 33 |
static_assert(( std::is_nothrow_constructible_v<T, A0>), ""); |
| 34 |
#endif |
| 35 |
} |
| 36 |
|
| 37 |
template <class T> |
| 38 |
void test_is_not_nothrow_constructible() |
| 39 |
{ |
| 40 |
static_assert((!std::is_nothrow_constructible<T>::value), ""); |
| 41 |
#if TEST_STD_VER > 14 |
| 42 |
static_assert((!std::is_nothrow_constructible_v<T>), ""); |
| 43 |
#endif |
| 44 |
} |
| 45 |
|
| 46 |
template <class T, class A0> |
| 47 |
void test_is_not_nothrow_constructible() |
| 48 |
{ |
| 49 |
static_assert((!std::is_nothrow_constructible<T, A0>::value), ""); |
| 50 |
#if TEST_STD_VER > 14 |
| 51 |
static_assert((!std::is_nothrow_constructible_v<T, A0>), ""); |
| 52 |
#endif |
| 53 |
} |
| 54 |
|
| 55 |
template <class T, class A0, class A1> |
| 56 |
void test_is_not_nothrow_constructible() |
| 57 |
{ |
| 58 |
static_assert((!std::is_nothrow_constructible<T, A0, A1>::value), ""); |
| 59 |
#if TEST_STD_VER > 14 |
| 60 |
static_assert((!std::is_nothrow_constructible_v<T, A0, A1>), ""); |
| 61 |
#endif |
| 62 |
} |
| 63 |
|
| 64 |
struct C |
| 65 |
{ |
| 66 |
C(C&); // not const |
| 67 |
void operator=(C&); // not const |
| 68 |
}; |
| 69 |
|
| 70 |
#if TEST_STD_VER >= 11 |
| 71 |
struct Tuple { |
| 72 |
Tuple(Empty&&) noexcept {} |
| 73 |
}; |
| 74 |
#endif |
| 75 |
|
| 76 |
int 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 >= 11 |
| 88 |
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 |
#endif |
| 93 |
|
| 94 |
return 0; |
| 95 |
} |