Skip to content

Commit 4371296

Browse files
committed
Fix #13888 FP shadowVariable in friend function
1 parent f1fa374 commit 4371296

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

lib/checkother.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4053,7 +4053,8 @@ void CheckOther::checkShadowVariables()
40534053
continue;
40544054
if (scope.type == ScopeType::eFunction && scope.className == var.name())
40554055
continue;
4056-
if (functionScope->functionOf && functionScope->functionOf->isClassOrStructOrUnion() && functionScope->function && functionScope->function->isStatic() &&
4056+
if (functionScope->functionOf && functionScope->functionOf->isClassOrStructOrUnion() && functionScope->function &&
4057+
(functionScope->function->isStatic() || functionScope->function->isFriend()) &&
40574058
shadowed->variable() && !shadowed->variable()->isLocal())
40584059
continue;
40594060
shadowError(var.nameToken(), shadowed, (shadowed->varId() != 0) ? "variable" : "function");

test/testother.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12386,6 +12386,12 @@ class TestOther : public TestFixture {
1238612386
"}\n"
1238712387
"int g() { return 1; }\n");
1238812388
ASSERT_EQUALS("", errout_str());
12389+
12390+
check("struct S {\n" // #13888
12391+
" int i;\n"
12392+
" friend int f() { int i = 5; return i; }\n"
12393+
"};\n");
12394+
ASSERT_EQUALS("", errout_str());
1238912395
}
1239012396

1239112397
void knownArgument() {

0 commit comments

Comments
 (0)