Fix issue 9461: False positive: Reference to temporary returned using trailing return type (#2345)

This commit is contained in:
Paul Fultz II 2019-11-10 02:44:04 -06:00 committed by Daniel Marjamäki
parent 2d326c011d
commit c1da6c7dd2
2 changed files with 11 additions and 1 deletions

View File

@ -872,7 +872,7 @@ public:
const Token* returnDefEnd() const {
if (this->hasTrailingReturnType()) {
return Token::findsimplematch(retDef, "{");
return Token::findmatch(retDef, "{|;");
} else {
return tokenDef;
}

View File

@ -110,6 +110,8 @@ private:
TEST_CASE(returnReference14);
TEST_CASE(returnReference15); // #9432
TEST_CASE(returnReference16); // #9433
TEST_CASE(returnReference16); // #9433
TEST_CASE(returnReference17); // #9461
TEST_CASE(returnReferenceFunction);
TEST_CASE(returnReferenceContainer);
TEST_CASE(returnReferenceLiteral);
@ -1280,6 +1282,14 @@ private:
TODO_ASSERT_EQUALS("error", "", errout.str());
}
void returnReference17() {
check("auto g() -> int&;\n"
"int& f() {\n"
" return g();\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void returnReferenceFunction() {
check("int& f(int& a) {\n"
" return a;\n"