diff --git a/clang-tools-extra/clang-tidy/bugprone/EmptyCatchCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/EmptyCatchCheck.cpp index eebab847d1070..16264b9af1ae0 100644 --- a/clang-tools-extra/clang-tidy/bugprone/EmptyCatchCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/EmptyCatchCheck.cpp @@ -90,6 +90,7 @@ void EmptyCatchCheck::registerMatchers(MatchFinder *Finder) { Finder->addMatcher( cxxCatchStmt(unless(isExpansionInSystemHeader()), unless(isInMacro()), unless(hasCaughtType(IgnoredExceptionType)), + unless(hasDeclContext(cxxDestructorDecl())), hasHandler(compoundStmt( statementCountIs(0), unless(hasAnyTextFromList(IgnoreCatchWithKeywords))))) diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index c3a6d2f9b2890..426c97225c0e1 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -244,6 +244,10 @@ Changes in existing checks correcting a spelling mistake on its option ``NamePrefixSuffixSilenceDissimilarityTreshold``. +- Improved :doc:`bugprone-empty-catch + ` check by allowing empty + ``catch`` blocks in destructors. + - Improved :doc:`bugprone-exception-escape ` check's handling of lambdas: exceptions from captures are now diagnosed, exceptions in the bodies of diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/empty-catch.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/empty-catch.cpp index 8ab38229b6dbf..1319496269d86 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/empty-catch.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/empty-catch.cpp @@ -65,3 +65,12 @@ void functionWithComment2() { // @IGNORE: relax its safe } } + +struct StructWithEmptyCatchInDestructor { + ~StructWithEmptyCatchInDestructor() { + try { + } + catch (...) { + } + } +};