[Bug c++/79249] Lambda call does not create exception handler.

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu Jan 26 20:48:00 GMT 2017


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)();
}


More information about the Gcc-bugs mailing list