libstdc++-v3/testsuite/20_util/optional/constexpr/cons/conv.cc
raw| 1 | // { dg-do compile { target c++20 } } |
| 2 | |
| 3 | #include <optional> |
| 4 | #include <testsuite_hooks.h> |
| 5 | |
| 6 | constexpr bool |
| 7 | test_cons() |
| 8 | { |
| 9 | std::optional<int> oi(1); |
| 10 | std::optional<long> ol(oi); |
| 11 | VERIFY( *ol == 1L ); |
| 12 | VERIFY( *oi == 1 ); |
| 13 | |
| 14 | std::optional<unsigned> ou(std::move(oi)); |
| 15 | VERIFY( *ou == 1u ); |
| 16 | VERIFY( oi.has_value() && *oi == 1 ); |
| 17 | |
| 18 | return true; |
| 19 | } |
| 20 | |
| 21 | static_assert( test_cons() ); |