| 1 |
// { dg-do compile { target c++23 } } |
| 2 |
// { dg-options "-fno-exceptions" } |
| 3 |
|
| 4 |
#include <expected> |
| 5 |
|
| 6 |
// 3843. std::expected<T,E>::value() & assumes E is copy constructible |
| 7 |
void |
| 8 |
test_lwg3843() |
| 9 |
{ |
| 10 |
struct E1 { |
| 11 |
E1(int) { } |
| 12 |
E1(E1&) { } |
| 13 |
E1(const E1&) = delete; |
| 14 |
}; |
| 15 |
std::expected<int, E1> v1; |
| 16 |
v1.value(); // { dg-error "here" } |
| 17 |
const auto& v1c = v1; |
| 18 |
v1c.value(); // { dg-error "here" } |
| 19 |
|
| 20 |
struct E2 { |
| 21 |
E2(int) { } |
| 22 |
E2(const E2&) { } |
| 23 |
E2(E2&&) = delete; |
| 24 |
}; |
| 25 |
std::expected<int, E2> v2; |
| 26 |
v2.value(); |
| 27 |
std::move(v2).value(); // { dg-error "here" } |
| 28 |
const auto& v2c = v2; |
| 29 |
v2c.value(); |
| 30 |
std::move(v2c).value(); |
| 31 |
|
| 32 |
struct E3 { |
| 33 |
E3(int) { } |
| 34 |
E3(const E3&) { } |
| 35 |
E3(E3&&) { } |
| 36 |
E3(const E3&&) = delete; |
| 37 |
}; |
| 38 |
std::expected<int, E3> v3; |
| 39 |
v3.value(); |
| 40 |
std::move(v3).value(); |
| 41 |
const auto& v3c = v3; |
| 42 |
v3c.value(); |
| 43 |
std::move(v3c).value(); // { dg-error "here" } |
| 44 |
} |
| 45 |
|
| 46 |
// 3940. std::expected<void, E>::value() also needs E to be copy constructible |
| 47 |
void |
| 48 |
test_lwg3940() |
| 49 |
{ |
| 50 |
struct E1 { |
| 51 |
E1(int) { } |
| 52 |
E1(E1&) { } |
| 53 |
E1(const E1&) = delete; |
| 54 |
}; |
| 55 |
std::expected<void, E1> v1; |
| 56 |
v1.value(); // { dg-error "here" } |
| 57 |
|
| 58 |
struct E2 { |
| 59 |
E2(int) { } |
| 60 |
E2(const E2&) { } |
| 61 |
E2(E2&&) = delete; |
| 62 |
}; |
| 63 |
std::expected<void, E2> v2; |
| 64 |
std::move(v2).value(); // { dg-error "here" } |
| 65 |
} |
| 66 |
|
| 67 |
// { dg-error "static assertion failed" "" { target *-*-* } 0 } |
| 68 |
// { dg-prune-output "use of deleted function" } |
| 69 |
// { dg-prune-output "control reaches end of non-void function" } |