Fix false positive in `bugprone-throw-keyword-missing` check
authorFabian Wolff <fabian.wolff@alumni.ethz.ch>
Tue, 16 Nov 2021 12:09:17 +0000 (07:09 -0500)
committerAaron Ballman <aaron@aaronballman.com>
Tue, 16 Nov 2021 12:09:17 +0000 (07:09 -0500)
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.

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

index 462a33a..5327a0c 100644 (file)
@@ -26,7 +26,7 @@ void ThrowKeywordMissingCheck::registerMatchers(MatchFinder *Finder) {
               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"),
index 5fae036..dff600c 100644 (file)
@@ -118,6 +118,7 @@ void localVariableInitTest() {
 
 class CtorInitializerListTest {
   RegularException exc;
+  RegularException exc2{};
 
   CtorInitializerListTest() : exc(RegularException()) {}