Fix issue 9530: False positive: Reference to temporary returned when using initializer lists (#2796)
This commit is contained in:
parent
11c99d7387
commit
782684a7cc
|
@ -273,6 +273,9 @@ bool isTemporary(bool cpp, const Token* tok, const Library* library, bool unknow
|
|||
// Currying a function is unknown in cppcheck
|
||||
if (Token::simpleMatch(tok, "(") && Token::simpleMatch(tok->astOperand1(), "("))
|
||||
return unknown;
|
||||
if (Token::simpleMatch(tok, "{") && Token::simpleMatch(tok->astParent(), "return") && tok->astOperand1() &&
|
||||
!tok->astOperand2())
|
||||
return isTemporary(cpp, tok->astOperand1(), library);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -115,6 +115,7 @@ private:
|
|||
TEST_CASE(returnReference18); // #9482
|
||||
TEST_CASE(returnReference19); // #9597
|
||||
TEST_CASE(returnReference20); // #9536
|
||||
TEST_CASE(returnReference21); // #9530
|
||||
TEST_CASE(returnReferenceFunction);
|
||||
TEST_CASE(returnReferenceContainer);
|
||||
TEST_CASE(returnReferenceLiteral);
|
||||
|
@ -1352,6 +1353,14 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
// #9530
|
||||
void returnReference21() {
|
||||
check("int& f(int& x) {\n"
|
||||
" return {x};\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void returnReferenceFunction() {
|
||||
check("int& f(int& a) {\n"
|
||||
" return a;\n"
|
||||
|
|
Loading…
Reference in New Issue