Fix #12218: class and union (#5705)

Co-authored-by: chrchr-github <chrchr@github>
This commit is contained in:
chrchr-github 2023-12-01 10:03:43 +01:00 committed by GitHub
parent 9dd729e9be
commit e2082267e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 1 deletions

View File

@ -1947,7 +1947,7 @@ void Tokenizer::simplifyTypedefCpp()
tok2->str(typeStart->str()); tok2->str(typeStart->str());
// restore qualification if it was removed // restore qualification if it was removed
if (typeStart->str() == "struct" || structRemoved) { if (Token::Match(typeStart, "class|struct|union") || structRemoved) {
if (structRemoved) if (structRemoved)
tok2 = tok2->previous(); tok2 = tok2->previous();

View File

@ -3454,6 +3454,33 @@ private:
" g(sizeof(struct N::S));\n" " g(sizeof(struct N::S));\n"
"}\n"; "}\n";
ASSERT_EQUALS("namespace N { struct S { } ; } void g ( int ) ; void f ( ) { g ( sizeof ( struct N :: S ) ) ; }", tok(code)); 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() { void simplifyTypedefFunction1() {