diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 3c756829d..e20c95eb1 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -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()); diff --git a/test/teststl.cpp b/test/teststl.cpp index 317696b0c..4126296af 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -67,6 +67,7 @@ private: TEST_CASE(iterator22); TEST_CASE(iterator23); TEST_CASE(iterator24); + TEST_CASE(iterator25); // #9742 TEST_CASE(iteratorExpression); TEST_CASE(iteratorSameExpression); @@ -1104,6 +1105,19 @@ private: ASSERT_EQUALS("", errout.str()); } + void iterator25() { + // #9742 + check("struct S {\n" + " std::vector& 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& f();\n" "std::vector& g();\n"