fix invalid bitfield match and simplification that created invalid code

This commit is contained in:
Robert Reif 2011-03-21 20:17:14 -04:00
parent 15fc071514
commit dc0dfea079
2 changed files with 18 additions and 1 deletions

View File

@ -9316,7 +9316,7 @@ void Tokenizer::simplifyBitfields()
Token *last = 0; Token *last = 0;
if (Token::Match(tok, ";|{|}|public:|protected:|private: const| %type% %var% :") && 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; int offset = 0;
if (tok->next()->str() == "const") if (tok->next()->str() == "const")

View File

@ -291,6 +291,7 @@ private:
TEST_CASE(bitfields5); // ticket #1956 TEST_CASE(bitfields5); // ticket #1956
TEST_CASE(bitfields6); // ticket #2595 TEST_CASE(bitfields6); // ticket #2595
TEST_CASE(bitfields7); // ticket #1987 TEST_CASE(bitfields7); // ticket #1987
TEST_CASE(bitfields8);
TEST_CASE(microsoftMFC); TEST_CASE(microsoftMFC);
@ -5300,6 +5301,22 @@ private:
ASSERT_EQUALS("", errout.str()); 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() void microsoftMFC()
{ {
const char code1[] = "class MyDialog : public CDialog { DECLARE_MESSAGE_MAP() private: CString text; };"; const char code1[] = "class MyDialog : public CDialog { DECLARE_MESSAGE_MAP() private: CString text; };";