From 5bf617ba9f723fbfdee2dadba320a0e18d05a129 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 26 Nov 2024 10:59:39 +0100 Subject: [PATCH 1/5] Update astutils.cpp --- lib/astutils.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/astutils.cpp b/lib/astutils.cpp index cc6a0e21748..79d4b76cb00 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -2676,8 +2676,13 @@ 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* ctok = tok2->astParent(); + if (Token::simpleMatch(ctok->astOperand1(), ".")) + ctok = ctok->astOperand1()->astOperand2(); + else + ctok = ctok->astOperand1(); + 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, From 2af55d2a805af4171ae7279370853c67b65ea521 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 26 Nov 2024 11:00:33 +0100 Subject: [PATCH 2/5] Update testother.cpp --- test/testother.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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() { From fc6b605ac34d03afa0976a39bcd09c42f7b02136 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 26 Nov 2024 12:05:55 +0100 Subject: [PATCH 3/5] Update valueflow.cpp --- lib/valueflow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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) { From 2d016c389dc679e74669e2b85145535f1361f193 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 5 Dec 2024 23:45:06 +0100 Subject: [PATCH 4/5] Update astutils.cpp --- lib/astutils.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/astutils.cpp b/lib/astutils.cpp index 79d4b76cb00..c25603cb54d 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -2676,11 +2676,9 @@ bool isVariableChanged(const Token *tok, int indirect, const Settings &settings, return false; const Token *ftok = tok2->astParent()->astOperand2(); - const Token* ctok = tok2->astParent(); - if (Token::simpleMatch(ctok->astOperand1(), ".")) - ctok = ctok->astOperand1()->astOperand2(); - else - ctok = ctok->astOperand1(); + const Token* ctok = tok2; + if (Token::simpleMatch(tok2, ".")) + ctok = tok2->astOperand2(); if (astIsContainer(ctok) && ctok->valueType() && ctok->valueType()->container) { const Library::Container* c = ctok->valueType()->container; const Library::Container::Action action = c->getAction(ftok->str()); From 7e61f840685f027532373ea58c02a5a2f4b2e469 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Fri, 6 Dec 2024 15:00:07 +0100 Subject: [PATCH 5/5] Update astutils.cpp --- lib/astutils.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/astutils.cpp b/lib/astutils.cpp index c25603cb54d..a9381d66aa9 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -2676,9 +2676,7 @@ bool isVariableChanged(const Token *tok, int indirect, const Settings &settings, return false; const Token *ftok = tok2->astParent()->astOperand2(); - const Token* ctok = tok2; - if (Token::simpleMatch(tok2, ".")) - ctok = tok2->astOperand2(); + 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());