diff --git a/lib/checkcondition.cpp b/lib/checkcondition.cpp index 59aad6a9598..14fa900944d 100644 --- a/lib/checkcondition.cpp +++ b/lib/checkcondition.cpp @@ -619,6 +619,8 @@ static bool isNonConstFunctionCall(const Token *ftok, const Library &library) return false; if (ftok->function() && ftok->function()->isConst()) return false; + if (ftok->isControlFlowKeyword()) + return false; return true; } diff --git a/test/testcondition.cpp b/test/testcondition.cpp index a592c489c59..241d0400099 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -2820,6 +2820,14 @@ class TestCondition : public TestFixture { " }\n" "}"); ASSERT_EQUALS("", errout_str()); + + check("void f(const int* p, const int* e) {\n" // #14595 + " for (; p;) {\n" + " if (p == e) {}\n" + " if (p) {}\n" + " }\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:2:12] -> [test.cpp:4:13]: (warning) Identical inner 'if' condition is always true. [identicalInnerCondition]\n", errout_str()); } void identicalConditionAfterEarlyExit() { @@ -4675,7 +4683,7 @@ class TestCondition : public TestFixture { " }\n" " }\n" "}\n"); - ASSERT_EQUALS("[test.cpp:5:18]: (style) Condition 'S::s' is always true [knownConditionTrueFalse]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10] -> [test.cpp:5:18]: (warning) Identical inner 'if' condition is always true. [identicalInnerCondition]\n", errout_str()); check("void f() {\n" // #10811 " int i = 0;\n" @@ -4836,7 +4844,7 @@ class TestCondition : public TestFixture { " if (!b) {}\n" " if (a) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:6:9] -> [test.cpp:9:9]: (style) Condition 'a' is always false [knownConditionTrueFalse]\n", + ASSERT_EQUALS("[test.cpp:6:9] -> [test.cpp:9:9]: (warning) Identical condition 'a', second condition is always false [identicalConditionAfterEarlyExit]\n", errout_str()); }