diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index f1448e6a1..e2acc5b55 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2349,7 +2349,7 @@ void Tokenizer::simplifyLabelsCaseDefault() } else if (Token::Match(tok, "(|[")) tok = tok->link(); - if (Token::Match(tok, "[;{}] case")) { + if (Token::Match(tok, "[;{}:] case")) { while (nullptr != (tok = tok->next())) { if (Token::Match(tok, "(|[")) { tok = tok->link(); @@ -2367,8 +2367,10 @@ void Tokenizer::simplifyLabelsCaseDefault() break; if (tok->str() != "case" && tok->next() && tok->next()->str() == ":") { tok = tok->next(); - if (tok->next()->str() != ";") + if (tok->next()->str() != ";" && tok->next()->str() != "case") tok->insertToken(";"); + else + tok = tok->previous(); } else { syntaxError(tok); } @@ -8064,7 +8066,7 @@ void Tokenizer::eraseDeadCode(Token *begin, const Token *end) else indentcase = switchindents[indentswitch-1]; } - } else if (Token::Match(tok, "[{};] case")) { + } else if (Token::Match(tok, "[{};:] case")) { const Token *tok2 = Token::findsimplematch(tok->next(), ": ;", end); if (!tok2) { tok->deleteNext(); @@ -8106,7 +8108,7 @@ void Tokenizer::eraseDeadCode(Token *begin, const Token *end) while (tok2->next() && tok2->next() != end) { if (Token::Match(tok2->next(), "{|[|(")) { tok2 = tok2->next()->link(); - } else if (Token::Match(tok2, "[{};] case")) { + } else if (Token::Match(tok2, "[{};:] case")) { const Token *tok3 = Token::findsimplematch(tok2->next(), ": ;", end); if (!tok3) { tok2 = tok2->next(); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index ad0b5c362..cac367d52 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -7994,11 +7994,11 @@ private: } void simplifyCaseRange() { - ASSERT_EQUALS("void f ( ) { case 1 : ; case 2 : ; case 3 : ; case 4 : ; }", tokenizeAndStringify("void f() { case 1 ... 4: }")); + ASSERT_EQUALS("void f ( ) { case 1 : case 2 : case 3 : case 4 : ; }", tokenizeAndStringify("void f() { case 1 ... 4: }")); ASSERT_EQUALS("void f ( ) { case 4 . . . 1 : ; }", tokenizeAndStringify("void f() { case 4 ... 1: }")); tokenizeAndStringify("void f() { case 1 ... 1000000: }"); // Do not run out of memory - ASSERT_EQUALS("void f ( ) { case 'a' : ; case 'b' : ; case 'c' : ; }", tokenizeAndStringify("void f() { case 'a' ... 'c': }")); + ASSERT_EQUALS("void f ( ) { case 'a' : case 'b' : case 'c' : ; }", tokenizeAndStringify("void f() { case 'a' ... 'c': }")); ASSERT_EQUALS("void f ( ) { case 'c' . . . 'a' : ; }", tokenizeAndStringify("void f() { case 'c' ... 'a': }")); }