Skip to content

Commit 4ad9b8a

Browse files
Fix #14074 FP constParameterReference reported for std::array object when non-const pointer to internal data is returned (danmar#7890)
Co-authored-by: chrchr-github <[email protected]>
1 parent a8b7e2b commit 4ad9b8a

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

lib/checkother.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1728,6 +1728,9 @@ void CheckOther::checkConstVariable()
17281728
retTok = retTok->astOperand2();
17291729
if (Token::simpleMatch(retTok, "&"))
17301730
retTok = retTok->astOperand1();
1731+
ValueFlow::Value ltVal = ValueFlow::getLifetimeObjValue(retTok);
1732+
if (ltVal.isLifetimeValue() && ltVal.tokvalue->varId() == var->declarationId())
1733+
return true;
17311734
return ValueFlow::hasLifetimeToken(getParentLifetime(retTok), var->nameToken(), *mSettings);
17321735
}))
17331736
continue;

test/testother.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3964,6 +3964,9 @@ class TestOther : public TestFixture {
39643964

39653965
check("void push(V& v) { v.push_back({ .x = 1 }); }"); // #14010
39663966
ASSERT_EQUALS("", errout_str());
3967+
3968+
check("size_t* f(std::array<uint8_t, 128>& a) { return reinterpret_cast<size_t*>(a.data()); }\n"); // #14074
3969+
ASSERT_EQUALS("", errout_str());
39673970
}
39683971

39693972
void constParameterCallback() {

0 commit comments

Comments
 (0)