From da6e0308c514e86c0138289b74588c7dad825352 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 20 Apr 2020 18:02:10 +0200 Subject: [PATCH] Fixed #9195 (False positive: shadowFunction when constructor is shadowed) --- lib/checkother.cpp | 2 +- test/testother.cpp | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index ac9d85d32..462b410a7 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -2944,7 +2944,7 @@ static const Token *findShadowed(const Scope *scope, const std::string &varname, return var.nameToken(); } for (const Function &f : scope->functionList) { - if (f.name() == varname) + if (f.type == Function::Type::eFunction && f.name() == varname) return f.tokenDef; } if (scope->type == Scope::eLambda) diff --git a/test/testother.cpp b/test/testother.cpp index 57eab7eb5..3d3420249 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -8316,6 +8316,9 @@ private: check("void f(int x) { int x; }"); ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:1]: (style) Local variable 'x' shadows outer argument\n", errout.str()); + + check("class C { C(); void foo() { static int C = 0; } }"); // #9195 - shadow constructor + ASSERT_EQUALS("", errout.str()); } void constArgument() {