diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 83366a8ba..ef0b6923b 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -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()) diff --git a/test/testautovariables.cpp b/test/testautovariables.cpp index ea82a1fcb..52f12bfab 100644 --- a/test/testautovariables.cpp +++ b/test/testautovariables.cpp @@ -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"