@@ -2481,7 +2481,7 @@ void CheckOther::raceAfterInterlockedDecrementError(const Token* tok)
24812481
24822482void CheckOther::checkUnusedLabel ()
24832483{
2484- if (!_settings->isEnabled (" style" ))
2484+ if (!_settings->isEnabled (" style" ) && !_settings-> isEnabled ( " warning " ) )
24852485 return ;
24862486
24872487 const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase ();
@@ -2495,16 +2495,23 @@ void CheckOther::checkUnusedLabel()
24952495
24962496 if (Token::Match (tok, " {|}|; %name% :" ) && tok->strAt (1 ) != " default" ) {
24972497 if (!Token::findsimplematch (scope->classStart ->next (), (" goto " + tok->strAt (1 )).c_str (), scope->classEnd ->previous ()))
2498- unusedLabelError (tok->next ());
2498+ unusedLabelError (tok->next (), tok-> scope ()-> type == Scope::eSwitch );
24992499 }
25002500 }
25012501 }
25022502}
25032503
2504- void CheckOther::unusedLabelError (const Token* tok)
2504+ void CheckOther::unusedLabelError (const Token* tok, bool inSwitch )
25052505{
2506- reportError (tok, Severity::style, " unusedLabel" ,
2507- " Label '" + (tok?tok->str ():emptyString) + " ' is not used." );
2506+ if (inSwitch) {
2507+ if (!tok || _settings->isEnabled (" warning" ))
2508+ reportError (tok, Severity::warning, " unusedLabelSwitch" ,
2509+ " Label '" + (tok ? tok->str () : emptyString) + " ' is not used. Should this be a 'case' of the enclosing switch()?" );
2510+ } else {
2511+ if (!tok || _settings->isEnabled (" style" ))
2512+ reportError (tok, Severity::style, " unusedLabel" ,
2513+ " Label '" + (tok ? tok->str () : emptyString) + " ' is not used." );
2514+ }
25082515}
25092516
25102517
0 commit comments