Skip to content

Commit

Permalink
Update testother.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Apr 15, 2024
1 parent bbe8667 commit 6730be6
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test/testother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 6730be6

Please sign in to comment.