Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/programmemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())) {
Expand Down
18 changes: 16 additions & 2 deletions test/testcondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const One*>(&b);\n"
" if (one == nullptr)\n"
" two = dynamic_cast<const Two*>(&b);\n"
" if (two) {}\n"
"}\n");
ASSERT_EQUALS("", errout_str());
}

void knownConditionIncrementLoop() { // #9808
Expand Down