From 3109d16b42de6be03773988582b7d6fef609e685 Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Mon, 1 Jun 2020 01:53:08 -0500 Subject: [PATCH] Fix issue 9742: FP iterators3 for address of reference to vector in struct (#2668) --- lib/valueflow.cpp | 2 +- test/teststl.cpp | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) 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"