From dc0dfea0799027051a53576136de6b0b66c9bb09 Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Mon, 21 Mar 2011 20:17:14 -0400 Subject: [PATCH] fix invalid bitfield match and simplification that created invalid code --- lib/tokenize.cpp | 2 +- test/testtokenize.cpp | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index f630a4c0a..b4badf102 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -9316,7 +9316,7 @@ void Tokenizer::simplifyBitfields() Token *last = 0; if (Token::Match(tok, ";|{|}|public:|protected:|private: const| %type% %var% :") && - !Token::Match(tok->next(), "case|public|protected|private")) + !Token::Match(tok->next(), "case|public|protected|private|class|struct")) { int offset = 0; if (tok->next()->str() == "const") diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 5406b6bf6..e0ded16e9 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -291,6 +291,7 @@ private: TEST_CASE(bitfields5); // ticket #1956 TEST_CASE(bitfields6); // ticket #2595 TEST_CASE(bitfields7); // ticket #1987 + TEST_CASE(bitfields8); TEST_CASE(microsoftMFC); @@ -5300,6 +5301,22 @@ private: ASSERT_EQUALS("", errout.str()); } + void bitfields8() + { + const char code[] = "struct A;" + "class B : virtual public C" + "{" + " int f();" + "};"; + const char expected[] = "struct A ; " + "class B : virtual public C " + "{ " + "int f ( ) ; " + "} ;"; + ASSERT_EQUALS(expected, tokenizeAndStringify(code,false)); + ASSERT_EQUALS("", errout.str()); + } + void microsoftMFC() { const char code1[] = "class MyDialog : public CDialog { DECLARE_MESSAGE_MAP() private: CString text; };";