Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/checkautovariables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions test/testautovariables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3050,6 +3050,13 @@ class TestAutoVariables : public TestFixture {
" 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() {
Expand Down