Redundant assignment: Added TODO testcase for detecting redundant assignment in inner scope

This commit is contained in:
Daniel Marjamäki 2010-04-24 12:21:26 +02:00
parent e6f640d816
commit 1eafe45c47
1 changed files with 33 additions and 0 deletions

View File

@ -73,6 +73,7 @@ private:
TEST_CASE(localvar8);
TEST_CASE(localvar9); // ticket #1605
TEST_CASE(localvar10);
TEST_CASE(localvar11);
TEST_CASE(localvaralias);
TEST_CASE(localvarasm);
@ -641,6 +642,38 @@ private:
"[test.cpp:7]: (style) Unused variable: i\n", errout.str());
}
void localvar11()
{
functionVariableUsage("void foo(int x)\n"
"{\n"
" int a = 0;\n"
" if (x == 1)\n"
" {\n"
" a = 123;\n" // redundant assignment
" return;\n"
" }\n"
" x = a;\n"
"}\n");
ASSERT_EQUALS("", errout.str()); // catch changes
TODO_ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'a' is assigned a value that is never used\n", errout.str());
// The variable 'a' is initialized. But the initialized value is
// never used. It is only initialized for security reasons.
functionVariableUsage("void foo(int x)\n"
"{\n"
" int a = 0;\n"
" if (x == 1)\n"
" a = 123;\n"
" else if (x == 2)\n"
" a = 456;\n"
" else\n"
" return;\n"
" x = a;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void localvaralias()
{
functionVariableUsage("void foo()\n"