diff --git a/lib/astutils.cpp b/lib/astutils.cpp index cc6a0e21748..a9381d66aa9 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -2676,8 +2676,9 @@ bool isVariableChanged(const Token *tok, int indirect, const Settings &settings, return false; const Token *ftok = tok2->astParent()->astOperand2(); - if (astIsContainer(tok2->astParent()->astOperand1()) && vt && vt->container) { - const Library::Container* c = vt->container; + const Token* const ctok = tok2->str() == "." ? tok2->astOperand2() : tok2; + if (astIsContainer(ctok) && ctok->valueType() && ctok->valueType()->container) { + const Library::Container* c = ctok->valueType()->container; const Library::Container::Action action = c->getAction(ftok->str()); if (contains({Library::Container::Action::INSERT, Library::Container::Action::ERASE, diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 775193b34ba..8519aa0c96a 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -5494,7 +5494,7 @@ static void valueFlowLibraryFunction(Token* tok, const std::string& returnValue, } static void valueFlowSubFunction(const TokenList& tokenlist, - SymbolDatabase& symboldatabase, + const SymbolDatabase& symboldatabase, ErrorLogger& errorLogger, const Settings& settings) { diff --git a/test/testother.cpp b/test/testother.cpp index 1a4d10c4f16..ff2e027d34a 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -3753,6 +3753,23 @@ class TestOther : public TestFixture { " return g(a, s.x);\n" "}\n"); ASSERT_EQUALS("", errout_str()); + + check("struct S { std::vector v; };\n" // #13317 + "struct T { S s; };\n" + "int f(S& s) {\n" + " for (std::vector::const_iterator it = s.v.cbegin(); it != s.v.cend(); ++it) {}\n" + " return *s.v.cbegin();\n" + "}\n" + "int f(T& t) {\n" + " return *t.s.v.cbegin();\n" + "}\n" + "int f(std::vector& v) {\n" + " return *v.cbegin();\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:3]: (style) Parameter 's' can be declared as reference to const\n" + "[test.cpp:7]: (style) Parameter 't' can be declared as reference to const\n" + "[test.cpp:10]: (style) Parameter 'v' can be declared as reference to const\n", + errout_str()); } void constParameterCallback() {