Fix issue 9973: False positive: mismatching iterator container, reference (#2893)
This commit is contained in:
parent
bd5fc4b579
commit
ae6f611df0
|
@ -796,9 +796,15 @@ void CheckStl::mismatchingContainerIterator()
|
|||
continue;
|
||||
if (val.lifetimeKind != ValueFlow::Value::LifetimeKind::Iterator)
|
||||
continue;
|
||||
if (isSameExpression(true, false, tok, val.tokvalue, mSettings->library, false, false))
|
||||
continue;
|
||||
mismatchingContainerIteratorError(tok, iterTok);
|
||||
for (const LifetimeToken& lt:getLifetimeTokens(tok)) {
|
||||
if (lt.inconclusive)
|
||||
continue;
|
||||
const Token* contTok = lt.token;
|
||||
if (isSameExpression(true, false, contTok, val.tokvalue, mSettings->library, false, false))
|
||||
continue;
|
||||
mismatchingContainerIteratorError(tok, iterTok);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1351,6 +1351,20 @@ private:
|
|||
" return a;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:2]: (error) Iterator 'b.begin()' from different container 'a' are used together.\n", errout.str());
|
||||
|
||||
// #9973
|
||||
check("void f() {\n"
|
||||
" std::list<int> l1;\n"
|
||||
" std::list<int> l2;\n"
|
||||
" std::list<int>& l = l2;\n"
|
||||
" for (auto it = l.begin(); it != l.end(); ++it) {\n"
|
||||
" if (*it == 1) {\n"
|
||||
" l.erase(it);\n"
|
||||
" break;\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
// Dereferencing invalid pointer
|
||||
|
|
Loading…
Reference in New Issue