forked from OSchip/llvm-project
[clang-tidy] Fix false positive for cppcoreguidelines-init-variables
Summary: Fixes [[ https://bugs.llvm.org/show_bug.cgi?id=44746 | False positive for cppcoreguidelines-init-variables in range based for loop in template function ]] Reviewers: aaron.ballman, alexfh, hokein, JonasToth, gribozavr2 Reviewed By: aaron.ballman Subscribers: merge_guards_bot, xazax.hun, wuzish, nemanjai, kbarton, cfe-commits Tags: #clang, #clang-tools-extra Differential Revision: https://reviews.llvm.org/D73843
This commit is contained in:
parent
ee85415dbb
commit
efcd09cea9
|
@ -29,11 +29,15 @@ InitVariablesCheck::InitVariablesCheck(StringRef Name,
|
|||
MathHeader(Options.get("MathHeader", "math.h")) {}
|
||||
|
||||
void InitVariablesCheck::registerMatchers(MatchFinder *Finder) {
|
||||
Finder->addMatcher(varDecl(unless(hasInitializer(anything())),
|
||||
unless(isInstantiated()), isLocalVarDecl(),
|
||||
unless(isStaticLocal()), isDefinition())
|
||||
.bind("vardecl"),
|
||||
this);
|
||||
std::string BadDecl = "badDecl";
|
||||
Finder->addMatcher(
|
||||
varDecl(unless(hasInitializer(anything())), unless(isInstantiated()),
|
||||
isLocalVarDecl(), unless(isStaticLocal()), isDefinition(),
|
||||
optionally(hasParent(declStmt(hasParent(
|
||||
cxxForRangeStmt(hasLoopVariable(varDecl().bind(BadDecl))))))),
|
||||
unless(equalsBoundNode(BadDecl)))
|
||||
.bind("vardecl"),
|
||||
this);
|
||||
}
|
||||
|
||||
void InitVariablesCheck::registerPPCallbacks(const SourceManager &SM,
|
||||
|
|
|
@ -78,3 +78,9 @@ void init_unit_tests() {
|
|||
int parens(42);
|
||||
int braces{42};
|
||||
}
|
||||
|
||||
template <typename RANGE>
|
||||
void f(RANGE r) {
|
||||
for (char c : r) {
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue