Add testcase for #8807 (False negative: Redundant variable assignments (loop))

This commit is contained in:
Daniel Marjamäki 2018-12-16 21:45:26 +01:00
parent c8d688607a
commit 357e2fbfb3
1 changed files with 19 additions and 0 deletions

View File

@ -108,6 +108,7 @@ private:
TEST_CASE(localvar52);
TEST_CASE(localvar53); // continue
TEST_CASE(localvar54); // ast, {}
TEST_CASE(localvar55);
TEST_CASE(localvarloops); // loops
TEST_CASE(localvaralias1);
TEST_CASE(localvaralias2); // ticket #1637
@ -2122,6 +2123,24 @@ private:
ASSERT_EQUALS("", errout.str());
}
void localvar55() {
functionVariableUsage("void f(int mode) {\n"
" int x = 0;\n" // <- redundant assignment
"\n"
" for (int i = 0; i < 10; i++) {\n"
" if (mode == 0x04)\n"
" x = 0;\n" // <- redundant assignment
" if (mode == 0x0f) {\n"
" x = address;\n"
" data[x] = 0;\n"
" }\n"
" }\n"
"}");
ASSERT_EQUALS("[test.cpp:2]: (style) Variable 'x' is assigned a value that is never used.\n"
"[test.cpp:6]: (style) Variable 'x' is assigned a value that is never used.\n",
errout.str());
}
void localvarloops() {
// loops
functionVariableUsage("void fun() {\n"