From 92efbd748ee08a48b451f8b09c8f2a60677f3736 Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Mon, 28 Feb 2011 19:35:00 -0500 Subject: [PATCH] fix #2595 bitfield fix for case x: break; and default: break; --- lib/tokenize.cpp | 6 ++++-- test/testtokenize.cpp | 6 ++++++ 2 files changed, 10 insertions(+), 2 deletions(-) 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()