You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Extending #23519, many people who simply add -std=c++11 to their command line fail to adjust their destructors to never throw exceptions. This matters because under C++ 11 the default is for destructors to be noexcept, so any thrown exceptions means an instant std::terminate unlike in C++ 03.
Therefore if clang-tidy could issue a warning for this combination of factors:
(a) -std=c++11 or later is specified
(b) A destructor is noexcept
(c) Any calls to noexcept unspecified or false functions are made not wrapped in a try...catch(...) - note the catch all ellipsis.
(d) If any of the catch handlers rethrow, or throw another exception, a warning should also be given.
That is probably good enough for a minimal implementation. If however you can also recursively analyse all functions called without a noexcept to see if they call code which could throw, one could apply this warning not just to destructors, but to any noexcept function. Ideally, for any noexcept function there should be a warning if any exception throw could ever exit that function. This I think would be an extremely useful new warning indeed, as even the very highest quality C++ code can accidentally miss bad_alloc meeting a noexcept function.
Niall
The text was updated successfully, but these errors were encountered:
This is implemented in bugprone-exception-escape, that checks that no exception can escape from a destructor and other functions that should not throw.
Extended Description
Extending #23519, many people who simply add -std=c++11 to their command line fail to adjust their destructors to never throw exceptions. This matters because under C++ 11 the default is for destructors to be noexcept, so any thrown exceptions means an instant std::terminate unlike in C++ 03.
Therefore if clang-tidy could issue a warning for this combination of factors:
(a) -std=c++11 or later is specified
(b) A destructor is noexcept
(c) Any calls to noexcept unspecified or false functions are made not wrapped in a try...catch(...) - note the catch all ellipsis.
(d) If any of the catch handlers rethrow, or throw another exception, a warning should also be given.
That is probably good enough for a minimal implementation. If however you can also recursively analyse all functions called without a noexcept to see if they call code which could throw, one could apply this warning not just to destructors, but to any noexcept function. Ideally, for any noexcept function there should be a warning if any exception throw could ever exit that function. This I think would be an extremely useful new warning indeed, as even the very highest quality C++ code can accidentally miss bad_alloc meeting a noexcept function.
Niall
The text was updated successfully, but these errors were encountered: