Author: Carlos Galvez Date: 2024-11-09T22:04:17+01:00 New Revision: 69fb9bcde0312e672e6f2280f8662784731d79e6
URL: https://github.com/llvm/llvm-project/commit/69fb9bcde0312e672e6f2280f8662784731d79e6 DIFF: https://github.com/llvm/llvm-project/commit/69fb9bcde0312e672e6f2280f8662784731d79e6.diff LOG: Fix false positive in bugprone-throw-keyword-missing (#115302) Fixes #115055 --------- Co-authored-by: Carlos Gálvez <carlos.gal...@zenseact.com> Added: Modified: clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp clang-tools-extra/docs/ReleaseNotes.rst clang-tools-extra/test/clang-tidy/checkers/bugprone/throw-keyword-missing.cpp Removed: ################################################################################ diff --git a/clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp index 64c155c29cf8b9..17d2e75e4f666f 100644 --- a/clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp @@ -15,9 +15,6 @@ using namespace clang::ast_matchers; namespace clang::tidy::bugprone { void ThrowKeywordMissingCheck::registerMatchers(MatchFinder *Finder) { - auto CtorInitializerList = - cxxConstructorDecl(hasAnyConstructorInitializer(anything())); - Finder->addMatcher( cxxConstructExpr( hasType(cxxRecordDecl( @@ -27,7 +24,7 @@ void ThrowKeywordMissingCheck::registerMatchers(MatchFinder *Finder) { stmt(anyOf(cxxThrowExpr(), callExpr(), returnStmt()))), hasAncestor(decl(anyOf(varDecl(), fieldDecl()))), hasAncestor(expr(cxxNewExpr(hasAnyPlacementArg(anything())))), - allOf(hasAncestor(CtorInitializerList), + allOf(hasAncestor(cxxConstructorDecl()), unless(hasAncestor(cxxCatchStmt())))))) .bind("temporary-exception-not-thrown"), this); diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index abcdcc25705bf5..c79f423bac5f06 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -177,6 +177,10 @@ Changes in existing checks usages of ``sizeof()``, ``alignof()``, and ``offsetof()`` when adding or subtracting from a pointer directly or when used to scale a numeric value. +- Improved :doc:`bugprone-throw-keyword-missing + <clang-tidy/checks/bugprone/throw-keyword-missing>` by fixing a false positive + when using non-static member initializers and a constructor. + - Improved :doc:`bugprone-unchecked-optional-access <clang-tidy/checks/bugprone/unchecked-optional-access>` to support `bsl::optional` and `bdlb::NullableValue` from diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/throw-keyword-missing.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/throw-keyword-missing.cpp index 49233c0deefdf0..bafd3d19b5a319 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/throw-keyword-missing.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/throw-keyword-missing.cpp @@ -139,6 +139,15 @@ CtorInitializerListTest::CtorInitializerListTest(float) try : exc(RegularExcepti RegularException(); } +namespace GH115055 { +class CtorInitializerListTest2 { + public: + CtorInitializerListTest2() {} + private: + RegularException exc{}; +}; +} // namespace GH115055 + RegularException funcReturningExceptionTest(int i) { return RegularException(); } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits