From c5673612e285d1d347b6a7d2b90f5eb4abe21422 Mon Sep 17 00:00:00 2001 From: amai2012 Date: Thu, 30 Jul 2015 10:30:30 +0200 Subject: [PATCH] #6069 False positive incorrectLogicOperator due to dynamic_cast. Run CheckCondition::checkIncorrectLogicOperator on non-simplified tokenlist. --- lib/checkcondition.h | 2 +- test/testcondition.cpp | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/checkcondition.h b/lib/checkcondition.h index cc9e7805a..7478c8f41 100644 --- a/lib/checkcondition.h +++ b/lib/checkcondition.h @@ -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(); } diff --git a/test/testcondition.cpp b/test/testcondition.cpp index 70f3eb8b8..699947a81 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -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(obj));\n" + "}"); + ASSERT_EQUALS("", errout.str()); + } + void secondAlwaysTrueFalseWhenFirstTrueError() { check("void f(int x) {\n" " if (x > 5 && x != 1)\n"