diff options
author | Nathan James <n.james93@hotmail.co.uk> | 2020-07-01 13:40:18 +0100 |
---|---|---|
committer | Nathan James <n.james93@hotmail.co.uk> | 2020-07-01 13:40:20 +0100 |
commit | 669494e9c06c78b51260598bba9d84ba7634a53e (patch) | |
tree | a5899009ec04371381d55c4f2f4a6925509351b1 | |
parent | 37dd8b6ce5f3ad6c5b9f6b5498606f8b7723e8ab (diff) | |
download | llvm-669494e9c06c78b51260598bba9d84ba7634a53e.zip llvm-669494e9c06c78b51260598bba9d84ba7634a53e.tar.gz llvm-669494e9c06c78b51260598bba9d84ba7634a53e.tar.bz2 |
[clang-tidy] fix cppcoreguidelines-init-variables with catch variables
Ignore catch statement var decls.
Reviewed By: aaron.ballman
Differential Revision: https://reviews.llvm.org/D82924
-rw-r--r-- | clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp | 1 | ||||
-rw-r--r-- | clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-init-variables.cpp | 9 |
2 files changed, 9 insertions, 1 deletions
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp index e7a57be..2be3bc4 100644 --- a/clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp +++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp @@ -42,6 +42,7 @@ void InitVariablesCheck::registerMatchers(MatchFinder *Finder) { 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))) diff --git a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-init-variables.cpp b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-init-variables.cpp index 4c92e19..9a06850 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-init-variables.cpp +++ b/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 @@ void f(RANGE r) { for (char c : r) { } } + +void catch_variable_decl() { + // Expect no warning given here. + try { + } catch (int X) { + } +} |