Skip to content

Commit 73f8b9c

Browse files
committed
Fix
1 parent 15e1882 commit 73f8b9c

2 files changed

Lines changed: 16 additions & 7 deletions

File tree

lib/checkother.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3339,13 +3339,11 @@ static bool checkVariableAssignment(const Token* tok, const Settings& settings)
33393339
return false;
33403340
if (isVariableChanged(var, settings))
33413341
return false;
3342-
if (var->isMember()) {
3343-
const Scope* scope = tok->scope();
3344-
while (scope && scope->type != ScopeType::eFunction)
3345-
scope = scope->nestedIn;
3346-
if (!scope || !scope->function || (!scope->function->isConst() && !scope->function->isStatic()))
3347-
return false;
3348-
}
3342+
const Scope* scope = tok->scope();
3343+
while (scope && scope->type != ScopeType::eFunction)
3344+
scope = scope->nestedIn;
3345+
if (!scope || !scope->function || (scope->functionOf && !scope->function->isConst() && !scope->function->isStatic()))
3346+
return false;
33493347
return true;
33503348
}
33513349

test/testother.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9899,6 +9899,17 @@ class TestOther : public TestFixture {
98999899
ASSERT_EQUALS("[test.cpp:2:17]: (performance, inconclusive) Use const reference for 's1' to avoid unnecessary data copying. [redundantCopyLocalConst]\n"
99009900
"[test.cpp:7:17]: (performance, inconclusive) Use const reference for 's1' to avoid unnecessary data copying. [redundantCopyLocalConst]\n",
99019901
errout_str());
9902+
9903+
check("struct S {\n"
9904+
" std::string m;\n"
9905+
" int f(const std::string& s);\n"
9906+
"};\n"
9907+
"int S::f(const std::string& s) {\n"
9908+
" std::string c = s;\n"
9909+
" m.clear();\n"
9910+
" return c.size();\n"
9911+
"}\n");
9912+
ASSERT_EQUALS("", errout_str());
99029913
}
99039914

99049915
void checkNegativeShift() {

0 commit comments

Comments
 (0)