Fixed #5803 (False positive: Same iterator is used with different containers - insert() from range of different container)
This commit is contained in:
parent
55b3f0bf38
commit
2566fd09da
|
@ -165,6 +165,20 @@ void CheckStl::iterators()
|
||||||
if (itTok->previous()->str() == "*")
|
if (itTok->previous()->str() == "*")
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
// inserting iterator range..
|
||||||
|
if (tok2->strAt(2) == "insert") {
|
||||||
|
const Token *par2 = itTok->nextArgument();
|
||||||
|
while (par2 && par2->str() != ")") {
|
||||||
|
if (par2->varId() == container->declarationId())
|
||||||
|
break;
|
||||||
|
if (par2->str() == "(")
|
||||||
|
par2 = par2->link();
|
||||||
|
par2 = par2->next();
|
||||||
|
}
|
||||||
|
if (par2->varId() == container->declarationId())
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// Show error message, mismatching iterator is used.
|
// Show error message, mismatching iterator is used.
|
||||||
iteratorsError(tok2, container->name(), tok2->str());
|
iteratorsError(tok2, container->name(), tok2->str());
|
||||||
}
|
}
|
||||||
|
|
|
@ -201,6 +201,14 @@ private:
|
||||||
" l2.insert(it, 0);\n"
|
" l2.insert(it, 0);\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:6]: (error) Same iterator is used with different containers 'l1' and 'l2'.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:6]: (error) Same iterator is used with different containers 'l1' and 'l2'.\n", errout.str());
|
||||||
|
|
||||||
|
check("void foo() {\n" // #5803
|
||||||
|
" list<int> l1;\n"
|
||||||
|
" list<int> l2;\n"
|
||||||
|
" list<int>::iterator it = l1.begin();\n"
|
||||||
|
" l2.insert(it, l1.end());\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void iterator4() {
|
void iterator4() {
|
||||||
|
|
Loading…
Reference in New Issue