Fix 10522: FP: derefInvalidIterator when using emplace with 1 argument (#3482)

This commit is contained in:
Paul Fultz II 2021-10-05 01:23:47 -05:00 committed by GitHub
parent c7e13d0e0b
commit 71809044bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 0 deletions

View File

@ -460,6 +460,9 @@ Token* astParentSkipParens(Token* tok)
return parent; return parent;
if (parent->link() != nextAfterAstRightmostLeaf(tok)) if (parent->link() != nextAfterAstRightmostLeaf(tok))
return parent; return parent;
if (Token::Match(parent->previous(), "%name% (") ||
(Token::simpleMatch(parent->previous(), "> (") && parent->previous()->link()))
return parent;
return astParentSkipParens(parent); return astParentSkipParens(parent);
} }

View File

@ -4098,6 +4098,12 @@ private:
" return *it;\n" " return *it;\n"
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
check("int f(std::vector<int> &vect) {\n"
" const int &v = *vect.emplace(vect.end());\n"
" return v;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
} }
void dereferenceInvalidIterator2() { void dereferenceInvalidIterator2() {