| 1 | // { dg-do run { target c++23 } } |
| 2 | |
| 3 | // LWG 4222. 'expected' constructor from a single value missing a constraint |
| 4 | |
| 5 | #include <expected> |
| 6 | #include <type_traits> |
| 7 | #include <testsuite_hooks.h> |
| 8 | |
| 9 | struct T { |
| 10 | explicit T(auto) {} |
| 11 | }; |
| 12 | struct E { |
| 13 | E(int) {} |
| 14 | }; |
| 15 | |
| 16 | struct V { |
| 17 | explicit constexpr V(std::unexpect_t) {} |
| 18 | }; |
| 19 | |
| 20 | static_assert(!std::is_constructible_v<std::expected<T, E>, std::unexpect_t>); |
| 21 | static_assert(!std::is_constructible_v<std::expected<T, E>, std::unexpect_t &>); |
| 22 | static_assert(!std::is_constructible_v<std::expected<T, E>, std::unexpect_t &&>); |
| 23 | static_assert(!std::is_constructible_v<std::expected<T, E>, const std::unexpect_t>); |
| 24 | static_assert(!std::is_constructible_v<std::expected<T, E>, const std::unexpect_t &>); |
| 25 | static_assert(!std::is_constructible_v<std::expected<T, E>, const std::unexpect_t &&>); |
| 26 | |
| 27 | constexpr bool test() { |
| 28 | std::expected<V, int> e1(std::in_place, std::unexpect); |
| 29 | VERIFY( e1.has_value() ); |
| 30 | std::expected<int, V> e2(std::unexpect, std::unexpect); |
| 31 | VERIFY( !e2.has_value() ); |
| 32 | return true; |
| 33 | } |
| 34 | |
| 35 | int main() { |
| 36 | test(); |
| 37 | static_assert(test()); |
| 38 | return 0; |
| 39 | } |