Fixed wrong message shown if unused label appears directly after a switch() scope
This commit is contained in:
parent
b6614d0aa4
commit
e23dc5c1e2
|
@ -2589,7 +2589,7 @@ void CheckOther::checkUnusedLabel()
|
||||||
|
|
||||||
if (Token::Match(tok, "{|}|; %name% :") && tok->strAt(1) != "default") {
|
if (Token::Match(tok, "{|}|; %name% :") && tok->strAt(1) != "default") {
|
||||||
if (!Token::findsimplematch(scope->classStart->next(), ("goto " + tok->strAt(1)).c_str(), scope->classEnd->previous()))
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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"
|
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());
|
"[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() {
|
void testEvaluationOrder() {
|
||||||
|
|
Loading…
Reference in New Issue