GCC produces a warning for void foo() noexcept { throw 42; } But not for static void bar() { throw 42; } void foo() noexcept { bar(); } Such a warning would be quite handy for checking the usage of noexcept in a codebase.
Confirmed with the output below. -Wterminate is fully implemented in the C++ front-end so it doesn't know about what might happen in called functions. Implementing the detection across inlined functions requires moving the warning to the middle-end and deciding how to deal with situations where the called function throws only under some non-constant conditions (e.g., issue -Wterminate regardless, or a -Wmaybe-terminate kind of a warning, or none). $ gcc -O2 -Wall -Wextra -S -Wall a.C void foo () noexcept { throw 42; } static void bar () { throw 42; } void foobar () noexcept { bar (); } a.C: In function ‘void foo()’: a.C:3:5: warning: ‘throw’ will always call ‘terminate’ [-Wterminate] 3 | throw 42; | ^~~~~~~~
(In reply to Martin Sebor from comment #1) > Confirmed with the output below. -Wterminate is fully implemented in the > C++ front-end so it doesn't know about what might happen in called > functions. Implementing the detection across inlined functions requires > moving the warning to the middle-end and deciding how to deal with > situations where the called function throws only under some non-constant > conditions (e.g., issue -Wterminate regardless, or a -Wmaybe-terminate kind > of a warning, or none). I would be happy even with a "noexcept function calls a non-noexcept one" warning.
That would likely be far too noisy for use 99% of the time.
dup of bug 61372 *** This bug has been marked as a duplicate of bug 61372 ***