https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83400
Bug ID: 83400 Summary: g++ -O1 doesn't execute any code in destructors with a throw statement if it sees another throw Product: gcc Version: 7.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: redbeard0531 at gmail dot com Target Milestone: --- Repro code below doesn't print the "in dtor" line when compiled with -O1 or higher. It does with g++ -O0 and with clang++ at any optimization level. Note that even with the raise() call enabled, which would prevent the second exception from firing, it still won't print "in dtor". I've reproed with g++ 4.8.2, 5.4.0, 7.2.0, and 7.2.1, all on linux. No warnings are output even with -Wall -Wextra. #include <exception> #include <string> #include <iostream> #include <signal.h> struct ThrowInDtor{ ~ThrowInDtor() noexcept(false) { std::cout << "in dtor" << std::endl; // Doesn't print. // raise(SIGINT); // Still repros with this commented in. throw std::exception(); } }; int main() { try { ThrowInDtor throws; throw std::exception(); } catch (std::exception&) { // unreachable } }