[PATCH] D113585: [clang-tidy] Fix false positive in `bugprone-throw-keyword-missing` check

Fabian Wolff via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 10 10:42:34 PST 2021


fwolff created this revision.
fwolff added reviewers: steveire, alexfh, Eugene.Zelenko.
fwolff added a project: clang-tools-extra.
Herald added subscribers: carlosgalvezp, xazax.hun.
fwolff requested review of this revision.
Herald added a subscriber: cfe-commits.

Fixes PR#52400. The tests for `bugprone-throw-keyword-missing` actually already contain exceptions as class members, but not as members with initializers, which was probably just an oversight.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D113585

Files:
  clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-throw-keyword-missing.cpp


Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-throw-keyword-missing.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-throw-keyword-missing.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-throw-keyword-missing.cpp
@@ -118,6 +118,7 @@
 
 class CtorInitializerListTest {
   RegularException exc;
+  RegularException exc2{};
 
   CtorInitializerListTest() : exc(RegularException()) {}
 
Index: clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
@@ -26,7 +26,7 @@
               isSameOrDerivedFrom(matchesName("[Ee]xception|EXCEPTION")))),
           unless(anyOf(hasAncestor(stmt(
                            anyOf(cxxThrowExpr(), callExpr(), returnStmt()))),
-                       hasAncestor(varDecl()),
+                       hasAncestor(decl(anyOf(varDecl(), fieldDecl()))),
                        allOf(hasAncestor(CtorInitializerList),
                              unless(hasAncestor(cxxCatchStmt()))))))
           .bind("temporary-exception-not-thrown"),


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D113585.386231.patch
Type: text/x-patch
Size: 1295 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211110/0250e283/attachment-0001.bin>


More information about the cfe-commits mailing list