https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84858
Bug ID: 84858 Summary: wrong exception handling of std::function Product: gcc Version: 5.4.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: herumi at nifty dot com Target Milestone: --- The following code shows "g" infinitely. Is my code wrong? Or is it a bug of gcc? >g++ t.cpp -O2 -std=c++11 && ./a.out >f >f >g >g >.... My environments are Ubuntu 16.04.4 LTS kernel : 4.4.0-116-generic gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.9) This was reproduced by g++ 7.2.0, 6.3.0, 5.5.0 with same option -O2 -std=c++11 and not reproduced by clang-5.0 or Visual Studio 2015. cat t.cpp --- #include <stdio.h> #include <functional> #include <stdexcept> void f() noexcept { puts("f"); } void g() { puts("g"); throw std::runtime_error("err"); } int main() { std::function<void()> a = f; a(); try{ a(); } catch (...) { } std::function<void()> b = g; try { b(); } catch (...) { } } ---