Fix #11362 FP returnDanglingLifetime for pointer to struct member in static array (#4563)

* Fix  #11362 FP returnDanglingLifetime for pointer to struct member in static array

* Undo
This commit is contained in:
chrchr-github 2022-10-22 00:27:30 +02:00 committed by GitHub
parent 515369739c
commit e046232535
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 1 deletions

View File

@ -410,7 +410,7 @@ static bool isInScope(const Token * tok, const Scope * scope)
const Variable * var = tok->variable();
if (var && (var->isGlobal() || var->isStatic() || var->isExtern()))
return false;
if (tok->scope() && tok->scope()->isNestedIn(scope))
if (tok->scope() && !tok->scope()->isClassOrStructOrUnion() && tok->scope()->isNestedIn(scope))
return true;
if (!var)
return false;

View File

@ -3050,6 +3050,13 @@ private:
" return std::tie(xs[i]...);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
// #11362
check("int* f() {\n"
" static struct { int x; } a[] = { { 1 } };\n"
" return &a[0].x;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void danglingLifetimeFunction() {