// { dg-do compile { target c++23 } } #include void test01() { std::optional o; o.or_else([&] { return o; }); // OK o.or_else([] { return std::optional(); }); // { dg-error "here" } o.or_else([] { return 1; }); // { dg-error "here" } std::move(o).or_else([] { return std::optional(); }); // { dg-error "here" } std::move(o).or_else([] { return 1; }); // { dg-error "here" } } // { dg-prune-output "static assertion failed" } void test02() { struct move_only { move_only() { } move_only(move_only&&) { } }; std::optional mo; mo.or_else([]{ return std::optional{}; }); // { dg-error "no matching function" } }