From 26722c2b3c01440a66c7488316b7dbcc237f95b5 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 17 Apr 2024 14:27:33 +0200 Subject: [PATCH] Update testother.cpp --- test/testother.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/test/testother.cpp b/test/testother.cpp index 85ee90f7ff6..b9bc5abea20 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -1712,7 +1712,7 @@ class TestOther : public TestFixture { } void varScope40() { - checkP("#define NUM (-999.9)\n" + checkP("#define NUM (-999.9)\n" // #8862 "double f(int i) {\n" " double a = NUM;\n" " double b = -NUM;\n" @@ -1732,6 +1732,19 @@ class TestOther : public TestFixture { "[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()); + + check("struct S { int a; };\n" // #12618 + "int f(const S* s, int i) {\n" + " int x = s->a;\n" + " const int b[] = { 1, 2, 3 };\n" + " int y = b[1];\n" + " if (i)\n" + " return x + y;\n" + " return 0;\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:3]: (style) The scope of the variable 'x' can be reduced.\n" + "[test.cpp:5]: (style) The scope of the variable 'y' can be reduced.\n", + errout_str()); } #define checkOldStylePointerCast(code) checkOldStylePointerCast_(code, __FILE__, __LINE__)