Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/checkcondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ void CheckCondition::oppositeElseIfConditionError(const Token *ifCond, const Tok

//---------------------------------------------------------------------------
// - Opposite inner conditions => always false
// - (TODO) Same/Overlapping inner condition => always true
// - Same/Overlapping inner condition => always true
// - same condition after early exit => always false
//---------------------------------------------------------------------------

Expand Down Expand Up @@ -759,6 +759,8 @@ void CheckCondition::multiCondition2()
oppositeInnerConditionError(firstCondition, cond2, errorPath);
} else if (!isReturnVar && isSameExpression(true, firstCondition, cond2, *mSettings, true, true, &errorPath)) {
identicalInnerConditionError(firstCondition, cond2, errorPath);
} else if (!isReturnVar && isOverlappingCond(cond2, firstCondition, true)) {
identicalInnerConditionError(firstCondition, cond2, errorPath);
}
}
return ChildrenToVisit::none;
Expand Down
2 changes: 1 addition & 1 deletion lib/checkcondition.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class CPPCHECKLIB CheckCondition : public Check {
/**
* multiconditions #2
* - Opposite inner conditions => always false
* - (TODO) Same/Overlapping inner condition => always true
* - Same/Overlapping inner condition => always true
* - same condition after early exit => always false
**/
void multiCondition2();
Expand Down
14 changes: 14 additions & 0 deletions test/testcondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2834,6 +2834,20 @@ class TestCondition : public TestFixture {
" }\n"
"}\n");
ASSERT_EQUALS("[test.cpp:2:12] -> [test.cpp:4:13]: (warning) Identical inner 'if' condition is always true. [identicalInnerCondition]\n", errout_str());

check("void f(int x) {\n"
" if (x == 1) {\n"
" if (x & 7) {}\n"
" }\n"
"}");
ASSERT_EQUALS("[test.cpp:2:11] -> [test.cpp:3:15]: (warning) Identical inner 'if' condition is always true. [identicalInnerCondition]\n", errout_str());
Comment thread
danmar marked this conversation as resolved.
Outdated

check("void f(int x) {\n"
" if (x & 7) {\n"
" if (x == 1) {}\n"
" }\n"
"}");
ASSERT_EQUALS("", errout_str());
}

void identicalConditionAfterEarlyExit() {
Expand Down
Loading