Fixed wrong message shown if unused label appears directly after a switch() scope

This commit is contained in:
PKEuS 2016-11-20 14:43:54 +01:00
parent b6614d0aa4
commit e23dc5c1e2
2 changed files with 10 additions and 1 deletions

View File

@ -2589,7 +2589,7 @@ void CheckOther::checkUnusedLabel()
if (Token::Match(tok, "{|}|; %name% :") && tok->strAt(1) != "default") {
if (!Token::findsimplematch(scope->classStart->next(), ("goto " + tok->strAt(1)).c_str(), scope->classEnd->previous()))
unusedLabelError(tok->next(), tok->scope()->type == Scope::eSwitch);
unusedLabelError(tok->next(), tok->next()->scope()->type == Scope::eSwitch);
}
}
}

View File

@ -5972,6 +5972,15 @@ private:
"}");
ASSERT_EQUALS("[test.cpp:3]: (warning) Label 'caseZERO' is not used. Should this be a 'case' of the enclosing switch()?\n"
"[test.cpp:5]: (warning) Label 'case1' is not used. Should this be a 'case' of the enclosing switch()?\n", errout.str());
check("int test(char art) {\n"
" switch (art) {\n"
" case 2:\n"
" return 2;\n"
" }\n"
" label:\n"
"}");
ASSERT_EQUALS("[test.cpp:6]: (style) Label 'label' is not used.\n", errout.str());
}
void testEvaluationOrder() {