Skip to content

Commit 64b72bd

Browse files
committed
Fixed danmar#6227 (False positive (oppositeInnerCondition) - if (!dynamic_cast<>))
1 parent 5cc744b commit 64b72bd

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

lib/checkcondition.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class CPPCHECKLIB CheckCondition : public Check {
4848
CheckCondition checkCondition(tokenizer, settings, errorLogger);
4949
checkCondition.multiCondition();
5050
checkCondition.clarifyCondition(); // not simplified because ifAssign
51+
checkCondition.oppositeInnerCondition();
5152
}
5253

5354
/** @brief Run checks against the simplified token list */
@@ -56,7 +57,6 @@ class CPPCHECKLIB CheckCondition : public Check {
5657
checkCondition.assignIf();
5758
checkCondition.checkBadBitmaskCheck();
5859
checkCondition.comparison();
59-
checkCondition.oppositeInnerCondition();
6060
checkCondition.checkIncorrectLogicOperator();
6161
checkCondition.checkModuloAlwaysTrueFalse();
6262
checkCondition.alwaysTrueFalse();

test/testcondition.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,6 +1309,23 @@ class TestCondition : public TestFixture {
13091309
" }\n"
13101310
"}");
13111311
ASSERT_EQUALS("", errout.str());
1312+
1313+
// #6227 - FP caused by simplifications of casts and known variables
1314+
check("void foo(A *a) {\n"
1315+
" if(a) {\n"
1316+
" B *b = dynamic_cast<B*>(a);\n"
1317+
" if(!b) {}\n"
1318+
" }\n"
1319+
"}");
1320+
ASSERT_EQUALS("", errout.str());
1321+
1322+
check("void foo(int a) {\n"
1323+
" if(a) {\n"
1324+
" int b = a;\n"
1325+
" if(!b) {}\n"
1326+
" }\n"
1327+
"}");
1328+
TODO_ASSERT_EQUALS("error", "", errout.str());
13121329
}
13131330

13141331
// clarify conditions with = and comparison

0 commit comments

Comments
 (0)