diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 1f2a460e7..3ac241912 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -5107,6 +5107,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 ea94938ea..3e2669979 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -6397,6 +6397,13 @@ private: " s;\n" "}\n"; valueOfTok(code, "s"); + + 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() {