Skip to content

Commit 53bf059

Browse files
committed
Fix
1 parent 4ff7d31 commit 53bf059

3 files changed

Lines changed: 5 additions & 2 deletions

File tree

lib/checkother.cpp

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

lib/checkstl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1091,7 +1091,7 @@ static const ValueFlow::Value* getInnerLifetime(const Token* tok,
10911091
if (!tok)
10921092
return nullptr;
10931093
for (const ValueFlow::Value& val : tok->values()) {
1094-
if (!val.isLocalLifetimeValue() && !val.isArgumentLifetimeValue())
1094+
if (!val.isLocalLifetimeValue())
10951095
continue;
10961096
if (contains({ValueFlow::Value::LifetimeKind::Address,
10971097
ValueFlow::Value::LifetimeKind::SubObject,

lib/valueflow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1796,7 +1796,7 @@ static std::vector<ValueFlow::LifetimeToken> getLifetimeTokens(const Token* tok,
17961796
if (Token::Match(tok->tokAt(-2), ". %name% (") && tok->tokAt(-2)->originalName() != "->" && astIsContainer(tok->tokAt(-2)->astOperand1())) {
17971797
const Library::Container* library = getLibraryContainer(tok->tokAt(-2)->astOperand1());
17981798
const Library::Container::Yield y = library->getYield(tok->strAt(-1));
1799-
if (contains({Library::Container::Yield::AT_INDEX, Library::Container::Yield::ITEM, Library::Container::Yield::BUFFER, Library::Container::Yield::BUFFER_NT}, y)) {
1799+
if (y == Library::Container::Yield::AT_INDEX || y == Library::Container::Yield::ITEM) {
18001800
errorPath.emplace_back(tok->previous(), "Accessing container.");
18011801
return ValueFlow::LifetimeToken::setAddressOf(
18021802
getLifetimeTokens(tok->tokAt(-2)->astOperand1(), escape, std::move(errorPath), pred, settings, depth - 1),

0 commit comments

Comments
 (0)