Fix issue 10090: ValueFlow: Wrong lifetime, pointer member is not allocated on stack (#3109)
This commit is contained in:
parent
cf8a5d9a22
commit
0ecac8e23b
|
@ -593,6 +593,8 @@ void CheckAutoVariables::checkVarLifetimeScope(const Token * start, const Token
|
|||
continue;
|
||||
if (!isLifetimeBorrowed(tok, mSettings))
|
||||
continue;
|
||||
if (tokvalue->exprId() == tok->exprId() && !(tok->variable() && tok->variable()->isArray()))
|
||||
continue;
|
||||
if ((tokvalue->variable() && !isEscapedReference(tokvalue->variable()) &&
|
||||
isInScope(tokvalue->variable()->nameToken(), scope)) ||
|
||||
isDeadTemporary(mTokenizer->isCPP(), tokvalue, tok, &mSettings->library)) {
|
||||
|
|
|
@ -2579,6 +2579,24 @@ private:
|
|||
" }\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// #10090
|
||||
check("struct a {\n"
|
||||
" int b{};\n"
|
||||
"};\n"
|
||||
"struct c {\n"
|
||||
" int* c{};\n"
|
||||
" a* d{};\n"
|
||||
"};\n"
|
||||
"a* f();\n"
|
||||
"c g() {\n"
|
||||
" c e;\n"
|
||||
" e.d = f();\n"
|
||||
" if (e.d)\n"
|
||||
" e.c = &e.d->b;\n"
|
||||
" return e;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void danglingLifetimeFunction() {
|
||||
|
|
Loading…
Reference in New Issue