Fix issue 9742: FP iterators3 for address of reference to vector in struct (#2668)

This commit is contained in:
Paul Fultz II 2020-06-01 01:53:08 -05:00 committed by GitHub
parent 9772770226
commit 3109d16b42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -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());

View File

@ -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<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"