Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ned14 mannequin opened this issue May 21, 2015 · 1 comment
Labels
bugzilla Issues migrated from bugzilla clang-tidy

Comments

@ned14
Copy link
Mannequin

ned14 mannequin commented May 21, 2015

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

@JonasToth
Copy link
Member

This is implemented in bugprone-exception-escape, that checks that no exception can escape from a destructor and other functions that should not throw.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla clang-tidy
Projects
None yet
Development

No branches or pull requests

1 participant