| 1 |
// { dg-do compile { target c++20 } } |
| 2 |
|
| 3 |
// Copyright (C) 2020-2025 Free Software Foundation, Inc. |
| 4 |
// |
| 5 |
// This file is part of the GNU ISO C++ Library. This library is free |
| 6 |
// software; you can redistribute it and/or modify it under the |
| 7 |
// terms of the GNU General Public License as published by the |
| 8 |
// Free Software Foundation; either version 3, or (at your option) |
| 9 |
// any later version. |
| 10 |
// |
| 11 |
// This library is distributed in the hope that it will be useful, |
| 12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
// GNU General Public License for more details. |
| 15 |
// |
| 16 |
// You should have received a copy of the GNU General Public License along |
| 17 |
// with this library; see the file COPYING3. If not see |
| 18 |
// <http://www.gnu.org/licenses/>. |
| 19 |
|
| 20 |
#include <type_traits> |
| 21 |
|
| 22 |
static_assert( std::is_nothrow_constructible_v<int[1]> ); |
| 23 |
static_assert( std::is_nothrow_constructible_v<int[1], int> ); |
| 24 |
static_assert( std::is_nothrow_constructible_v<int[2], int> ); |
| 25 |
static_assert( std::is_nothrow_constructible_v<int[2], int, int> ); |
| 26 |
static_assert( ! std::is_nothrow_constructible_v<int[1], int, int> ); |
| 27 |
static_assert( ! std::is_nothrow_constructible_v<int[]> ); |
| 28 |
static_assert( ! std::is_nothrow_constructible_v<int[], int> ); |
| 29 |
static_assert( ! std::is_nothrow_constructible_v<int[], int, int> ); |
| 30 |
|
| 31 |
struct X |
| 32 |
{ |
| 33 |
X() = default; |
| 34 |
X(int) noexcept { } |
| 35 |
X(double) { } |
| 36 |
}; |
| 37 |
|
| 38 |
static_assert( std::is_nothrow_constructible_v<X[2]> ); |
| 39 |
static_assert( std::is_nothrow_constructible_v<X[1], X> ); |
| 40 |
static_assert( std::is_nothrow_constructible_v<X[1], int> ); |
| 41 |
static_assert( ! std::is_nothrow_constructible_v<X[1], double> ); |
| 42 |
static_assert( ! std::is_nothrow_constructible_v<X[2], int, double> ); |
| 43 |
|
| 44 |
struct Y |
| 45 |
{ |
| 46 |
int i; |
| 47 |
X x; |
| 48 |
}; |
| 49 |
|
| 50 |
static_assert( std::is_nothrow_constructible_v<Y> ); |
| 51 |
static_assert( std::is_nothrow_constructible_v<Y, Y> ); |
| 52 |
static_assert( std::is_nothrow_constructible_v<Y, int> ); |
| 53 |
static_assert( ! std::is_nothrow_constructible_v<Y, X> ); |
| 54 |
static_assert( std::is_nothrow_constructible_v<Y, int, X> ); |
| 55 |
static_assert( std::is_nothrow_constructible_v<Y, int, int> ); |
| 56 |
static_assert( ! std::is_nothrow_constructible_v<Y, int, double> ); |
| 57 |
|
| 58 |
struct Z : Y { }; |
| 59 |
|
| 60 |
static_assert( std::is_nothrow_constructible_v<Z> ); |
| 61 |
static_assert( std::is_nothrow_constructible_v<Z, Z> ); |
| 62 |
static_assert( std::is_nothrow_constructible_v<Z, Y> ); |
| 63 |
static_assert( ! std::is_nothrow_constructible_v<Z, int> ); |
| 64 |
static_assert( ! std::is_nothrow_constructible_v<Z, int, X> ); |
| 65 |
static_assert( ! std::is_nothrow_constructible_v<Z, int, int> ); |
| 66 |
static_assert( ! std::is_nothrow_constructible_v<Z, Y, double> ); |
| 67 |
static_assert( ! std::is_nothrow_constructible_v<Z, int, double> ); |
| 68 |
static_assert( ! std::is_nothrow_constructible_v<Z, X> ); |