summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathan James <n.james93@hotmail.co.uk>2020-02-02 21:26:04 +0000
committerHans Wennborg <hans@chromium.org>2020-02-10 14:17:54 +0100
commit84cda4cceabdfec4f130bfafe7bbd050aa65b2ec (patch)
tree75071bd374756c72c9aea16ef5310db55bc9b8fb
parent8b8a4834a4b8aaff751c95e458d7a01ceae081a2 (diff)
downloadbcm5719-llvm-84cda4cceabdfec4f130bfafe7bbd050aa65b2ec.tar.gz
bcm5719-llvm-84cda4cceabdfec4f130bfafe7bbd050aa65b2ec.zip
[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 (cherry picked from commit efcd09cea9a51c522954aa24e4b5513266daf6c3)
-rw-r--r--clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp14
-rw-r--r--clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-init-variables.cpp6
2 files changed, 15 insertions, 5 deletions
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp
index 8a628317a30..a5d9275afaf 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp
@@ -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,
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 d43e44808a4..4c92e1976f9 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
@@ -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) {
+ }
+}
OpenPOWER on IntegriCloud