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