https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104601
--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> --- Testcase without the unneeded <cstdio> which aborts if miscompiled. #include <algorithm> #include <optional> inline std::optional<int> a(std::vector<int>::iterator b, std::vector<int>::iterator c, std::optional<int> h(int)) { std::optional<int> d; find_if(b, c, [&](auto e) { d = h(e); return d; }); return d; } std::optional<int> f(int) { return 1; } int main() { std::vector<int> g(100); auto b = g.begin(); auto c = g.end(); auto e = a(b, c, f); if (!e) __builtin_abort(); }