Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/checkother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1727,6 +1727,9 @@ void CheckOther::checkConstVariable()
retTok = retTok->astOperand2();
if (Token::simpleMatch(retTok, "&"))
retTok = retTok->astOperand1();
ValueFlow::Value ltVal = ValueFlow::getLifetimeObjValue(retTok);
if (ltVal.isLifetimeValue() && ltVal.tokvalue->varId() == var->declarationId())
return true;
return ValueFlow::hasLifetimeToken(getParentLifetime(retTok), var->nameToken(), *mSettings);
}))
continue;
Expand Down
3 changes: 3 additions & 0 deletions test/testother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3960,6 +3960,9 @@ class TestOther : public TestFixture {

check("void push(V& v) { v.push_back({ .x = 1 }); }"); // #14010
ASSERT_EQUALS("", errout_str());

check("size_t* f(std::array<uint8_t, 128>& a) { return reinterpret_cast<size_t*>(a.data()); }\n"); // #14074
ASSERT_EQUALS("", errout_str());
}

void constParameterCallback() {
Expand Down