From 3874c546cc895ea1fa05c206c5b3c09b95a07f32 Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Tue, 7 Dec 2021 00:43:25 -0600 Subject: [PATCH] Fix 10641: FP invalidLifetime with compiler-generated constructor (#3609) --- lib/valueflow.cpp | 2 -- test/testautovariables.cpp | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 235c09f3c..d7215b8bd 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -3631,8 +3631,6 @@ struct LifetimeStore { const Variable* var = lt.token->variable(); if (var && var->isArgument()) { value.lifetimeScope = ValueFlow::Value::LifetimeScope::Argument; - } else if (exprDependsOnThis(lt.token)) { - value.lifetimeScope = ValueFlow::Value::LifetimeScope::ThisPointer; } else { continue; } diff --git a/test/testautovariables.cpp b/test/testautovariables.cpp index 289b54ba5..09a9bb271 100644 --- a/test/testautovariables.cpp +++ b/test/testautovariables.cpp @@ -3398,6 +3398,23 @@ private: ASSERT_EQUALS( "[test.cpp:9] -> [test.cpp:9] -> [test.cpp:9] -> [test.cpp:4] -> [test.cpp:4] -> [test.cpp:8] -> [test.cpp:9]: (error) Returning object that points to local variable 'i' that will be invalid when returning.\n", errout.str()); + + check("struct S {\n" + " int i{};\n" + "};\n" + "struct T {\n" + " S getS() const { return S{ j }; }\n" + " int j{};\n" + "};\n" + "void f(S* p) {\n" + " S ret;\n" + " {\n" + " T t;\n" + " ret = t.getS();\n" + " }\n" + " *p = ret;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void invalidLifetime() {