From 98480bf504097d23a507fd53c27a697de16f8891 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 1 Dec 2011 17:46:33 +0100 Subject: [PATCH] Fixed #3354 (Incorrect both sides of '||' expression match when using increment in expression.) --- lib/checkother.cpp | 3 +++ test/testother.cpp | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 29b02b11a..8c033e969 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -2566,6 +2566,9 @@ void CheckOther::checkExpressionRange(const std::list &constFunctions, break; } --brackets; + } else if (tok->str() == "++" || tok->str() == "--") { + valid = false; + break; } } diff --git a/test/testother.cpp b/test/testother.cpp index 6aed31d2e..624d85b5b 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -143,6 +143,7 @@ private: TEST_CASE(duplicateExpression1); TEST_CASE(duplicateExpression2); // ticket #2730 TEST_CASE(duplicateExpression3); // ticket #3317 + TEST_CASE(duplicateExpression4); // ticket #3354 (++) TEST_CASE(alwaysTrueFalseStringCompare); 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()); } + 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() { check_preprocess_suppress(