From 8ddc5764f8ba74898eff4b2a25d16041b5343954 Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Tue, 24 Aug 2021 21:06:03 -0500 Subject: [PATCH] Fix 10425: False positive: returnDanglingLifetime when taking address of captured variable (#3415) --- lib/valueflow.cpp | 1 + test/testautovariables.cpp | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index cc093d5b2..1d663c494 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -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); } }; diff --git a/test/testautovariables.cpp b/test/testautovariables.cpp index e0552558c..83ee2487d 100644 --- a/test/testautovariables.cpp +++ b/test/testautovariables.cpp @@ -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() {