This revision was automatically updated to reflect the committed changes.
Closed by commit rGefcd09cea9a5: [clang-tidy] Fix false positive for
cppcoreguidelines-init-variables (authored by njames93).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D73843/new/
https://reviews.llvm.org/D73843
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
@@ -78,3 +78,9 @@
int parens(42);
int braces{42};
}
+
+template <typename RANGE>
+void f(RANGE r) {
+ for (char c : r) {
+ }
+}
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
@@ -29,11 +29,15 @@
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,
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
@@ -78,3 +78,9 @@
int parens(42);
int braces{42};
}
+
+template <typename RANGE>
+void f(RANGE r) {
+ for (char c : r) {
+ }
+}
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
@@ -29,11 +29,15 @@
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,
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits