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
2 changes: 1 addition & 1 deletion lib/valueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3596,7 +3596,7 @@ static void valueFlowLifetime(TokenList *tokenlist, SymbolDatabase*, ErrorLogger
value.lifetimeScope = ValueFlow::Value::LifetimeScope::Local;
value.tokvalue = lt.token;
value.errorPath = std::move(errorPath);
if (astIsPointer(lt.token) || !Token::Match(lt.token->astParent(), ".|["))
if (lt.addressOf || astIsPointer(lt.token) || !Token::Match(lt.token->astParent(), ".|["))
value.lifetimeKind = ValueFlow::Value::LifetimeKind::Address;
value.setInconclusive(lt.inconclusive);
setTokenValue(tok, value, tokenlist->getSettings());
Expand Down
14 changes: 14 additions & 0 deletions test/teststl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class TestStl : public TestFixture {
TEST_CASE(iterator22);
TEST_CASE(iterator23);
TEST_CASE(iterator24);
TEST_CASE(iterator25); // #9742
TEST_CASE(iteratorExpression);
TEST_CASE(iteratorSameExpression);

Expand Down Expand Up @@ -1104,6 +1105,19 @@ class TestStl : public TestFixture {
ASSERT_EQUALS("", errout.str());
}

void iterator25() {
// #9742
check("struct S {\n"
" std::vector<int>& v;\n"
"};\n"
"struct T {\n"
" bool operator()(const S& lhs, const S& rhs) const {\n"
" return &lhs.v != &rhs.v;\n"
" }\n"
"};\n");
ASSERT_EQUALS("", errout.str());
}

void iteratorExpression() {
check("std::vector<int>& f();\n"
"std::vector<int>& g();\n"
Expand Down