https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79249
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> --- Slightly further reduced: template <typename FnT> auto attempt(FnT f) { return [f]() { try { f(); } catch(...) { __builtin_puts("caught"); } }; } // More complex behavior does not seem to matter here, however // removing "noexcept" results in GCC generating a program that works as // expected: void f_ident() noexcept { } // Even though this is not actually referenced by the other code, removing // it causes GCC to generate a program that works as expected. void test_attempt_call_with_exception_handler() { attempt(f_ident)(); } void g() { throw 1; } int main() { attempt(g)(); }