diff --git a/lib/checkautovariables.cpp b/lib/checkautovariables.cpp index be794c6f4..9422261e1 100644 --- a/lib/checkautovariables.cpp +++ b/lib/checkautovariables.cpp @@ -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; diff --git a/test/testautovariables.cpp b/test/testautovariables.cpp index 48c19555c..e2c3c2193 100644 --- a/test/testautovariables.cpp +++ b/test/testautovariables.cpp @@ -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() {