diff --git a/lib/programmemory.cpp b/lib/programmemory.cpp index 458183e6a81..1e7ba3323d6 100644 --- a/lib/programmemory.cpp +++ b/lib/programmemory.cpp @@ -1572,8 +1572,11 @@ namespace { return unknown(); } else if (expr->str() == "(" && expr->isCast()) { - if (Token::simpleMatch(expr->previous(), ">") && expr->linkAt(-1)) - return execute(expr->astOperand2()); + if (expr->astOperand2()) { + if (expr->astOperand1()->str() != "dynamic_cast") + return execute(expr->astOperand2()); + return unknown(); + } return execute(expr->astOperand1()); } if (expr->exprId() > 0 && pm->hasValue(expr->exprId())) { diff --git a/test/testcondition.cpp b/test/testcondition.cpp index 2cedb63758e..45ec8d5fb24 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -6084,11 +6084,25 @@ class TestCondition : public TestFixture { errout_str()); } - void knownConditionCast() { // #9976 - check("void f(int i) {\n" + void knownConditionCast() { + check("void f(int i) {\n" // #9976 " if (i < 0 || (unsigned)i > 5) {}\n" "}\n"); ASSERT_EQUALS("", errout_str()); + + check("struct B {\n" // #12941 + " virtual void f();\n" + "};\n" + "struct One : public B {};\n" + "struct Two : public B {};\n" + "void g(const B& b) {\n" + " const Two* two = nullptr;\n" + " const One* one = dynamic_cast(&b);\n" + " if (one == nullptr)\n" + " two = dynamic_cast(&b);\n" + " if (two) {}\n" + "}\n"); + ASSERT_EQUALS("", errout_str()); } void knownConditionIncrementLoop() { // #9808