Skip to content

Commit ac4a86a

Browse files
authored
[clang-tidy]: Ignore empty catch blocks in destructors in bugprone-empty-catch check
1 parent 6f1f00c commit ac4a86a

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

clang-tools-extra/clang-tidy/bugprone/EmptyCatchCheck.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ void EmptyCatchCheck::registerMatchers(MatchFinder *Finder) {
9090
Finder->addMatcher(
9191
cxxCatchStmt(unless(isExpansionInSystemHeader()), unless(isInMacro()),
9292
unless(hasCaughtType(IgnoredExceptionType)),
93+
unless(hasAncestor(cxxDestructorDecl())),
9394
hasHandler(compoundStmt(
9495
statementCountIs(0),
9596
unless(hasAnyTextFromList(IgnoreCatchWithKeywords)))))

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,10 @@ Changes in existing checks
244244
correcting a spelling mistake on its option
245245
``NamePrefixSuffixSilenceDissimilarityTreshold``.
246246

247+
- Improved :doc:`bugprone-empty-catch
248+
<clang-tidy/checks/bugprone/empty-catch>` check by allowing empty
249+
``catch`` blocks in destructors.
250+
247251
- Improved :doc:`bugprone-exception-escape
248252
<clang-tidy/checks/bugprone/exception-escape>` check's handling of lambdas:
249253
exceptions from captures are now diagnosed, exceptions in the bodies of

clang-tools-extra/test/clang-tidy/checkers/bugprone/empty-catch.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,12 @@ void functionWithComment2() {
6565
// @IGNORE: relax its safe
6666
}
6767
}
68+
69+
struct StructWithEmptyCatchInDestructor {
70+
~StructWithEmptyCatchInDestructor() {
71+
try {
72+
}
73+
catch (...) {
74+
}
75+
}
76+
};

0 commit comments

Comments
 (0)