Fix issue 9973: False positive: mismatching iterator container, reference (#2893)
This commit is contained in:
parent
bd5fc4b579
commit
ae6f611df0
|
@ -796,10 +796,16 @@ void CheckStl::mismatchingContainerIterator()
|
||||||
continue;
|
continue;
|
||||||
if (val.lifetimeKind != ValueFlow::Value::LifetimeKind::Iterator)
|
if (val.lifetimeKind != ValueFlow::Value::LifetimeKind::Iterator)
|
||||||
continue;
|
continue;
|
||||||
if (isSameExpression(true, false, tok, val.tokvalue, mSettings->library, false, false))
|
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;
|
continue;
|
||||||
mismatchingContainerIteratorError(tok, iterTok);
|
mismatchingContainerIteratorError(tok, iterTok);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1351,6 +1351,20 @@ private:
|
||||||
" return a;\n"
|
" return a;\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:2]: (error) Iterator 'b.begin()' from different container 'a' are used together.\n", errout.str());
|
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
|
// Dereferencing invalid pointer
|
||||||
|
|
Loading…
Reference in New Issue