diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 31a00bcbc..6283b5406 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -800,8 +800,7 @@ static void setTokenValue(Token* tok, // cast.. if (const Token *castType = getCastTypeStartToken(parent)) { - if (((tok->valueType() == nullptr && value.isImpossible()) || astIsPointer(tok)) && - contains({ValueFlow::Value::ValueType::INT, ValueFlow::Value::ValueType::SYMBOLIC}, value.valueType) && + if (contains({ValueFlow::Value::ValueType::INT, ValueFlow::Value::ValueType::SYMBOLIC}, value.valueType) && Token::simpleMatch(parent->astOperand1(), "dynamic_cast")) return; const ValueType &valueType = ValueType::parseDecl(castType, settings); diff --git a/test/testcondition.cpp b/test/testcondition.cpp index a270641da..fc8a9f16d 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -667,6 +667,17 @@ private: "}"); ASSERT_EQUALS("", errout.str()); + check("class B { virtual void v() {} };\n" // #11037 + "class D1 : public B {};\n" + "class D2 : public B {};\n" + "void f(const std::shared_ptr&p) {\n" + " const auto d1 = dynamic_cast(p.get());\n" + " const auto d2 = dynamic_cast(p.get());\n" + " if (d1) {}\n" + " else if (d2) {}\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + check("void f(int x) {\n" // #6482 " if (x & 1) {}\n" " else if (x == 0) {}\n"