Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/astutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion lib/valueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
17 changes: 17 additions & 0 deletions test/testother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3753,6 +3753,23 @@ class TestOther : public TestFixture {
" return g(a, s.x);\n"
"}\n");
ASSERT_EQUALS("", errout_str());

check("struct S { std::vector<int> v; };\n" // #13317
"struct T { S s; };\n"
"int f(S& s) {\n"
" for (std::vector<int>::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<int>& 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() {
Expand Down