diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index de1dfc2c9..1b92386aa 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -4945,6 +4945,8 @@ static void valueFlowForwardAssign(Token* const tok, // Skip RHS const Token * nextExpression = tok->astParent() ? nextAfterAstRightmostLeaf(tok->astParent()) : tok->next(); + if (!nextExpression) + return; for (ValueFlow::Value& value : values) { if (value.isSymbolicValue()) diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index ee326ff61..bee4a3d45 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -6259,6 +6259,13 @@ private: " }\n" "};\n"; valueOfTok(code, "f.c"); + + code = "int f(int value) { return 0; }\n" + "std::shared_ptr g() {\n" + " static const std::shared_ptr x{ new M{} };\n" + " return x;\n" + "}\n"; + valueOfTok(code, "x"); } void valueFlowHang() {