From 8a1c0dd0173f1397f8770e814891fba21c482a4c Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Sun, 2 Jun 2019 03:21:26 -0500 Subject: [PATCH] Fix FP with non-local variable referencing a non-local variable (#1864) --- lib/checkautovariables.cpp | 2 +- test/testautovariables.cpp | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/checkautovariables.cpp b/lib/checkautovariables.cpp index 5e9f7d0bf..3f7be8672 100644 --- a/lib/checkautovariables.cpp +++ b/lib/checkautovariables.cpp @@ -630,7 +630,7 @@ void CheckAutoVariables::checkVarLifetimeScope(const Token * start, const Token break; } else if (tok->variable() && tok->variable()->declarationId() == tok->varId() && !tok->variable()->isLocal() && !tok->variable()->isArgument() && - isInScope(val.tokvalue, tok->scope())) { + isInScope(val.tokvalue->variable()->nameToken(), tok->scope())) { errorDanglngLifetime(tok, &val); break; } diff --git a/test/testautovariables.cpp b/test/testautovariables.cpp index 62c84c432..1061636d1 100644 --- a/test/testautovariables.cpp +++ b/test/testautovariables.cpp @@ -1721,6 +1721,15 @@ private: " std::map< S, B > m2;\n" "};\n"); ASSERT_EQUALS("", errout.str()); + + check("struct A {\n" + " std::vector v;\n" + " int x;\n" + " void f() {\n" + " v.push_back(&x);\n" + " }\n" + "};\n"); + ASSERT_EQUALS("", errout.str()); } void danglingLifetime() {