[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
This commit is contained in:
Nathan James 2020-07-01 13:40:18 +01:00
parent 37dd8b6ce5
commit 669494e9c0
No known key found for this signature in database
GPG Key ID: CC007AFCDA90AA5F
2 changed files with 9 additions and 1 deletions

View File

@ -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)))

View File

@ -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) {
}
}