From f90a93591f5ae417ecac17154b1bbb406338072a Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 15 Mar 2022 12:54:19 +0100 Subject: [PATCH] Add tests for #9871, #10144 (#3902) * Add test for #9871 * Add test for #10144 * Format --- test/testother.cpp | 11 +++++++++++ test/testsimplifytypedef.cpp | 10 ++++++++++ 2 files changed, 21 insertions(+) diff --git a/test/testother.cpp b/test/testother.cpp index cec87da46..52183a2fa 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -156,6 +156,7 @@ private: TEST_CASE(duplicateExpression11); // #8916 (function call) TEST_CASE(duplicateExpression12); // #10026 TEST_CASE(duplicateExpression13); // #7899 + TEST_CASE(duplicateExpression14); // #9871 TEST_CASE(duplicateExpressionLoop); TEST_CASE(duplicateValueTernary); TEST_CASE(duplicateExpressionTernary); // #6391 @@ -5592,6 +5593,16 @@ private: ASSERT_EQUALS("", errout.str()); } + void duplicateExpression14() { //#9871 + check("int f() {\n" + " int k = 7;\n" + " int* f = &k;\n" + " int* g = &k;\n" + " return (f + 4 != g + 4);\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4] -> [test.cpp:5]: (style) The comparison 'f+4 != g+4' is always false because 'f+4' and 'g+4' represent the same value.\n", errout.str()); + } + void duplicateExpressionLoop() { check("void f() {\n" " int a = 1;\n" diff --git a/test/testsimplifytypedef.cpp b/test/testsimplifytypedef.cpp index 9c0495e0e..b5941bdb3 100644 --- a/test/testsimplifytypedef.cpp +++ b/test/testsimplifytypedef.cpp @@ -187,6 +187,7 @@ private: TEST_CASE(simplifyTypedef138); TEST_CASE(simplifyTypedef139); TEST_CASE(simplifyTypedef140); // #10798 + TEST_CASE(simplifyTypedef141); // #10144 TEST_CASE(simplifyTypedefFunction1); TEST_CASE(simplifyTypedefFunction2); // ticket #1685 @@ -3039,7 +3040,16 @@ private: "enum class E { A };\n"; ASSERT_EQUALS("enum class E { A } ;", tok(code)); } + } + void simplifyTypedef141() { // #10144 + const char code[] = "class C {\n" + " struct I {\n" + " using vt = const std::string;\n" + " using ptr = vt*;\n" + " };\n" + "};\n"; + ASSERT_EQUALS("class C { struct I { } ; } ;", tok(code)); } void simplifyTypedefFunction1() {