Fix 11381: FP derefInvalidIteratorRedundantCheck when updating iterator using std::tie (#4659)
This commit is contained in:
parent
7506b4ab52
commit
f8132ea022
|
@ -2361,7 +2361,8 @@ bool isVariableChangedByFunctionCall(const Token *tok, int indirect, const Setti
|
||||||
if (indirect > 0 && requireInit && requireNonNull)
|
if (indirect > 0 && requireInit && requireNonNull)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (Token::simpleMatch(tok->tokAt(-2), "std :: tie"))
|
||||||
|
return true;
|
||||||
// if the library says 0 is invalid
|
// if the library says 0 is invalid
|
||||||
// => it is assumed that parameter is an in parameter (TODO: this is a bad heuristic)
|
// => it is assumed that parameter is an in parameter (TODO: this is a bad heuristic)
|
||||||
if (indirect == 0 && requireNonNull)
|
if (indirect == 0 && requireNonNull)
|
||||||
|
|
|
@ -4658,6 +4658,17 @@ private:
|
||||||
" return s.end();\n"
|
" return s.end();\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (style) Consider using std::find_if algorithm instead of a raw loop.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3]: (style) Consider using std::find_if algorithm instead of a raw loop.\n", errout.str());
|
||||||
|
|
||||||
|
// #11381
|
||||||
|
check("int f(std::map<int, int>& map) {\n"
|
||||||
|
" auto it = map.find(1);\n"
|
||||||
|
" if (it == map.end()) {\n"
|
||||||
|
" bool bInserted;\n"
|
||||||
|
" std::tie(it, bInserted) = map.emplace(1, 42);\n"
|
||||||
|
" }\n"
|
||||||
|
" return debug_valueflow(it)->second;\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void dereferenceInvalidIterator2() {
|
void dereferenceInvalidIterator2() {
|
||||||
|
|
Loading…
Reference in New Issue