Fix 10163: false positive: lifetime for r is not same as for seq 'for (auto& r: seq)' (#3442)
This commit is contained in:
parent
82b725e540
commit
28bc717cbe
|
@ -2935,8 +2935,10 @@ static std::vector<LifetimeToken> getLifetimeTokens(const Token* tok,
|
||||||
if (vartok == tok)
|
if (vartok == tok)
|
||||||
return {{tok, true, std::move(errorPath)}};
|
return {{tok, true, std::move(errorPath)}};
|
||||||
const Token* contok = var->nameToken()->astParent()->astOperand2();
|
const Token* contok = var->nameToken()->astParent()->astOperand2();
|
||||||
if (contok)
|
if (astIsContainer(contok))
|
||||||
return getLifetimeTokens(contok, escape, std::move(errorPath), pred, depth - 1);
|
return getLifetimeTokens(contok, escape, std::move(errorPath), pred, depth - 1);
|
||||||
|
else
|
||||||
|
return std::vector<LifetimeToken>{};
|
||||||
} else {
|
} else {
|
||||||
return std::vector<LifetimeToken> {};
|
return std::vector<LifetimeToken> {};
|
||||||
}
|
}
|
||||||
|
|
|
@ -2432,6 +2432,15 @@ private:
|
||||||
" return i;\n"
|
" return i;\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("", errout.str());
|
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() {
|
void danglingLifetime() {
|
||||||
|
|
Loading…
Reference in New Issue