diff --git a/lib/astutils.cpp b/lib/astutils.cpp index 64c5a74a3c6..e28993f76e7 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -2579,8 +2579,8 @@ bool isVariableChanged(const Token *tok, int indirect, const Settings *settings, if (indirect == 0 && astIsPointer(tok)) return false; - const Token *ftok = tok->tokAt(2); - if (astIsContainer(tok) && vt && vt->container) { + const Token *ftok = tok2->astParent()->astOperand2(); + if (astIsContainer(tok2->astParent()->astOperand1()) && vt && vt->container) { const Library::Container* c = vt->container; const Library::Container::Action action = c->getAction(ftok->str()); if (contains({Library::Container::Action::INSERT, diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index b69010bd9b4..676d69733b4 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -659,12 +659,11 @@ std::vector CheckClass::createUsageList(const Scope *scope) void CheckClass::assignVar(std::vector &usageList, nonneg int varid) { - for (Usage& usage: usageList) { - if (usage.var->declarationId() == varid) { - usage.assign = true; - return; - } - } + auto it = std::find_if(usageList.begin(), usageList.end(), [varid](const Usage& usage) { + return usage.var->declarationId() == varid; + }); + if (it != usageList.end()) + it->assign = true; } void CheckClass::assignVar(std::vector &usageList, const Token* vartok) @@ -673,23 +672,21 @@ void CheckClass::assignVar(std::vector &usageList, const Token* vartok) assignVar(usageList, vartok->varId()); return; } - for (Usage& usage: usageList) { + auto it = std::find_if(usageList.begin(), usageList.end(), [vartok](const Usage& usage) { // FIXME: This is a workaround when varid is not set for a derived member - if (usage.var->name() == vartok->str()) { - usage.assign = true; - return; - } - } + return usage.var->name() == vartok->str(); + }); + if (it != usageList.end()) + it->assign = true; } void CheckClass::initVar(std::vector &usageList, nonneg int varid) { - for (Usage& usage: usageList) { - if (usage.var->declarationId() == varid) { - usage.init = true; - return; - } - } + auto it = std::find_if(usageList.begin(), usageList.end(), [varid](const Usage& usage) { + return usage.var->declarationId() == varid; + }); + if (it != usageList.end()) + it->init = true; } void CheckClass::assignAllVar(std::vector &usageList) diff --git a/test/testother.cpp b/test/testother.cpp index d3bb8e4d91b..0615492fbdb 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -2191,6 +2191,25 @@ class TestOther : public TestFixture { "}\n"); ASSERT_EQUALS("", errout.str()); + check("struct S { std::list l; };\n" // #12147 + "class C { public: std::list l; };\n" + "bool f(S s) {\n" + " return s.l.empty();\n" + "}\n" + "bool f(C c) {\n" + " return c.l.empty();\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:3]: (performance) Function parameter 's' should be passed by const reference.\n" + "[test.cpp:6]: (performance) Function parameter 'c' should be passed by const reference.\n", + errout.str()); + + check("struct S { std::list a[1][1]; };\n" + "bool f(S s) {\n" + " return s.a[0][0].empty();\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:2]: (performance) Function parameter 's' should be passed by const reference.\n", + errout.str()); + Settings settings1 = settingsBuilder().platform(Platform::Type::Win64).build(); check("using ui64 = unsigned __int64;\n" "ui64 Test(ui64 one, ui64 two) { return one + two; }\n",