Skip to content

Add clang-tidy warning for destructors which call noexcept(false) code not wrapped in a try...catch #23992

Closed
@ned14

Description

@ned14
Bugzilla Link 23618
Resolution FIXED
Resolved on Oct 02, 2018 14:09
Version unspecified
OS Windows NT
CC @chandlerc,@JonasToth

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions