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
2 changes: 1 addition & 1 deletion lib/astutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2772,7 +2772,7 @@ static bool isExpressionChangedAt(const F& getExprTok,
return true;
if (tok->isLiteral() || tok->isKeyword() || tok->isStandardType() || Token::Match(tok, ",|;|:"))
return false;
if (tok->exprId() != exprid) {
if (tok->exprId() != exprid || (!tok->varId() && !tok->isName())) {
if (globalvar && Token::Match(tok, "%name% (") && !(tok->function() && tok->function()->isAttributePure()))
// TODO: Is global variable really changed by function call?
return true;
Expand Down
32 changes: 32 additions & 0 deletions test/teststl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class TestStl : public TestFixture {
TEST_CASE(iterator26); // #9176
TEST_CASE(iterator27); // #10378
TEST_CASE(iterator28); // #10450
TEST_CASE(iterator29);
TEST_CASE(iteratorExpression);
TEST_CASE(iteratorSameExpression);
TEST_CASE(mismatchingContainerIterator);
Expand Down Expand Up @@ -1846,6 +1847,37 @@ class TestStl : public TestFixture {
ASSERT_EQUALS("[test.cpp:10]: (style) Consider using std::find_if algorithm instead of a raw loop.\n", errout.str());
}

void iterator29()
{
// #11511
check("std::vector<int>& g();\n"
"void f() {\n"
" auto v = g();\n"
" auto it = g().begin();\n"
" while (it != g().end())\n"
" it = v.erase(it);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:6]: (error) Iterator 'it' from different container 'v' are used together.\n", errout.str());

check("std::vector<int>& g(int);\n"
"void f(int i, int j) {\n"
" auto& r = g(i);\n"
" auto it = g(j).begin();\n"
" while (it != g(j).end())\n"
" it = r.erase(it);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:6]: (error) Iterator 'it' from different container 'r' are used together.\n", errout.str());

check("std::vector<int>& g();\n"
"void f() {\n"
" auto& r = g();\n"
" auto it = g().begin();\n"
" while (it != g().end())\n"
" it = r.erase(it);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}

void iteratorExpression() {
check("std::vector<int>& f();\n"
"std::vector<int>& g();\n"
Expand Down