diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index d522fb8e619..6078186368f 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -1585,7 +1585,8 @@ static std::vector getLifetimeTokens(const Token* tok, if (vartok->str() == "[" || vartok->isUnaryOp("*")) vartok = vartok->astOperand1(); else if (vartok->str() == ".") { - if (vartok->originalName().empty() || !Token::simpleMatch(vartok->astOperand1(), ".")) + if (!Token::simpleMatch(vartok->astOperand1(), ".") && + !(vartok->astOperand2() && vartok->astOperand2()->valueType() && vartok->astOperand2()->valueType()->reference != Reference::None)) vartok = vartok->astOperand1(); else break; diff --git a/test/testautovariables.cpp b/test/testautovariables.cpp index d9d0e8cb190..3d4803cbbcb 100644 --- a/test/testautovariables.cpp +++ b/test/testautovariables.cpp @@ -119,6 +119,7 @@ class TestAutoVariables : public TestFixture { TEST_CASE(returnReference25); // #10983 TEST_CASE(returnReference26); TEST_CASE(returnReference27); + TEST_CASE(returnReference28); TEST_CASE(returnReferenceFunction); TEST_CASE(returnReferenceContainer); TEST_CASE(returnReferenceLiteral); @@ -1672,6 +1673,17 @@ class TestAutoVariables : public TestFixture { ASSERT_EQUALS("", errout_str()); } + void returnReference28() + { + check("struct S {\n" // #13373 + " int& r;\n" + "};\n" + "int& f(S s) {\n" + " return s.r;\n" + "}\n"); + ASSERT_EQUALS("", errout_str()); + } + void returnReferenceFunction() { check("int& f(int& a) {\n" " return a;\n"