redundantAssignmentInSwitch: fix false positive when there is goto

This commit is contained in:
Daniel Marjamäki 2018-11-24 21:39:01 +01:00
parent d2bd536f1b
commit 2f66b31d43
2 changed files with 9 additions and 1 deletions

View File

@ -471,7 +471,7 @@ const Token *CheckOther::checkRedundantAssignmentRecursive(const Token *assign1,
return nullptr;
}
if (Token::Match(tok, "break|continue|return|throw")) {
if (Token::Match(tok, "break|continue|return|throw|goto")) {
// TODO: handle these better
*read = true;
return nullptr;

View File

@ -1932,6 +1932,14 @@ private:
"}\n", nullptr, false, false, true);
ASSERT_EQUALS("", errout.str());
check("void f() {\n"
" int x;\n"
" switch (state) {\n"
" case 1: x = 3; goto a;\n"
" case 1: x = 6; goto a;\n"
" }\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void switchRedundantOperationTest() {