Skip to content

Commit 28dfa41

Browse files
Fix #14724 FP: overlapping inner condition, function call (#8527)
Co-authored-by: chrchr-github <noreply@github.com>
1 parent 4ff8d43 commit 28dfa41

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

lib/checkcondition.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,7 @@ void CheckCondition::multiCondition2()
684684
if (!nonlocal && var) {
685685
if (!(var->isLocal() || var->isArgument()))
686686
nonlocal = true;
687-
else if ((var->isPointer() || var->isReference()) && !Token::Match(cond->astParent(), "%oror%|&&|!"))
687+
else if ((var->isPointer() || var->isReference() || var->isArray()) && !Token::Match(cond->astParent(), "%oror%|&&|!"))
688688
// TODO: if var is pointer check what it points at
689689
nonlocal = true;
690690
}

test/testcondition.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2843,6 +2843,15 @@ class TestCondition : public TestFixture {
28432843
" return 0;\n"
28442844
"}\n");
28452845
ASSERT_EQUALS("", errout_str());
2846+
2847+
check("void f(int x, int y) {\n"
2848+
" int a[] = { x, y };\n"
2849+
" if (a[0] == 1) {\n"
2850+
" if (a[0] == 1) {}\n"
2851+
" }\n"
2852+
"}");
2853+
ASSERT_EQUALS("[test.cpp:3:14] -> [test.cpp:4:18]: (warning) Identical inner 'if' condition is always true. [identicalInnerCondition]\n",
2854+
errout_str());
28462855
}
28472856

28482857
void identicalConditionAfterEarlyExit() {
@@ -3029,6 +3038,15 @@ class TestCondition : public TestFixture {
30293038
" }\n"
30303039
"}");
30313040
ASSERT_EQUALS("", errout_str());
3041+
3042+
check("void g(int[]);\n" // #14724
3043+
"void f(int a[]) {\n"
3044+
" if (a[0] == 1) {\n"
3045+
" g(a);\n"
3046+
" if (a[0] == 1) {}\n"
3047+
" }\n"
3048+
"}");
3049+
ASSERT_EQUALS("", errout_str());
30323050
}
30333051

30343052
void overlappingInnerCondition() {

0 commit comments

Comments
 (0)