]> 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-2021 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-options "-std=gnu++17" }
19 // { dg-do compile { target c++17 } }
20
21 #include <optional>
22
23 struct NonTrivialDtor {
24 ~NonTrivialDtor() { }
25 };
26
27 struct NonTrivialCopyAssign {
28 NonTrivialCopyAssign& operator=(const NonTrivialCopyAssign&) { return *this; }
29 NonTrivialCopyAssign& operator=(NonTrivialCopyAssign&&) = default;
30 };
31
32 struct NonTrivialMoveAssign {
33 NonTrivialMoveAssign& operator=(const NonTrivialMoveAssign&) = default;
34 NonTrivialMoveAssign& operator=(NonTrivialMoveAssign&&) { return *this; }
35 };
36
37 struct NonTrivialAssign {
38 NonTrivialAssign& operator=(const NonTrivialAssign&) { return *this; }
39 NonTrivialAssign& operator=(NonTrivialAssign&&) { return *this; }
40 };
41
42 struct NonTrivialAll {
43 ~NonTrivialAll() { }
44 NonTrivialAll& operator=(const NonTrivialAll&) { return *this; }
45 NonTrivialAll& operator=(NonTrivialAll&&) { return *this; }
46 };
47
48 struct ConstExpr { int i = 0; };
49
50 struct Trivial { int i; };
51
52 template<typename T>
53 constexpr bool check
54 = std::is_nothrow_default_constructible_v<std::optional<T>>;
55
56 // PR libstdc++/85642
57 static_assert(check<NonTrivialDtor>);
58 static_assert(check<NonTrivialCopyAssign>);
59 static_assert(check<NonTrivialMoveAssign>);
60 static_assert(check<NonTrivialAssign>);
61 static_assert(check<NonTrivialAll>);
62 static_assert(check<ConstExpr>);
63 static_assert(check<Trivial>);