Fixed #7907 (FN: redundant assignment inside switchcase, overwritten by assignment outside of switch)
This commit is contained in:
parent
4558fd5a2c
commit
fe38e256cc
|
@ -494,6 +494,8 @@ void CheckOther::checkRedundantAssignment()
|
|||
// there is redundant assignment. Is there a case between the assignments?
|
||||
bool hasCase = false;
|
||||
for (const Token *tok2 = tok; tok2 != nextAssign; tok2 = tok2->next()) {
|
||||
if (tok2->str() == "break" || tok2->str() == "return")
|
||||
break;
|
||||
if (tok2->str() == "case") {
|
||||
hasCase = true;
|
||||
break;
|
||||
|
|
|
@ -2284,6 +2284,27 @@ private:
|
|||
" bar(y);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:10]: (warning) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing?\n", errout.str());
|
||||
|
||||
check("bool f() {\n"
|
||||
" bool ret = false;\n"
|
||||
" switch (switchCond) {\n"
|
||||
" case 1:\n"
|
||||
" ret = true;\n"
|
||||
" break;\n"
|
||||
" case 31:\n"
|
||||
" ret = true;\n"
|
||||
" break;\n"
|
||||
" case 54:\n"
|
||||
" ret = true;\n"
|
||||
" break;\n"
|
||||
" };\n"
|
||||
" ret = true;\n"
|
||||
" return ret;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:14]: (style) Variable 'ret' is reassigned a value before the old one has been used.\n"
|
||||
"[test.cpp:8] -> [test.cpp:14]: (style) Variable 'ret' is reassigned a value before the old one has been used.\n"
|
||||
"[test.cpp:11] -> [test.cpp:14]: (style) Variable 'ret' is reassigned a value before the old one has been used.\n",
|
||||
errout.str());
|
||||
}
|
||||
|
||||
void switchRedundantBitwiseOperationTest() {
|
||||
|
|
Loading…
Reference in New Issue