Skip to content

Commit ef92f3f

Browse files
authored
Fix #14170 (Bitfields may be followed by comma) (danmar#7865)
1 parent c8a7ab8 commit ef92f3f

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/tokenize.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10055,7 +10055,7 @@ void Tokenizer::simplifyBitfields()
1005510055
!Token::Match(tok->next(), "case|public|protected|private|class|struct") &&
1005610056
!Token::simpleMatch(tok->tokAt(2), "default :")) {
1005710057
Token *tok1 = typeTok->next();
10058-
if (Token::Match(tok1, "%name% : %num% [;=]"))
10058+
if (Token::Match(tok1, "%name% : %num% [;=,]"))
1005910059
if (!tok1->setBits(MathLib::toBigNumber(tok1->tokAt(2))))
1006010060
tooLargeError(tok1->tokAt(2));
1006110061
if (tok1 && tok1->tokAt(2) &&

test/testtokenize.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ class TestTokenizer : public TestFixture {
310310
TEST_CASE(bitfields18);
311311
TEST_CASE(bitfields19); // ticket #13733
312312
TEST_CASE(bitfields20);
313+
TEST_CASE(bitfields21);
313314

314315
TEST_CASE(simplifyNamespaceStd);
315316

@@ -4899,6 +4900,16 @@ class TestTokenizer : public TestFixture {
48994900
ASSERT_EQUALS("struct S { volatile :: uint32_t a ; } ;", tokenizeAndStringify(code));
49004901
}
49014902

4903+
void bitfields21() {
4904+
const char code[] = "struct S { uint32_t a : 1, b : 1; };";
4905+
SimpleTokenizer tokenizer(settings0, *this);
4906+
ASSERT(tokenizer.tokenize(code));
4907+
const Token *a = Token::findsimplematch(tokenizer.tokens(), "a");
4908+
ASSERT_EQUALS(1, a->bits());
4909+
const Token *b = Token::findsimplematch(tokenizer.tokens(), "b");
4910+
ASSERT_EQUALS(1, b->bits());
4911+
}
4912+
49024913
void simplifyNamespaceStd() {
49034914
const char *expected;
49044915

0 commit comments

Comments
 (0)