Skip to content

Commit 3109d16

Browse files
authored
Fix issue 9742: FP iterators3 for address of reference to vector in struct (#2668)
1 parent 9772770 commit 3109d16

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

lib/valueflow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3596,7 +3596,7 @@ static void valueFlowLifetime(TokenList *tokenlist, SymbolDatabase*, ErrorLogger
35963596
value.lifetimeScope = ValueFlow::Value::LifetimeScope::Local;
35973597
value.tokvalue = lt.token;
35983598
value.errorPath = std::move(errorPath);
3599-
if (astIsPointer(lt.token) || !Token::Match(lt.token->astParent(), ".|["))
3599+
if (lt.addressOf || astIsPointer(lt.token) || !Token::Match(lt.token->astParent(), ".|["))
36003600
value.lifetimeKind = ValueFlow::Value::LifetimeKind::Address;
36013601
value.setInconclusive(lt.inconclusive);
36023602
setTokenValue(tok, value, tokenlist->getSettings());

test/teststl.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class TestStl : public TestFixture {
6767
TEST_CASE(iterator22);
6868
TEST_CASE(iterator23);
6969
TEST_CASE(iterator24);
70+
TEST_CASE(iterator25); // #9742
7071
TEST_CASE(iteratorExpression);
7172
TEST_CASE(iteratorSameExpression);
7273

@@ -1104,6 +1105,19 @@ class TestStl : public TestFixture {
11041105
ASSERT_EQUALS("", errout.str());
11051106
}
11061107

1108+
void iterator25() {
1109+
// #9742
1110+
check("struct S {\n"
1111+
" std::vector<int>& v;\n"
1112+
"};\n"
1113+
"struct T {\n"
1114+
" bool operator()(const S& lhs, const S& rhs) const {\n"
1115+
" return &lhs.v != &rhs.v;\n"
1116+
" }\n"
1117+
"};\n");
1118+
ASSERT_EQUALS("", errout.str());
1119+
}
1120+
11071121
void iteratorExpression() {
11081122
check("std::vector<int>& f();\n"
11091123
"std::vector<int>& g();\n"

0 commit comments

Comments
 (0)