]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/20_util/optional/cons/noexcept.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 20_util / optional / cons / noexcept.cc
CommitLineData
7adcbafe 1// Copyright (C) 2020-2022 Free Software Foundation, Inc.
8992cd18
JW
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
22template<bool B>
23struct 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
36using std::is_nothrow_constructible_v;
37using std::in_place_t;
38
39using Xyes = X<true>;
40using Xno = X<false>;
41using Oyes = std::optional<Xyes>;
42using Ono = std::optional<Xno>;
43
44static_assert( is_nothrow_constructible_v<Oyes> );
45static_assert( is_nothrow_constructible_v<Oyes, std::nullopt_t> );
46static_assert( is_nothrow_constructible_v<Oyes, const Xyes&> );
47static_assert( is_nothrow_constructible_v<Oyes, Xyes> );
48static_assert( is_nothrow_constructible_v<Oyes, in_place_t, short> );
49static_assert( is_nothrow_constructible_v<Oyes, in_place_t,
50 std::initializer_list<int>,
51 long> );
52static_assert( is_nothrow_constructible_v<Oyes, const Ono&> );
53static_assert( is_nothrow_constructible_v<Oyes, Ono> );
54
55static_assert( is_nothrow_constructible_v<Ono> );
56static_assert( is_nothrow_constructible_v<Ono, std::nullopt_t> );
57static_assert( ! is_nothrow_constructible_v<Ono, const Xno&> );
58static_assert( ! is_nothrow_constructible_v<Ono, Xno> );
59static_assert( ! is_nothrow_constructible_v<Ono, in_place_t, short> );
60static_assert( ! is_nothrow_constructible_v<Ono, in_place_t,
61 std::initializer_list<int>,
62 long> );
63static_assert( ! is_nothrow_constructible_v<Ono, const Xyes&> );
64static_assert( ! is_nothrow_constructible_v<Ono, Xyes> );