From 71809044bdf77e50fa25754088cf42e3fb1e1a78 Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Tue, 5 Oct 2021 01:23:47 -0500 Subject: [PATCH] Fix 10522: FP: derefInvalidIterator when using emplace with 1 argument (#3482) --- lib/astutils.cpp | 3 +++ test/teststl.cpp | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/lib/astutils.cpp b/lib/astutils.cpp index a8eb38609..52e4839d5 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -460,6 +460,9 @@ Token* astParentSkipParens(Token* tok) return parent; if (parent->link() != nextAfterAstRightmostLeaf(tok)) return parent; + if (Token::Match(parent->previous(), "%name% (") || + (Token::simpleMatch(parent->previous(), "> (") && parent->previous()->link())) + return parent; return astParentSkipParens(parent); } diff --git a/test/teststl.cpp b/test/teststl.cpp index 261a10c78..d2eca7659 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -4098,6 +4098,12 @@ private: " return *it;\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + check("int f(std::vector &vect) {\n" + " const int &v = *vect.emplace(vect.end());\n" + " return v;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void dereferenceInvalidIterator2() {