diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index fb9f6dda7a1..967beaf3ea6 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -4099,6 +4099,8 @@ static bool isVariableInit(const Token *tok) return false; if (var->nameToken() != tok->astOperand1()) return false; + if (var->isPointer()) + return true; const ValueType* vt = var->valueType(); if (!vt) return false; diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 8305a63bc56..7fa28855eb1 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -3188,6 +3188,18 @@ class TestValueFlow : public TestFixture { " return x;\n" "}\n"; ASSERT_EQUALS(true, testValueOfXKnown(code, 3U, -1)); + + code = "A* f() {\n" // #14864 + " A* x{};\n" + " return x;\n" + "}\n"; + ASSERT_EQUALS(true, testValueOfXKnown(code, 3U, 0)); + + code = "A* f() {\n" + " A* x{ nullptr };\n" + " return x;\n" + "}\n"; + ASSERT_EQUALS(true, testValueOfXKnown(code, 3U, 0)); } void valueFlowAfterSwap()