diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index c69e73d03be..a4c5ce7829b 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -10078,17 +10078,7 @@ void Tokenizer::simplifyBitfields() if (!Token::Match(tok, ";|{|}|public:|protected:|private:")) continue; - bool isEnum = false; - if (tok->str() == "}") { - const Token *type = tok->link()->previous(); - while (type && type->isName()) { - if (type->str() == "enum") { - isEnum = true; - break; - } - type = type->previous(); - } - } + const bool isEnum = tok->str() == "}" && isEnumStart(tok->link()); const auto tooLargeError = [this](const Token *tok) { const auto max = std::numeric_limits::max(); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 45df39a4557..3ddb5d20515 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -4939,6 +4939,20 @@ class TestTokenizer : public TestFixture { tokenizeAndStringify("struct AB {\n" " enum Foo {A,B} foo : 4;\n" "};")); + + ASSERT_EQUALS("struct S {\n" // #14324 + "enum E : int { E0 , E1 } ; enum E e ;\n" + "} ;", + tokenizeAndStringify("struct S {\n" + " enum E : int { E0, E1 } e : 2;\n" + "};\n")); + + ASSERT_EQUALS("struct S {\n" + "enum class E : std :: uint8_t { E0 , E1 } ; enum E e ;\n" + "} ;", + tokenizeAndStringify("struct S {\n" + " enum class E : std::uint8_t { E0, E1 } e : 2;\n" + "};\n")); } void bitfields16() {