Skip to content

Commit 5342e2c

Browse files
Fix #11037 FP knownConditionTrueFalse with dynamic_cast (#4297)
1 parent 4316884 commit 5342e2c

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

lib/valueflow.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -800,8 +800,7 @@ static void setTokenValue(Token* tok,
800800

801801
// cast..
802802
if (const Token *castType = getCastTypeStartToken(parent)) {
803-
if (((tok->valueType() == nullptr && value.isImpossible()) || astIsPointer(tok)) &&
804-
contains({ValueFlow::Value::ValueType::INT, ValueFlow::Value::ValueType::SYMBOLIC}, value.valueType) &&
803+
if (contains({ValueFlow::Value::ValueType::INT, ValueFlow::Value::ValueType::SYMBOLIC}, value.valueType) &&
805804
Token::simpleMatch(parent->astOperand1(), "dynamic_cast"))
806805
return;
807806
const ValueType &valueType = ValueType::parseDecl(castType, settings);

test/testcondition.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,17 @@ class TestCondition : public TestFixture {
667667
"}");
668668
ASSERT_EQUALS("", errout.str());
669669

670+
check("class B { virtual void v() {} };\n" // #11037
671+
"class D1 : public B {};\n"
672+
"class D2 : public B {};\n"
673+
"void f(const std::shared_ptr<B>&p) {\n"
674+
" const auto d1 = dynamic_cast<D1*>(p.get());\n"
675+
" const auto d2 = dynamic_cast<D2*>(p.get());\n"
676+
" if (d1) {}\n"
677+
" else if (d2) {}\n"
678+
"}\n");
679+
ASSERT_EQUALS("", errout.str());
680+
670681
check("void f(int x) {\n" // #6482
671682
" if (x & 1) {}\n"
672683
" else if (x == 0) {}\n"

0 commit comments

Comments
 (0)