https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82741
Bug ID: 82741 Summary: Optimisations may cause noexcept specifier to be ignored Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: pdziepak at quarnos dot org Target Milestone: --- On x86_64: gcc version 7.2.1 20170915 (Red Hat 7.2.1-2) (GCC) The following code results in noexcept being ignored if optimisations are enabled. ---<snip>--- volatile bool should_throw = false; [[gnu::noinline]] void foo() { if (should_throw) { throw 42; } } [[gnu::noinline]] void bar() noexcept { should_throw = true; foo(); } int main() { try { foo(); bar(); foo(); } catch (...) { } } ---<snip>--- When compiled with -O1 or higher exception thrown from bar() doesn't cause std::terminate to be called. bar() is compiled to: 0000000000400730 <bar()>: 400730: c6 05 2a 09 20 00 01 movb $0x1,0x20092a(%rip) # 601061 <should_throw> 400737: eb c7 jmp 400700 <foo()>