Fix 10163: false positive: lifetime for r is not same as for seq 'for (auto& r: seq)' (#3442)

This commit is contained in:
Paul Fultz II 2021-09-04 12:53:14 -05:00 committed by GitHub
parent 82b725e540
commit 28bc717cbe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View File

@ -2935,8 +2935,10 @@ static std::vector<LifetimeToken> getLifetimeTokens(const Token* tok,
if (vartok == tok)
return {{tok, true, std::move(errorPath)}};
const Token* contok = var->nameToken()->astParent()->astOperand2();
if (contok)
if (astIsContainer(contok))
return getLifetimeTokens(contok, escape, std::move(errorPath), pred, depth - 1);
else
return std::vector<LifetimeToken>{};
} else {
return std::vector<LifetimeToken> {};
}

View File

@ -2432,6 +2432,15 @@ private:
" return i;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
check("int* get(std::vector<int>& container) {\n"
" Sequence seq(container);\n"
" for (auto& r : seq) {\n"
" return &r;\n"
" }\n"
" return &*seq.begin();\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void danglingLifetime() {