#6069 False positive incorrectLogicOperator due to dynamic_cast. Run CheckCondition::checkIncorrectLogicOperator on non-simplified tokenlist.

This commit is contained in:
amai2012 2015-07-30 10:30:30 +02:00
parent 9085fdc156
commit c5673612e2
2 changed files with 11 additions and 1 deletions

View File

@ -49,6 +49,7 @@ public:
checkCondition.multiCondition();
checkCondition.clarifyCondition(); // not simplified because ifAssign
checkCondition.oppositeInnerCondition();
checkCondition.checkIncorrectLogicOperator();
}
/** @brief Run checks against the simplified token list */
@ -57,7 +58,6 @@ public:
checkCondition.assignIf();
checkCondition.checkBadBitmaskCheck();
checkCondition.comparison();
checkCondition.checkIncorrectLogicOperator();
checkCondition.checkModuloAlwaysTrueFalse();
checkCondition.alwaysTrueFalse();
}

View File

@ -47,6 +47,7 @@ private:
TEST_CASE(incorrectLogicOperator6); // char literals
TEST_CASE(incorrectLogicOperator7); // opposite expressions: (expr || !expr)
TEST_CASE(incorrectLogicOperator8); // !
TEST_CASE(incorrectLogicOperator9);
TEST_CASE(secondAlwaysTrueFalseWhenFirstTrueError);
TEST_CASE(incorrectLogicOp_condSwapping);
TEST_CASE(testBug5895);
@ -932,6 +933,15 @@ private:
ASSERT_EQUALS("[test.cpp:2]: (warning) Logical conjunction always evaluates to false: !(i != 10) && !(i != 20).\n", errout.str());
}
void incorrectLogicOperator9() { // #6069 "False positive incorrectLogicOperator due to dynamic_cast"
check("class MyType;\n"
"class OtherType;\n"
"void foo (OtherType* obj) { \n"
" assert((!obj) || dynamic_cast<MyType*>(obj));\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void secondAlwaysTrueFalseWhenFirstTrueError() {
check("void f(int x) {\n"
" if (x > 5 && x != 1)\n"