]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/optional/constexpr/cons/value.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 20_util / optional / constexpr / cons / value.cc
1 // { dg-options "-std=gnu++17" }
2 // { dg-do compile { target c++17 } }
3
4 // Copyright (C) 2013-2021 Free Software Foundation, Inc.
5 //
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 3, or (at your option)
10 // any later version.
11
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING3. If not see
19 // <http://www.gnu.org/licenses/>.
20
21 #include <optional>
22 #include <testsuite_hooks.h>
23
24 int main()
25 {
26 // [20.5.4.1] Constructors
27
28 {
29 constexpr long i = 0x1234ABCD;
30 constexpr std::optional<long> o { i };
31 static_assert( o, "" );
32 static_assert( *o == 0x1234ABCD, "" );
33 }
34
35 {
36 constexpr long i = 0x1234ABCD;
37 constexpr std::optional<long> o = i;
38 static_assert( o, "" );
39 static_assert( *o == 0x1234ABCD, "" );
40 }
41
42 {
43 constexpr long i = 0x1234ABCD;
44 constexpr std::optional<long> o = { i };
45 static_assert( o, "" );
46 static_assert( *o == 0x1234ABCD, "" );
47 }
48
49 {
50 constexpr long i = 0x1234ABCD;
51 constexpr std::optional<long> o { std::move(i) };
52 static_assert( o, "" );
53 static_assert( *o == 0x1234ABCD, "" );
54 }
55
56 {
57 constexpr long i = 0x1234ABCD;
58 constexpr std::optional<long> o = std::move(i);
59 static_assert( o, "" );
60 static_assert( *o == 0x1234ABCD, "" );
61 }
62
63 {
64 constexpr long i = 0x1234ABCD;
65 constexpr std::optional<long> o = { std::move(i) };
66 static_assert( o, "" );
67 static_assert( *o == 0x1234ABCD, "" );
68 }
69 {
70 constexpr std::optional<long> o = 42;
71 constexpr std::optional<long> o2{o};
72 constexpr std::optional<long> o3(o);
73 constexpr std::optional<long> o4 = o;
74 constexpr std::optional<long> o5;
75 constexpr std::optional<long> o6{o5};
76 constexpr std::optional<long> o7(o5);
77 constexpr std::optional<long> o8 = o5;
78 constexpr std::optional<long> o9{std::move(o)};
79 constexpr std::optional<long> o10(std::move(o));
80 constexpr std::optional<long> o11 = std::move(o);
81 constexpr std::optional<long> o12;
82 constexpr std::optional<long> o13{std::move(o5)};
83 constexpr std::optional<long> o14(std::move(o5));
84 constexpr std::optional<long> o15 = std::move(o5);
85 }
86 }