Fixed #3354 (Incorrect both sides of '||' expression match when using increment in expression.)

This commit is contained in:
Daniel Marjamäki 2011-12-01 17:46:33 +01:00
parent fddfd16758
commit 98480bf504
2 changed files with 15 additions and 0 deletions

View File

@ -2566,6 +2566,9 @@ void CheckOther::checkExpressionRange(const std::list<Function> &constFunctions,
break; break;
} }
--brackets; --brackets;
} else if (tok->str() == "++" || tok->str() == "--") {
valid = false;
break;
} }
} }

View File

@ -143,6 +143,7 @@ private:
TEST_CASE(duplicateExpression1); TEST_CASE(duplicateExpression1);
TEST_CASE(duplicateExpression2); // ticket #2730 TEST_CASE(duplicateExpression2); // ticket #2730
TEST_CASE(duplicateExpression3); // ticket #3317 TEST_CASE(duplicateExpression3); // ticket #3317
TEST_CASE(duplicateExpression4); // ticket #3354 (++)
TEST_CASE(alwaysTrueFalseStringCompare); TEST_CASE(alwaysTrueFalseStringCompare);
TEST_CASE(checkStrncmpSizeof); TEST_CASE(checkStrncmpSizeof);
@ -3763,6 +3764,17 @@ private:
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2]: (style) Same expression on both sides of '||'.\n", errout.str()); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2]: (style) Same expression on both sides of '||'.\n", errout.str());
} }
void duplicateExpression4() {
check("void foo() {\n"
" if (*a++ != b || *a++ != b) {}\n"
"}");
ASSERT_EQUALS("", errout.str());
check("void foo() {\n"
" if (*a-- != b || *a-- != b) {}\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void alwaysTrueFalseStringCompare() { void alwaysTrueFalseStringCompare() {
check_preprocess_suppress( check_preprocess_suppress(