| 1 |
// { dg-do compile { target c++23 } } |
| 2 |
|
| 3 |
#include <optional> |
| 4 |
|
| 5 |
void |
| 6 |
test01() |
| 7 |
{ |
| 8 |
std::optional<int> o; |
| 9 |
o.or_else([&] { return o; }); // OK |
| 10 |
o.or_else([] { return std::optional<short>(); }); // { dg-error "here" } |
| 11 |
o.or_else([] { return 1; }); // { dg-error "here" } |
| 12 |
std::move(o).or_else([] { return std::optional<short>(); }); // { dg-error "here" } |
| 13 |
std::move(o).or_else([] { return 1; }); // { dg-error "here" } |
| 14 |
} |
| 15 |
|
| 16 |
// { dg-prune-output "static assertion failed" } |
| 17 |
|
| 18 |
void |
| 19 |
test02() |
| 20 |
{ |
| 21 |
struct move_only |
| 22 |
{ |
| 23 |
move_only() { } |
| 24 |
move_only(move_only&&) { } |
| 25 |
}; |
| 26 |
|
| 27 |
std::optional<move_only> mo; |
| 28 |
mo.or_else([]{ return std::optional<move_only>{}; }); // { dg-error "no matching function" } |
| 29 |
} |