From e2082267e2a693084e46685aecf2c5cea3a3428b Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Fri, 1 Dec 2023 10:03:43 +0100 Subject: [PATCH] Fix #12218: class and union (#5705) Co-authored-by: chrchr-github --- lib/tokenize.cpp | 2 +- test/testsimplifytypedef.cpp | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 7358a088f..2d82e02cd 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -1947,7 +1947,7 @@ void Tokenizer::simplifyTypedefCpp() tok2->str(typeStart->str()); // restore qualification if it was removed - if (typeStart->str() == "struct" || structRemoved) { + if (Token::Match(typeStart, "class|struct|union") || structRemoved) { if (structRemoved) tok2 = tok2->previous(); diff --git a/test/testsimplifytypedef.cpp b/test/testsimplifytypedef.cpp index d321026a3..8d3f0bb88 100644 --- a/test/testsimplifytypedef.cpp +++ b/test/testsimplifytypedef.cpp @@ -3454,6 +3454,33 @@ private: " g(sizeof(struct N::S));\n" "}\n"; ASSERT_EQUALS("namespace N { struct S { } ; } void g ( int ) ; void f ( ) { g ( sizeof ( struct N :: S ) ) ; }", tok(code)); + + code = "namespace N {\n" + " typedef class C {} C;\n" + "}\n" + "void g(int);\n" + "void f() {\n" + " g(sizeof(class N::C));\n" + "}\n"; + ASSERT_EQUALS("namespace N { class C { } ; } void g ( int ) ; void f ( ) { g ( sizeof ( class N :: C ) ) ; }", tok(code)); + + code = "namespace N {\n" + " typedef union U {} U;\n" + "}\n" + "void g(int);\n" + "void f() {\n" + " g(sizeof(union N::U));\n" + "}\n"; + ASSERT_EQUALS("namespace N { union U { } ; } void g ( int ) ; void f ( ) { g ( sizeof ( union N :: U ) ) ; }", tok(code)); + + code = "namespace N {\n" + " typedef enum E {} E;\n" + "}\n" + "void g(int);\n" + "void f() {\n" + " g(sizeof(enum N::E));\n" + "}\n"; + ASSERT_EQUALS("namespace N { enum E { } ; } void g ( int ) ; void f ( ) { g ( sizeof ( enum N :: E ) ) ; }", tok(code)); } void simplifyTypedefFunction1() {