https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111358
Bug ID: 111358 Summary: libstdc++'s optional::and_then and optional::transform are not ADL-proof Product: gcc Version: 14.0 Status: UNCONFIRMED Keywords: rejects-valid Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: de34 at live dot cn Target Milestone: --- The following program is incorrectly rejected when using libstdc++ (https://godbolt.org/z/eavTYjEdx): ``` #include <optional> namespace fvs { struct Foo {}; void operator*(std::optional<fvs::Foo>) = delete; } int main() { std::optional<fvs::Foo>{}.and_then( [](auto&&){ return std::optional<char>{}; }); std::optional<fvs::Foo>{}.transform( [](auto&&){ return 0; }); } ``` The reason of compilation error is that libstdc++ uses **this in and_then and transform functions, which triggers ADL and finds unwanted operator*(). These monadic operations are currently specified in [optional.monadic] with value(), so they should be ADL-proof.