From bf5c90a2beee05a48363819d2fe1c4fd229f73d1 Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Sun, 13 Oct 2019 12:12:46 -0500 Subject: [PATCH] Fix issue 9409: FP returnTempReference (#2266) * Fix issue 9409: FP returnTempReference * Format --- lib/astutils.cpp | 3 ++- test/testautovariables.cpp | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/astutils.cpp b/lib/astutils.cpp index 126674904..47405f987 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -225,7 +225,8 @@ bool isTemporary(bool cpp, const Token* tok) if (!tok) return false; if (Token::simpleMatch(tok, ".")) - return isTemporary(cpp, tok->astOperand1()) || isTemporary(cpp, tok->astOperand2()); + return (tok->originalName() != "->" && isTemporary(cpp, tok->astOperand1())) || + isTemporary(cpp, tok->astOperand2()); if (Token::Match(tok, ",|::")) return isTemporary(cpp, tok->astOperand2()); if (tok->isCast() || (cpp && isCPPCast(tok))) diff --git a/test/testautovariables.cpp b/test/testautovariables.cpp index 89393f098..30974e6ab 100644 --- a/test/testautovariables.cpp +++ b/test/testautovariables.cpp @@ -106,6 +106,7 @@ private: TEST_CASE(returnReference11); TEST_CASE(returnReference12); TEST_CASE(returnReference13); + TEST_CASE(returnReference14); TEST_CASE(returnReferenceFunction); TEST_CASE(returnReferenceContainer); TEST_CASE(returnReferenceLiteral); @@ -1230,6 +1231,20 @@ private: ASSERT_EQUALS("", errout.str()); } + void returnReference14() + { + check("struct C { void* m; };\n" + "struct A { void* &f(); };\n" + "C* g() {\n" + " static C c;\n" + " return &c;\n" + "}\n" + "void* &A::f() {\n" + " return g()->m;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + } + void returnReferenceFunction() { check("int& f(int& a) {\n" " return a;\n"