From 686e28de50f26f1b7b5d87693fecb2f525245854 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Fri, 12 Apr 2024 06:02:30 +0200 Subject: [PATCH] Add tests for #12205, #12405 (#6280) --- test/testother.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/testother.cpp b/test/testother.cpp index a9112277cde..4d4286ce1d5 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -99,6 +99,7 @@ class TestOther : public TestFixture { TEST_CASE(varScope36); // #12158 TEST_CASE(varScope37); // #12158 TEST_CASE(varScope38); + TEST_CASE(varScope39); TEST_CASE(oldStylePointerCast); TEST_CASE(invalidPointerCast); @@ -1693,6 +1694,22 @@ class TestOther : public TestFixture { ASSERT_EQUALS("", errout_str()); } + void varScope39() { + check("struct S {\n" // #12405 + " void f(const std::string&) const;\n" + " const int* g(std::string&) const;\n" + "};\n" + "void h(int);\n" + "void S::f(const std::string& s) const {\n" + " std::string n = s;\n" + " const int* a = g(n);\n" + " if (n == \"abc\") {\n" + " h(a[0]);\n" + " }\n" + "}\n"); + ASSERT_EQUALS("", errout_str()); + } + #define checkOldStylePointerCast(code) checkOldStylePointerCast_(code, __FILE__, __LINE__) void checkOldStylePointerCast_(const char code[], const char* file, int line) { @@ -4113,6 +4130,13 @@ class TestOther : public TestFixture { ASSERT_EQUALS("[test.cpp:3]: (style) C-style pointer casting\n" "[test.cpp:3]: (style) Variable 's' can be declared as pointer to const\n", errout_str()); // don't crash + + check("struct S { int i; };\n" // #12205 + "void f(S* s) {\n" + " (void)s->i;\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:2]: (style) Parameter 's' can be declared as pointer to const\n", + errout_str()); } void switchRedundantAssignmentTest() {