Skip to content

Commit 637aca8

Browse files
committed
Fixed #10752 (False positive: shadow variable in static method)
1 parent 38420c8 commit 637aca8

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

lib/checkother.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3273,6 +3273,8 @@ void CheckOther::checkShadowVariables()
32733273
continue;
32743274
if (scope.type == Scope::eFunction && scope.className == var.name())
32753275
continue;
3276+
if (functionScope->function && functionScope->function->isStatic() && shadowed->variable() && !shadowed->variable()->isLocal())
3277+
continue;
32763278
shadowError(var.nameToken(), shadowed, (shadowed->varId() != 0) ? "variable" : "function");
32773279
}
32783280
}

test/testother.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9323,6 +9323,17 @@ class TestOther : public TestFixture {
93239323

93249324
check("class C { C(); void foo() { static int C = 0; } }"); // #9195 - shadow constructor
93259325
ASSERT_EQUALS("", errout.str());
9326+
9327+
// 10752 - no
9328+
check("struct S {\n"
9329+
" int i;\n"
9330+
"\n"
9331+
" static int foo() {\n"
9332+
" int i = 0;\n"
9333+
" return i;\n"
9334+
" }\n"
9335+
"};");
9336+
ASSERT_EQUALS("", errout.str());
93269337
}
93279338

93289339
void knownArgument() {

0 commit comments

Comments
 (0)