diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index b56ba9e25..d31c06fe3 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -9124,7 +9124,8 @@ void Tokenizer::simplifyBitfields() { Token *last = 0; - if (Token::Match(tok, ";|{|}|public:|protected:|private: const| %type% %var% : %any% ;|,")) + if (Token::Match(tok, ";|{|}|public:|protected:|private: const| %type% %var% : %any% ;|,") && + tok->next()->str() != "case") { int offset = 0; if (tok->next()->str() == "const") @@ -9133,7 +9134,8 @@ void Tokenizer::simplifyBitfields() last = tok->tokAt(5 + offset); Token::eraseTokens(tok->tokAt(2 + offset), tok->tokAt(5 + offset)); } - else if (Token::Match(tok, ";|{|}|public:|protected:|private: const| %type% : %any% ;")) + else if (Token::Match(tok, ";|{|}|public:|protected:|private: const| %type% : %any% ;") && + tok->next()->str() != "default") { int offset = 0; if (tok->next()->str() == "const") diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 13d86cb28..02e75604d 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -5121,6 +5121,12 @@ private: const char code3[] = "struct A { bool : true; };"; ASSERT_EQUALS("struct A { } ;", tokenizeAndStringify(code3,false)); + + const char code4[] = "void f(int a) { switch (a) { case b: break; } }"; + ASSERT_EQUALS("void f ( int a ) { switch ( a ) { case b : ; break ; } }", tokenizeAndStringify(code4,true)); + + const char code5[] = "void f(int a) { switch (a) { default: break; } }"; + ASSERT_EQUALS("void f ( int a ) { switch ( a ) { default : ; break ; } }", tokenizeAndStringify(code5,true)); } void microsoftMFC()