Skip to content

Commit e713082

Browse files
committed
Fix #14324 syntaxError for enum member declared as bitfield
1 parent 27282f2 commit e713082

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

lib/tokenize.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10087,14 +10087,7 @@ void Tokenizer::simplifyBitfields()
1008710087

1008810088
bool isEnum = false;
1008910089
if (tok->str() == "}") {
10090-
const Token *type = tok->link()->previous();
10091-
while (type && type->isName()) {
10092-
if (type->str() == "enum") {
10093-
isEnum = true;
10094-
break;
10095-
}
10096-
type = type->previous();
10097-
}
10090+
isEnum = isEnumStart(tok->link());
1009810091
}
1009910092

1010010093
const auto tooLargeError = [this](const Token *tok) {

test/testtokenize.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4943,6 +4943,20 @@ class TestTokenizer : public TestFixture {
49434943
tokenizeAndStringify("struct AB {\n"
49444944
" enum Foo {A,B} foo : 4;\n"
49454945
"};"));
4946+
4947+
ASSERT_EQUALS("struct S {\n" // #14324
4948+
"enum E : int { E0 , E1 } ; enum E e ;\n"
4949+
"} ;",
4950+
tokenizeAndStringify("struct S {\n"
4951+
" enum E : int { E0, E1 } e : 2;\n"
4952+
"};\n"));
4953+
4954+
ASSERT_EQUALS("struct S {\n"
4955+
"enum class E : std :: uint8_t { E0 , E1 } ; enum E e ;\n"
4956+
"} ;",
4957+
tokenizeAndStringify("struct S {\n"
4958+
" enum class E : std::uint8_t { E0, E1 } e : 2;\n"
4959+
"};\n"));
49464960
}
49474961

49484962
void bitfields16() {

0 commit comments

Comments
 (0)