From 763763fa9bc408fb150ac8f91c16aa06e452183b Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Sun, 20 Feb 2011 18:22:49 -0500 Subject: [PATCH] fix bitfields to support non-numeric bitfield width --- lib/tokenize.cpp | 4 ++-- test/testtokenize.cpp | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 868184a60..e718fb5e9 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -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") diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 02177d4bf..7b35ea570 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -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; };";