Skip to content

Commit c149202

Browse files
authored
Fix 10624: FP knownConditionTrueFalse with pointer member and dynamic cast (#3598)
1 parent a0d6339 commit c149202

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

lib/valueflow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ static void setTokenValue(Token* tok, ValueFlow::Value value, const Settings* se
598598
// cast..
599599
if (const Token *castType = getCastTypeStartToken(parent)) {
600600
if (((tok->valueType() == nullptr && value.isImpossible()) || astIsPointer(tok)) &&
601-
value.valueType == ValueFlow::Value::ValueType::INT &&
601+
contains({ValueFlow::Value::ValueType::INT, ValueFlow::Value::ValueType::SYMBOLIC}, value.valueType) &&
602602
Token::simpleMatch(parent->astOperand1(), "dynamic_cast"))
603603
return;
604604
const ValueType &valueType = ValueType::parseDecl(castType, settings);

test/testcondition.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3914,6 +3914,19 @@ class TestCondition : public TestFixture {
39143914
" if (m_PC->GetI() != I) {}\n"
39153915
"}\n");
39163916
ASSERT_EQUALS("", errout.str());
3917+
3918+
// #10624
3919+
check("struct Data {\n"
3920+
" Base* PBase{};\n"
3921+
"};\n"
3922+
"void f(Data* BaseData) {\n"
3923+
" Base* PObj = BaseData->PBase;\n"
3924+
" if (PObj == nullptr)\n"
3925+
" return;\n"
3926+
" Derived* pD = dynamic_cast<Derived*>(PObj);\n"
3927+
" if (pD) {}\n"
3928+
"}\n");
3929+
ASSERT_EQUALS("", errout.str());
39173930
}
39183931

39193932
void alwaysTrueInfer() {

0 commit comments

Comments
 (0)