Skip to content

Commit

Permalink
Fix #12218: class and union (#5705)
Browse files Browse the repository at this point in the history
Co-authored-by: chrchr-github <chrchr@github>
  • Loading branch information
chrchr-github and chrchr-github committed Dec 1, 2023
1 parent 9dd729e commit e208226
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
27 changes: 27 additions & 0 deletions test/testsimplifytypedef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3454,6 +3454,33 @@ class TestSimplifyTypedef : public TestFixture {
" 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() {
Expand Down

0 comments on commit e208226

Please sign in to comment.