Author: Fabian Wolff
Date: 2021-11-16T07:09:17-05:00
New Revision: 738e7f1231949ec248c1d8d154783338215613d1

URL: 
https://github.com/llvm/llvm-project/commit/738e7f1231949ec248c1d8d154783338215613d1
DIFF: 
https://github.com/llvm/llvm-project/commit/738e7f1231949ec248c1d8d154783338215613d1.diff

LOG: Fix false positive in `bugprone-throw-keyword-missing` check

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.

Added: 
    

Modified: 
    clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
    
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 462a33a374a5f..5327a0c8d4c6b 100644
--- a/clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
@@ -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"),

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 5fae036fc5a39..dff600c947070 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
@@ -118,6 +118,7 @@ void localVariableInitTest() {
 
 class CtorInitializerListTest {
   RegularException exc;
+  RegularException exc2{};
 
   CtorInitializerListTest() : exc(RegularException()) {}
 


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to