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() {