Skip to content

Commit 9ba7901

Browse files
committed
Fix #14324 syntaxError for enum member declared as bitfield
1 parent 602da94 commit 9ba7901

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
@@ -10080,14 +10080,7 @@ void Tokenizer::simplifyBitfields()
1008010080

1008110081
bool isEnum = false;
1008210082
if (tok->str() == "}") {
10083-
const Token *type = tok->link()->previous();
10084-
while (type && type->isName()) {
10085-
if (type->str() == "enum") {
10086-
isEnum = true;
10087-
break;
10088-
}
10089-
type = type->previous();
10090-
}
10083+
isEnum = isEnumStart(tok->link());
1009110084
}
1009210085

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

test/testtokenize.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4939,6 +4939,20 @@ class TestTokenizer : public TestFixture {
49394939
tokenizeAndStringify("struct AB {\n"
49404940
" enum Foo {A,B} foo : 4;\n"
49414941
"};"));
4942+
4943+
ASSERT_EQUALS("struct S {\n" // #14324
4944+
"enum E : int { E0 , E1 } ; enum E e ;\n"
4945+
"} ;",
4946+
tokenizeAndStringify("struct S {\n"
4947+
" enum E : int { E0, E1 } e : 2;\n"
4948+
"};\n"));
4949+
4950+
ASSERT_EQUALS("struct S {\n"
4951+
"enum class E : std :: uint8_t { E0 , E1 } ; enum E e ;\n"
4952+
"} ;",
4953+
tokenizeAndStringify("struct S {\n"
4954+
" enum class E : std::uint8_t { E0, E1 } e : 2;\n"
4955+
"};\n"));
49424956
}
49434957

49444958
void bitfields16() {

0 commit comments

Comments
 (0)