From 9afeef01c6175b42dde72faed19c30e50a0d2aae Mon Sep 17 00:00:00 2001 From: Rikard Falkeborn Date: Fri, 10 Jan 2020 10:02:50 +0100 Subject: [PATCH] Improve duplicateExpressionTernary (#2484) Test both the cases where sizeof(int) == sizeof(long) and when they are different to improve testing. --- test/testother.cpp | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/test/testother.cpp b/test/testother.cpp index 715a5a6ac..d7a6e4c70 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -4846,10 +4846,24 @@ private: ASSERT_EQUALS("", errout.str()); // #6426 - check("void foo(bool flag) {\n" - " bar( (flag) ? ~0u : ~0ul);\n" - "}"); - ASSERT_EQUALS((_settings.sizeof_int==_settings.sizeof_long)?"[test.cpp:2]: (style) Same value in both branches of ternary operator.\n":"", errout.str()); + { + const char code[] = "void foo(bool flag) {\n" + " bar( (flag) ? ~0u : ~0ul);\n" + "}"; + Settings settings = _settings; + settings.sizeof_int = 4; + settings.int_bit = 32; + + settings.sizeof_long = 4; + settings.long_bit = 32; + check(code, &settings); + ASSERT_EQUALS("[test.cpp:2]: (style) Same value in both branches of ternary operator.\n", errout.str()); + + settings.sizeof_long = 8; + settings.long_bit = 64; + check(code, &settings); + ASSERT_EQUALS("", errout.str()); + } } void duplicateValueTernary() {