Skip to content

Commit 766c5b5

Browse files
Fix #14595 FN identicalInnerCondition in for loop (#8335)
1 parent ade8582 commit 766c5b5

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

lib/checkcondition.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,8 @@ static bool isNonConstFunctionCall(const Token *ftok, const Library &library)
619619
return false;
620620
if (ftok->function() && ftok->function()->isConst())
621621
return false;
622+
if (ftok->isControlFlowKeyword())
623+
return false;
622624
return true;
623625
}
624626

test/testcondition.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2820,6 +2820,14 @@ class TestCondition : public TestFixture {
28202820
" }\n"
28212821
"}");
28222822
ASSERT_EQUALS("", errout_str());
2823+
2824+
check("void f(const int* p, const int* e) {\n" // #14595
2825+
" for (; p;) {\n"
2826+
" if (p == e) {}\n"
2827+
" if (p) {}\n"
2828+
" }\n"
2829+
"}\n");
2830+
ASSERT_EQUALS("[test.cpp:2:12] -> [test.cpp:4:13]: (warning) Identical inner 'if' condition is always true. [identicalInnerCondition]\n", errout_str());
28232831
}
28242832

28252833
void identicalConditionAfterEarlyExit() {
@@ -4675,7 +4683,7 @@ class TestCondition : public TestFixture {
46754683
" }\n"
46764684
" }\n"
46774685
"}\n");
4678-
ASSERT_EQUALS("[test.cpp:5:18]: (style) Condition 'S::s' is always true [knownConditionTrueFalse]\n", errout_str());
4686+
ASSERT_EQUALS("[test.cpp:3:10] -> [test.cpp:5:18]: (warning) Identical inner 'if' condition is always true. [identicalInnerCondition]\n", errout_str());
46794687

46804688
check("void f() {\n" // #10811
46814689
" int i = 0;\n"
@@ -4836,7 +4844,7 @@ class TestCondition : public TestFixture {
48364844
" if (!b) {}\n"
48374845
" if (a) {}\n"
48384846
"}\n");
4839-
ASSERT_EQUALS("[test.cpp:6:9] -> [test.cpp:9:9]: (style) Condition 'a' is always false [knownConditionTrueFalse]\n",
4847+
ASSERT_EQUALS("[test.cpp:6:9] -> [test.cpp:9:9]: (warning) Identical condition 'a', second condition is always false [identicalConditionAfterEarlyExit]\n",
48404848
errout_str());
48414849
}
48424850

0 commit comments

Comments
 (0)