]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/optional/constexpr/cons/value.cc
40070444c8e305f13050e43b4abfc050303eeb5a
1 // { dg-options "-std=gnu++17" }
2 // { dg-do compile { target c++17 } }
4 // Copyright (C) 2013-2020 Free Software Foundation, Inc.
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)
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.
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/>.
22 #include <testsuite_hooks.h>
26 // [20.5.4.1] Constructors
29 constexpr long i
= 0x1234ABCD;
30 constexpr std::optional
<long> o
{ i
};
31 static_assert( o
, "" );
32 static_assert( *o
== 0x1234ABCD, "" );
36 constexpr long i
= 0x1234ABCD;
37 constexpr std::optional
<long> o
= i
;
38 static_assert( o
, "" );
39 static_assert( *o
== 0x1234ABCD, "" );
43 constexpr long i
= 0x1234ABCD;
44 constexpr std::optional
<long> o
= { i
};
45 static_assert( o
, "" );
46 static_assert( *o
== 0x1234ABCD, "" );
50 constexpr long i
= 0x1234ABCD;
51 constexpr std::optional
<long> o
{ std::move(i
) };
52 static_assert( o
, "" );
53 static_assert( *o
== 0x1234ABCD, "" );
57 constexpr long i
= 0x1234ABCD;
58 constexpr std::optional
<long> o
= std::move(i
);
59 static_assert( o
, "" );
60 static_assert( *o
== 0x1234ABCD, "" );
64 constexpr long i
= 0x1234ABCD;
65 constexpr std::optional
<long> o
= { std::move(i
) };
66 static_assert( o
, "" );
67 static_assert( *o
== 0x1234ABCD, "" );
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
);