Skip to content

Commit

Permalink
Add tests for #12205, #12405 (#6280)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Apr 12, 2024
1 parent a41ef74 commit 686e28d
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions test/testother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 686e28d

Please sign in to comment.