| 1 |
// { dg-do compile { target c++23 } } |
| 2 |
|
| 3 |
#include <expected> |
| 4 |
|
| 5 |
void |
| 6 |
test_unexpected() |
| 7 |
{ |
| 8 |
int i[2]{}; |
| 9 |
|
| 10 |
// std::unexpected<E> is ill-formed if E is a non-object type, |
| 11 |
|
| 12 |
std::unexpected<int&> ref(i[0]); // { dg-error "here" } |
| 13 |
std::unexpected<void()> func(test_unexpected); // { dg-error "here" } |
| 14 |
// { dg-error "no matching function for call to" "" { target *-*-* } 0 } |
| 15 |
// { dg-error "invalidly declared function type" "" { target *-*-* } 0 } |
| 16 |
|
| 17 |
// an array type, |
| 18 |
std::unexpected<int[2]> array(i); // { dg-error "here" } |
| 19 |
|
| 20 |
// a specialization of std::unexpected, |
| 21 |
std::unexpected<int> u(1); |
| 22 |
std::unexpected<std::unexpected<int>> nested(u); // { dg-error "here" } |
| 23 |
// |
| 24 |
// or a cv-qualified type. |
| 25 |
std::unexpected<const int> c_int(1); // { dg-error "here" } |
| 26 |
std::unexpected<volatile int> v_int(1); // { dg-error "here" } |
| 27 |
} |
| 28 |
|
| 29 |
void |
| 30 |
test_expected_value() |
| 31 |
{ |
| 32 |
// std::expected<T, E> is ill-formed if T is a reference type, |
| 33 |
std::expected<int&, int> ref(std::unexpect); // { dg-error "here" } |
| 34 |
// { dg-error "reference type" "" { target *-*-* } 0 } |
| 35 |
|
| 36 |
// a function type, |
| 37 |
std::expected<void(), int> func(std::unexpect); // { dg-error "here" } |
| 38 |
// { dg-error "returning a function" "" { target *-*-* } 0 } |
| 39 |
// |
| 40 |
// possibly cv-qualified types in_place_t, |
| 41 |
std::expected<std::in_place_t, int> tag(std::unexpect); // { dg-error "here" } |
| 42 |
std::expected<const std::in_place_t, int> ctag(std::unexpect); // { dg-error "here" } |
| 43 |
// unexpect_t, |
| 44 |
std::expected<std::unexpect_t, int> utag(std::unexpect); // { dg-error "here" } |
| 45 |
std::expected<const std::unexpect_t, int> cutag(std::unexpect); // { dg-error "here" } |
| 46 |
// or a specialization of unexpected. |
| 47 |
std::expected<std::unexpected<int>, int> unex(std::in_place, 1); // { dg-error "here" } |
| 48 |
std::expected<const std::unexpected<int>, int> cunex(std::in_place, 1); // { dg-error "here" } |
| 49 |
} |
| 50 |
|
| 51 |
void |
| 52 |
test_expected_error() |
| 53 |
{ |
| 54 |
|
| 55 |
// std::expected<T, E> is ill-formed if std::unexpected<E> would be |
| 56 |
// ill-formed. Test the same types as in test_unexpected(). |
| 57 |
|
| 58 |
std::expected<int, int&> ref; // { dg-error "here" } |
| 59 |
std::expected<int, void()> func; // { dg-error "here" } |
| 60 |
std::expected<int, int[2]> array; // { dg-error "here" } |
| 61 |
std::expected<int, std::unexpected<int>> nested; // { dg-error "here" } |
| 62 |
std::expected<int, const int> c_int; // { dg-error "here" } |
| 63 |
std::expected<int, volatile int> v_int; // { dg-error "here" } |
| 64 |
} |
| 65 |
|
| 66 |
// { dg-prune-output "static assertion failed" } |
| 67 |
// { dg-prune-output "function returning an array" } |