Skip to content

Commit

Permalink
Fix #12218 syntaxError with typedef in namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Nov 22, 2023
1 parent 83b5cb5 commit 78b3295
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1945,6 +1945,8 @@ void Tokenizer::simplifyTypedefCpp()
tok2 = tok2->next();
tok2->next()->insertToken("0");
}
if (Token::Match(tok2->tokAt(-1), "class|struct|union") && tok2->strAt(-1) == typeStart->str())
tok2->deletePrevious();
tok2->str(typeStart->str());

// restore qualification if it was removed
Expand Down
13 changes: 13 additions & 0 deletions test/testsimplifytypedef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ class TestSimplifyTypedef : public TestFixture {
TEST_CASE(simplifyTypedef146);
TEST_CASE(simplifyTypedef147);
TEST_CASE(simplifyTypedef148);
TEST_CASE(simplifyTypedef149);

TEST_CASE(simplifyTypedefFunction1);
TEST_CASE(simplifyTypedefFunction2); // ticket #1685
Expand Down Expand Up @@ -3443,6 +3444,18 @@ class TestSimplifyTypedef : public TestFixture {
ASSERT_EQUALS("int & r = i ;", tok(code));
}

void simplifyTypedef149() { // #12218
const char* code{};
code = "namespace N {\n"
" typedef struct S {} S;\n"
"}\n"
"void g(int);\n"
"void f() {\n"
" 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));
}

void simplifyTypedefFunction1() {
{
const char code[] = "typedef void (*my_func)();\n"
Expand Down

0 comments on commit 78b3295

Please sign in to comment.