]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/optional/cons/85642.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 20_util / optional / cons / 85642.cc
1 // Copyright (C) 2018-2023 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 struct NonTrivialDtor {
23 ~NonTrivialDtor() { }
24 };
25
26 struct NonTrivialCopyAssign {
27 NonTrivialCopyAssign& operator=(const NonTrivialCopyAssign&) { return *this; }
28 NonTrivialCopyAssign& operator=(NonTrivialCopyAssign&&) = default;
29 };
30
31 struct NonTrivialMoveAssign {
32 NonTrivialMoveAssign& operator=(const NonTrivialMoveAssign&) = default;
33 NonTrivialMoveAssign& operator=(NonTrivialMoveAssign&&) { return *this; }
34 };
35
36 struct NonTrivialAssign {
37 NonTrivialAssign& operator=(const NonTrivialAssign&) { return *this; }
38 NonTrivialAssign& operator=(NonTrivialAssign&&) { return *this; }
39 };
40
41 struct NonTrivialAll {
42 ~NonTrivialAll() { }
43 NonTrivialAll& operator=(const NonTrivialAll&) { return *this; }
44 NonTrivialAll& operator=(NonTrivialAll&&) { return *this; }
45 };
46
47 struct ConstExpr { int i = 0; };
48
49 struct Trivial { int i; };
50
51 template<typename T>
52 constexpr bool check
53 = std::is_nothrow_default_constructible_v<std::optional<T>>;
54
55 // PR libstdc++/85642
56 static_assert(check<NonTrivialDtor>);
57 static_assert(check<NonTrivialCopyAssign>);
58 static_assert(check<NonTrivialMoveAssign>);
59 static_assert(check<NonTrivialAssign>);
60 static_assert(check<NonTrivialAll>);
61 static_assert(check<ConstExpr>);
62 static_assert(check<Trivial>);