Fix issue 9900: False positive: Returning lambda that captures local variable 'x' that will be invalid when returning. (#2809)
This commit is contained in:
parent
782684a7cc
commit
e5d0ffdbe7
|
@ -3845,6 +3845,8 @@ static void valueFlowLifetime(TokenList *tokenlist, SymbolDatabase*, ErrorLogger
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const Token * tok2 = lam.bodyTok; tok2 != lam.bodyTok->link(); tok2 = tok2->next()) {
|
for (const Token * tok2 = lam.bodyTok; tok2 != lam.bodyTok->link(); tok2 = tok2->next()) {
|
||||||
|
if (!tok2->variable())
|
||||||
|
continue;
|
||||||
captureVariable(tok2, lam.implicitCapture, isImplicitCapturingVariable);
|
captureVariable(tok2, lam.implicitCapture, isImplicitCapturingVariable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1914,6 +1914,15 @@ private:
|
||||||
" return [=, &i] { return j; };\n"
|
" return [=, &i] { return j; };\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
check("void f(int*);\n"
|
||||||
|
"auto g(int y) {\n"
|
||||||
|
" int x = y;\n"
|
||||||
|
" return [=] {\n"
|
||||||
|
" g(&x);\n"
|
||||||
|
" };\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void danglingLifetimeContainer() {
|
void danglingLifetimeContainer() {
|
||||||
|
|
Loading…
Reference in New Issue