From 8356ec677490b119231cf25c93693dc2751ff8d6 Mon Sep 17 00:00:00 2001 From: rikardfalkeborn Date: Wed, 23 Jan 2019 09:09:03 +0100 Subject: [PATCH] Add regression test for #6906 and #7284 (#1614) * Add regression test for #6906 Ticket #6906 was fixed in f65cf220ba05c84a0dc0c8376c29455939408197. Add a test to make sure there are no regressions. * Add regression test for #7284 Ticket #7284 was fixed in 5d1fdf7958290d098998ba8afd7af391cc14d5a8. Add tests to avoid regressions. --- test/testcondition.cpp | 7 +++++++ test/testother.cpp | 13 +++++++++++++ 2 files changed, 20 insertions(+) diff --git a/test/testcondition.cpp b/test/testcondition.cpp index 71accd870..ed0a0a787 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -496,6 +496,13 @@ private: " else if (bar() >1 && b) {}\n" "}"); ASSERT_EQUALS("[test.cpp:5]: (style) Expression is always false because 'else if' condition matches previous condition at line 4.\n", errout.str()); + + // 7284 + check("void foo() {\n" + " if (a) {}\n" + " else if (!!a) {}\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:3]: (style) Expression is always false because 'else if' condition matches previous condition at line 2.\n", errout.str()); } void checkPureFunction(const char code[]) { diff --git a/test/testother.cpp b/test/testother.cpp index ca9c31534..71c675cb8 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -4082,6 +4082,19 @@ private: " return a && b && c;\n" "}\n"); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) Same expression on both sides of '&&' because 'a' and 'c' represent the same value.\n", errout.str()); + + // 6906 + check("void f(const bool b) {\n" + " const bool b1 = !b;\n" + " if(!b && b1){}\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) Same expression on both sides of '&&' because '!b' and 'b1' represent the same value.\n", errout.str()); + + // 7482 + check("void f(void) {\n" + " if (a || !!a) {}\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:2]: (style) Same expression on both sides of '||' because 'a' and '!!a' represent the same value.\n", errout.str()); } void duplicateExpression8() {