Fix 10641: FP invalidLifetime with compiler-generated constructor (#3609)
This commit is contained in:
parent
0be6e27231
commit
3874c546cc
|
@ -3631,8 +3631,6 @@ struct LifetimeStore {
|
||||||
const Variable* var = lt.token->variable();
|
const Variable* var = lt.token->variable();
|
||||||
if (var && var->isArgument()) {
|
if (var && var->isArgument()) {
|
||||||
value.lifetimeScope = ValueFlow::Value::LifetimeScope::Argument;
|
value.lifetimeScope = ValueFlow::Value::LifetimeScope::Argument;
|
||||||
} else if (exprDependsOnThis(lt.token)) {
|
|
||||||
value.lifetimeScope = ValueFlow::Value::LifetimeScope::ThisPointer;
|
|
||||||
} else {
|
} else {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3398,6 +3398,23 @@ private:
|
||||||
ASSERT_EQUALS(
|
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",
|
"[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());
|
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() {
|
void invalidLifetime() {
|
||||||
|
|
Loading…
Reference in New Issue