From 6730be6da3c0faf2779251f07a9a9d56919ffe15 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Mon, 15 Apr 2024 14:33:40 +0200 Subject: [PATCH] Update testother.cpp --- test/testother.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/testother.cpp b/test/testother.cpp index 4d4286ce1d5..c677c16fbf0 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -100,6 +100,7 @@ class TestOther : public TestFixture { TEST_CASE(varScope37); // #12158 TEST_CASE(varScope38); TEST_CASE(varScope39); + TEST_CASE(varScope40); TEST_CASE(oldStylePointerCast); TEST_CASE(invalidPointerCast); @@ -1710,6 +1711,28 @@ class TestOther : public TestFixture { ASSERT_EQUALS("", errout_str()); } + void varScope40() { + checkP("#define NUM (-999.9)\n" + "double f(int i) {\n" + " double a = NUM;\n" + " double b = -NUM;\n" + " double c = -1.0 * NUM;\n" + " if (i == 1) {\n" + " return a;\n" + " }\n" + " if (i == 2) {\n" + " return b;\n" + " }\n" + " if (i == 3) {\n" + " return c;\n" + " }\n" + " return 0.0;\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:3]: (style) The scope of the variable 'a' can be reduced.\n" + "[test.cpp:4]: (style) The scope of the variable 'b' can be reduced.\n" + "[test.cpp:5]: (style) The scope of the variable 'c' can be reduced.\n", + errout_str()); + } #define checkOldStylePointerCast(code) checkOldStylePointerCast_(code, __FILE__, __LINE__) void checkOldStylePointerCast_(const char code[], const char* file, int line) {