From bda9f707cc0cefc2fc686f6b9ec9d0d9fe3998b7 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Fri, 21 Apr 2023 18:58:44 +0200 Subject: [PATCH] Fix typedef in enum class (#4998) --- lib/tokenize.cpp | 2 +- test/testsimplifytypedef.cpp | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 7e485f859..f9a9d9603 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -1802,7 +1802,7 @@ void Tokenizer::simplifyTypedefCpp() } } - simplifyType = simplifyType && !inEnumClass; + simplifyType = simplifyType && (!inEnumClass || Token::simpleMatch(tok2->previous(), "=")); if (simplifyType) { mTypedefInfo.back().used = true; diff --git a/test/testsimplifytypedef.cpp b/test/testsimplifytypedef.cpp index 4e9b95915..fc33210c6 100644 --- a/test/testsimplifytypedef.cpp +++ b/test/testsimplifytypedef.cpp @@ -3224,6 +3224,14 @@ private: "enum class E { A };\n"; ASSERT_EQUALS("enum class E { A } ;", tok(code)); } + { + const char code[] = "namespace N {\n" + " struct S { enum E { E0 }; };\n" + "}\n" + "typedef N::S T;\n" + "enum class E { a = T::E0; };\n"; + ASSERT_EQUALS("namespace N { struct S { enum E { E0 } ; } ; } enum class E { a = N :: S :: E0 ; } ;", tok(code)); + } { // #11494 const char code[] = "typedef struct S {} KEY;\n" "class C { enum E { KEY }; };\n";