From 92c9d9ef86bf3f1f06a8e7eb181998803de088c6 Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Fri, 12 Apr 2024 00:04:35 +0200 Subject: [PATCH] Add tests for #12205, #12405 --- test/testother.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/testother.cpp b/test/testother.cpp index 113de252214..4b4f6215cee 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() {