diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 123a9fce2ee..b90d8315d66 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -4053,7 +4053,8 @@ void CheckOther::checkShadowVariables() continue; if (scope.type == ScopeType::eFunction && scope.className == var.name()) continue; - if (functionScope->functionOf && functionScope->functionOf->isClassOrStructOrUnion() && functionScope->function && functionScope->function->isStatic() && + if (functionScope->functionOf && functionScope->functionOf->isClassOrStructOrUnion() && functionScope->function && + (functionScope->function->isStatic() || functionScope->function->isFriend()) && shadowed->variable() && !shadowed->variable()->isLocal()) continue; shadowError(var.nameToken(), shadowed, (shadowed->varId() != 0) ? "variable" : "function"); diff --git a/test/testother.cpp b/test/testother.cpp index c126675a84b..b8cc67b1169 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -12386,6 +12386,12 @@ class TestOther : public TestFixture { "}\n" "int g() { return 1; }\n"); ASSERT_EQUALS("", errout_str()); + + check("struct S {\n" // #13888 + " int i;\n" + " friend int f() { int i = 5; return i; }\n" + "};\n"); + ASSERT_EQUALS("", errout_str()); } void knownArgument() {