Fix issue 9597: False positive: Reference to temporary returned if explicitly casted to base class (#2531)
This commit is contained in:
parent
583d5e5958
commit
e55ddacd18
|
@ -504,6 +504,8 @@ static bool iscast(const Token *tok)
|
|||
tok2 = tok2->link()->next();
|
||||
|
||||
if (tok2->str() == ")") {
|
||||
if (Token::Match(tok2->previous(), "&|&& )"))
|
||||
return true;
|
||||
if (Token::simpleMatch(tok2, ") (") && Token::simpleMatch(tok2->linkAt(1), ") ."))
|
||||
return true;
|
||||
return type || tok2->strAt(-1) == "*" || Token::simpleMatch(tok2, ") ~") ||
|
||||
|
|
|
@ -113,6 +113,7 @@ private:
|
|||
TEST_CASE(returnReference16); // #9433
|
||||
TEST_CASE(returnReference17); // #9461
|
||||
TEST_CASE(returnReference18); // #9482
|
||||
TEST_CASE(returnReference19); // #9597
|
||||
TEST_CASE(returnReferenceFunction);
|
||||
TEST_CASE(returnReferenceContainer);
|
||||
TEST_CASE(returnReferenceLiteral);
|
||||
|
@ -1307,6 +1308,14 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
// #9597
|
||||
void returnReference19() {
|
||||
check("struct C : B {\n"
|
||||
" const B &f() const { return (const B &)*this; }\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void returnReferenceFunction() {
|
||||
check("int& f(int& a) {\n"
|
||||
" return a;\n"
|
||||
|
|
Loading…
Reference in New Issue