Skip to content

Commit 14f3620

Browse files
Fix #13373 FP returnReference for reference member (#7066)
1 parent 152dd9d commit 14f3620

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

lib/valueflow.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1585,7 +1585,8 @@ static std::vector<ValueFlow::LifetimeToken> getLifetimeTokens(const Token* tok,
15851585
if (vartok->str() == "[" || vartok->isUnaryOp("*"))
15861586
vartok = vartok->astOperand1();
15871587
else if (vartok->str() == ".") {
1588-
if (vartok->originalName().empty() || !Token::simpleMatch(vartok->astOperand1(), "."))
1588+
if (!Token::simpleMatch(vartok->astOperand1(), ".") &&
1589+
!(vartok->astOperand2() && vartok->astOperand2()->valueType() && vartok->astOperand2()->valueType()->reference != Reference::None))
15891590
vartok = vartok->astOperand1();
15901591
else
15911592
break;

test/testautovariables.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ class TestAutoVariables : public TestFixture {
119119
TEST_CASE(returnReference25); // #10983
120120
TEST_CASE(returnReference26);
121121
TEST_CASE(returnReference27);
122+
TEST_CASE(returnReference28);
122123
TEST_CASE(returnReferenceFunction);
123124
TEST_CASE(returnReferenceContainer);
124125
TEST_CASE(returnReferenceLiteral);
@@ -1672,6 +1673,17 @@ class TestAutoVariables : public TestFixture {
16721673
ASSERT_EQUALS("", errout_str());
16731674
}
16741675

1676+
void returnReference28()
1677+
{
1678+
check("struct S {\n" // #13373
1679+
" int& r;\n"
1680+
"};\n"
1681+
"int& f(S s) {\n"
1682+
" return s.r;\n"
1683+
"}\n");
1684+
ASSERT_EQUALS("", errout_str());
1685+
}
1686+
16751687
void returnReferenceFunction() {
16761688
check("int& f(int& a) {\n"
16771689
" return a;\n"

0 commit comments

Comments
 (0)