Fix issue 9409: FP returnTempReference (#2266)

* Fix issue 9409: FP returnTempReference

* Format
This commit is contained in:
Paul Fultz II 2019-10-13 12:12:46 -05:00 committed by amai2012
parent 5a08ac361a
commit bf5c90a2be
2 changed files with 17 additions and 1 deletions

View File

@ -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)))

View File

@ -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"