From 7f62d8ff98f9ee0b2b29f99a5119f1e8d844dab7 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 2 Mar 2023 21:17:39 +0100 Subject: [PATCH] Fix #11594 internalAstError with immediately instantiated enum (#4841) --- lib/tokenize.cpp | 2 +- test/testsimplifytokens.cpp | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 8b369747b..2bcaaca95 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -8059,7 +8059,7 @@ void Tokenizer::simplifyStructDecl() } if (isEnum) { - if (tok->next()->str() == "{") { + if (tok->next()->str() == "{" && tok->next()->link() != tok->tokAt(2)) { tok->next()->str("("); tok->linkAt(1)->str(")"); } diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 8eefc0bd2..e27db6e65 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -2584,9 +2584,16 @@ private: void simplifyVarDeclInitLists() { - const char code[] = "std::vector v{a * b, 1};"; - const char exp[] = "std :: vector < int > v { a * b , 1 } ;"; - ASSERT_EQUALS(exp, tok(code)); + { + const char code[] = "std::vector v{a * b, 1};"; + const char exp[] = "std :: vector < int > v { a * b , 1 } ;"; + ASSERT_EQUALS(exp, tok(code)); + } + { + const char code[] = "enum E { E0 } e{};"; + const char exp[] = "enum E { E0 } ; enum E e ; e = { } ;"; + ASSERT_EQUALS(exp, tok(code)); + } } };