Fix 10425: False positive: returnDanglingLifetime when taking address of captured variable (#3415)

This commit is contained in:
Paul Fultz II 2021-08-24 21:06:03 -05:00 committed by GitHub
parent 5868d01e80
commit 8ddc5764f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 0 deletions

View File

@ -3839,6 +3839,7 @@ static void valueFlowLifetime(TokenList *tokenlist, SymbolDatabase*, ErrorLogger
tok2, "Lambda captures variable by value here.", ValueFlow::Value::LifetimeKind::Lambda};
ls.forward = false;
update |= ls.byVal(tok, tokenlist, errorLogger, settings, pred);
pred(tok2);
}
};

View File

@ -2037,6 +2037,18 @@ private:
" };\n"
"}\n");
ASSERT_EQUALS("", errout.str());
check("struct A {\n"
" int x;\n"
"};\n"
"auto f() {\n"
" A a;\n"
" return [=] {\n"
" const A* ap = &a;\n"
" ap->x;\n"
" };\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void danglingLifetimeContainer() {