Skip to content

Commit

Permalink
Update testother.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github authored Jun 17, 2024
1 parent f304cee commit 47255f4
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions test/testother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ class TestOther : public TestFixture {
TEST_CASE(redundantVarAssignment_switch_break);
TEST_CASE(redundantInitialization);
TEST_CASE(redundantMemWrite);
TEST_CASE(redundantAssignmentSameValue);

TEST_CASE(varFuncNullUB);

Expand Down Expand Up @@ -8029,7 +8030,9 @@ class TestOther : public TestFixture {
" use(i);\n"
" i = j;\n"
"}");
ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:3]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'.\n", errout_str());
ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:6]: (style) Variable 'i' is assigned an expression that holds the same value.\n"
"[test.cpp:4] -> [test.cpp:3]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'.\n",
errout_str());

check("struct A { int x; int y; };"
"void use(int);\n"
Expand All @@ -8039,7 +8042,9 @@ class TestOther : public TestFixture {
" use(j);\n"
" j = i;\n"
"}");
ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:3]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'.\n", errout_str());
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:6]: (style) Variable 'j' is assigned an expression that holds the same value.\n"
"[test.cpp:4] -> [test.cpp:3]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'.\n",
errout_str());

check("struct A { int x; int y; };"
"void use(int);\n"
Expand Down Expand Up @@ -9707,7 +9712,10 @@ class TestOther : public TestFixture {
"}\n");
ASSERT_EQUALS("test.cpp:3:style:Variable 'm[key]' is reassigned a value before the old one has been used.\n"
"test.cpp:2:note:m[key] is assigned\n"
"test.cpp:3:note:m[key] is overwritten\n",
"test.cpp:3:note:m[key] is overwritten\n"
"test.cpp:3:style:Variable 'm[key]' is assigned an expression that holds the same value.\n"
"test.cpp:2:note:m[key] is assigned 'value' here.\n"
"test.cpp:3:note:Variable 'm[key]' is assigned an expression that holds the same value.\n",
errout_str());
}

Expand Down Expand Up @@ -10178,6 +10186,16 @@ class TestOther : public TestFixture {
TODO_ASSERT_EQUALS("error", "", errout_str());
}

void redundantAssignmentSameValue() {
check("int main() {\n" // #11642
" int a = 0;\n"
" int b = a;\n"
" int c = 1;\n"
" a = b;\n"
" return a * b * c;\n");
ASSERT_EQUALS("[test.cpp:2]: (portability) Passing NULL after the last typed argument to a variadic function leads to undefined behaviour.\n", errout_str());
}

void varFuncNullUB() { // #4482
check("void a(...);\n"
"void b() { a(NULL); }");
Expand Down

0 comments on commit 47255f4

Please sign in to comment.