diff --git a/lib/checkautovariables.cpp b/lib/checkautovariables.cpp index 3d8f90037..cb369285b 100644 --- a/lib/checkautovariables.cpp +++ b/lib/checkautovariables.cpp @@ -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)) { diff --git a/test/testautovariables.cpp b/test/testautovariables.cpp index bfc9439ff..eec7ea87d 100644 --- a/test/testautovariables.cpp +++ b/test/testautovariables.cpp @@ -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() {