Partial fix for #10983 False positive: returnTempReference with trailing return type (#4055)

This commit is contained in:
chrchr-github 2022-04-27 20:11:32 +02:00 committed by GitHub
parent 034140e7e1
commit 7cedf3e0e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 0 deletions

View File

@ -6340,6 +6340,7 @@ static const Token * parsedecl(const Token *type, ValueType * const valuetype, V
valuetype->type = vt2->type;
valuetype->constness += vt2->constness;
valuetype->pointer += vt2->pointer;
valuetype->reference = vt2->reference;
type = type->linkAt(1)->next();
continue;
} else if (type->isSigned())

View File

@ -124,6 +124,7 @@ private:
TEST_CASE(returnReference22);
TEST_CASE(returnReference23);
TEST_CASE(returnReference24); // #10098
TEST_CASE(returnReference25); // #10983
TEST_CASE(returnReferenceFunction);
TEST_CASE(returnReferenceContainer);
TEST_CASE(returnReferenceLiteral);
@ -1552,6 +1553,18 @@ private:
ASSERT_EQUALS("[test.cpp:5]: (error) Reference to temporary returned.\n", errout.str());
}
void returnReference25()
{
check("int& f();\n" // #10983
" auto g() -> decltype(f()) {\n"
" return f();\n"
"}\n"
"int& h() {\n"
" return g();\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void returnReferenceFunction() {
check("int& f(int& a) {\n"
" return a;\n"