diff --git a/lib/checkautovariables.cpp b/lib/checkautovariables.cpp index 675781635..93c0f626d 100644 --- a/lib/checkautovariables.cpp +++ b/lib/checkautovariables.cpp @@ -643,7 +643,8 @@ void CheckAutoVariables::checkVarLifetimeScope(const Token * start, const Token } else if (isDeadScope(val.tokvalue, tok->scope())) { errorInvalidLifetime(tok, &val); break; - } else if (tok->variable() && !tok->variable()->isLocal() && !tok->variable()->isArgument() && + } else if (tok->variable() && tok->variable()->declarationId() == tok->varId() && + !tok->variable()->isLocal() && !tok->variable()->isArgument() && isInScope(val.tokvalue, tok->scope())) { errorDanglngLifetime(tok, &val); break; diff --git a/test/testautovariables.cpp b/test/testautovariables.cpp index e717596aa..3629bdcaa 100644 --- a/test/testautovariables.cpp +++ b/test/testautovariables.cpp @@ -1510,6 +1510,14 @@ private: "}\n"); ASSERT_EQUALS("", errout.str()); + check("void f() {\n" + " struct b {\n" + " uint32_t f[6];\n" + " } d;\n" + " uint32_t *a = d.f;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + // Make sure we dont hang check("struct A;\n" "void f() {\n"