I use noexcept heavily, and unfortunately if some transitive dependency ends up throwing in a rare case (unbeknownst to us), the crashes are extremely hard to debug - because noexcept
causes std::terminate
to get called.
Is there any way to detect these violations at compile time? In the example below the problem is obvious, but no compiler catches it by default. I realize it's not possible in all cases, but surely simpler cases should be possible
#include <stdexcept>
void baz()
{
throw std::runtime_error("std::terminate awaits");
}
void bar()
{
baz();
}
void foo() noexcept
{
bar();
}
Link to godbolt: https://godbolt.org/z/Ooet58
Are there compiler flags I don't know about? What about a static analysis tool that catches this?