fix bitfields to support non-numeric bitfield width

This commit is contained in:
Robert Reif 2011-02-20 18:22:49 -05:00
parent bfe28d3b26
commit 763763fa9b
2 changed files with 15 additions and 2 deletions

View File

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

View File

@ -279,6 +279,7 @@ private:
TEST_CASE(bitfields3);
TEST_CASE(bitfields4); // ticket #1956
TEST_CASE(bitfields5); // ticket #1956
TEST_CASE(bitfields6); // ticket #2595
TEST_CASE(microsoftMFC);
@ -5083,6 +5084,18 @@ private:
ASSERT_EQUALS("struct A { virtual void f ( ) { } int f1 ; } ;", tokenizeAndStringify(code3,false));
}
void bitfields6() // ticket #2595
{
const char code1[] = "struct A { bool b : true; };";
ASSERT_EQUALS("struct A { bool b ; } ;", tokenizeAndStringify(code1,false));
const char code2[] = "struct A { bool b : true, c : true; };";
ASSERT_EQUALS("struct A { bool b ; bool c ; } ;", tokenizeAndStringify(code2,false));
const char code3[] = "struct A { bool : true; };";
ASSERT_EQUALS("struct A { } ;", tokenizeAndStringify(code3,false));
}
void microsoftMFC()
{
const char code1[] = "class MyDialog : public CDialog { DECLARE_MESSAGE_MAP() private: CString text; };";