diff --git a/lib/checkother.cpp b/lib/checkother.cpp index f52b7cf8ba0..7c7cf189323 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -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; diff --git a/test/testother.cpp b/test/testother.cpp index e363642684d..44d4bb3cd4b 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -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& a) { return reinterpret_cast(a.data()); }\n"); // #14074 + ASSERT_EQUALS("", errout_str()); } void constParameterCallback() {