njames93 created this revision. njames93 added reviewers: aaron.ballman, alexfh, gribozavr2. Herald added subscribers: cfe-commits, kbarton, xazax.hun, nemanjai. Herald added a project: clang.
Ignore catch statement var decls. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D82924 Files: clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-init-variables.cpp Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-init-variables.cpp =================================================================== --- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-init-variables.cpp +++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-init-variables.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy %s cppcoreguidelines-init-variables %t -- -- -fno-delayed-template-parsing +// RUN: %check_clang_tidy %s cppcoreguidelines-init-variables %t -- -- -fno-delayed-template-parsing -fexceptions // Ensure that function declarations are not changed. void some_func(int x, double d, bool b, const char *p); @@ -84,3 +84,10 @@ for (char c : r) { } } + +void catch_variable_decl() { + // Expect no warning given here. + try { + } catch (int X) { + } +} \ No newline at end of file Index: clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp =================================================================== --- clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp +++ clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp @@ -9,6 +9,7 @@ #include "InitVariablesCheck.h" #include "clang/AST/ASTContext.h" +#include "clang/AST/StmtCXX.h" #include "clang/ASTMatchers/ASTMatchFinder.h" #include "clang/Lex/PPCallbacks.h" #include "clang/Lex/Preprocessor.h" @@ -42,6 +43,7 @@ Finder->addMatcher( varDecl(unless(hasInitializer(anything())), unless(isInstantiated()), isLocalVarDecl(), unless(isStaticLocal()), isDefinition(), + unless(hasParent(cxxCatchStmt())), optionally(hasParent(declStmt(hasParent( cxxForRangeStmt(hasLoopVariable(varDecl().bind(BadDecl))))))), unless(equalsBoundNode(BadDecl)))
Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-init-variables.cpp =================================================================== --- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-init-variables.cpp +++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-init-variables.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy %s cppcoreguidelines-init-variables %t -- -- -fno-delayed-template-parsing +// RUN: %check_clang_tidy %s cppcoreguidelines-init-variables %t -- -- -fno-delayed-template-parsing -fexceptions // Ensure that function declarations are not changed. void some_func(int x, double d, bool b, const char *p); @@ -84,3 +84,10 @@ for (char c : r) { } } + +void catch_variable_decl() { + // Expect no warning given here. + try { + } catch (int X) { + } +} \ No newline at end of file Index: clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp =================================================================== --- clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp +++ clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp @@ -9,6 +9,7 @@ #include "InitVariablesCheck.h" #include "clang/AST/ASTContext.h" +#include "clang/AST/StmtCXX.h" #include "clang/ASTMatchers/ASTMatchFinder.h" #include "clang/Lex/PPCallbacks.h" #include "clang/Lex/Preprocessor.h" @@ -42,6 +43,7 @@ Finder->addMatcher( varDecl(unless(hasInitializer(anything())), unless(isInstantiated()), isLocalVarDecl(), unless(isStaticLocal()), isDefinition(), + unless(hasParent(cxxCatchStmt())), optionally(hasParent(declStmt(hasParent( cxxForRangeStmt(hasLoopVariable(varDecl().bind(BadDecl))))))), unless(equalsBoundNode(BadDecl)))
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits