Skip to content

Commit 66078d3

Browse files
Fix #14324 syntaxError for enum member declared as bitfield (#8027)
Co-authored-by: chrchr-github <[email protected]>
1 parent 575de99 commit 66078d3

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

lib/tokenize.cpp

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10089,17 +10089,7 @@ void Tokenizer::simplifyBitfields()
1008910089
if (!Token::Match(tok, ";|{|}|public:|protected:|private:"))
1009010090
continue;
1009110091

10092-
bool isEnum = false;
10093-
if (tok->str() == "}") {
10094-
const Token *type = tok->link()->previous();
10095-
while (type && type->isName()) {
10096-
if (type->str() == "enum") {
10097-
isEnum = true;
10098-
break;
10099-
}
10100-
type = type->previous();
10101-
}
10102-
}
10092+
const bool isEnum = tok->str() == "}" && isEnumStart(tok->link());
1010310093

1010410094
const auto tooLargeError = [this](const Token *tok) {
1010510095
const auto max = std::numeric_limits<short>::max();

test/testtokenize.cpp

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

49504964
void bitfields16() {

0 commit comments

Comments
 (0)