Skip to content

Commit

Permalink
Fix #12014 syntaxError due to bad typedef simplification (#5493)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Sep 28, 2023
1 parent 033cf64 commit 6773cdb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1849,6 +1849,7 @@ void Tokenizer::simplifyTypedefCpp()
}

simplifyType = simplifyType && (!inEnumClass || Token::simpleMatch(tok2->previous(), "="));
simplifyType = simplifyType && !(Token::simpleMatch(tok2->next(), "<") && Token::simpleMatch(typeEnd, ">"));

if (simplifyType) {
mTypedefInfo.back().used = true;
Expand Down
20 changes: 20 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(simplifyTypedef144); // #9353
TEST_CASE(simplifyTypedef145); // #9353
TEST_CASE(simplifyTypedef146);
TEST_CASE(simplifyTypedef147);

TEST_CASE(simplifyTypedefFunction1);
TEST_CASE(simplifyTypedefFunction2); // ticket #1685
Expand Down Expand Up @@ -3397,6 +3398,25 @@ class TestSimplifyTypedef : public TestFixture {
ASSERT_EQUALS("namespace N { struct S { } ; struct T { void f ( int * ) ; } ; } void N :: T :: f ( int * ) { }", tok(code));
}

void simplifyTypedef147() {
const char* code{};
code = "namespace N {\n" // #12014
" template<typename T>\n"
" struct S {};\n"
"}\n"
"typedef N::S<int> S;\n"
"namespace N {\n"
" template<typename T>\n"
" struct U {\n"
" S<T> operator()() {\n"
" return {};\n"
" }\n"
" };\n"
"}\n";
ASSERT_EQUALS("namespace N { template < typename T > struct S { } ; } namespace N { template < typename T > struct U { S < T > operator() ( ) { return { } ; } } ; }",
tok(code));
}

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

0 comments on commit 6773cdb

Please sign in to comment.