Fix 11442: new "Reference to temporary returned." FPs (#4657)

This commit is contained in:
Paul Fultz II 2022-12-19 15:28:59 -06:00 committed by GitHub
parent 2cd8bb94e4
commit da32c5aecd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 0 deletions

View File

@ -407,6 +407,8 @@ bool isTemporary(bool cpp, const Token* tok, const Library* library, bool unknow
const Token* branchTok = tok->astOperand2();
if (!branchTok->astOperand1()->valueType())
return false;
if (!branchTok->astOperand2()->valueType())
return false;
return !branchTok->astOperand1()->valueType()->isTypeEqual(branchTok->astOperand2()->valueType());
}
if (Token::simpleMatch(tok, "(") && tok->astOperand1() &&

View File

@ -3733,6 +3733,14 @@ private:
"}\n",
true);
ASSERT_EQUALS("", errout.str());
// #11442
check("const std::string& f(const P< std::string >& value) {\n"
" static const std::string empty;\n"
" return value.get() == nullptr ? empty : *value;\n"
"}\n",
true);
ASSERT_EQUALS("", errout.str());
}
void danglingLifetimeBorrowedMembers()