From 6773cdb34bb4697a41c4438ebb2a34c4e4de4b69 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 28 Sep 2023 19:26:12 +0200 Subject: [PATCH] Fix #12014 syntaxError due to bad typedef simplification (#5493) --- lib/tokenize.cpp | 1 + test/testsimplifytypedef.cpp | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 84b105221..818de8a08 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -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; diff --git a/test/testsimplifytypedef.cpp b/test/testsimplifytypedef.cpp index b568d59c2..6ca82db5b 100644 --- a/test/testsimplifytypedef.cpp +++ b/test/testsimplifytypedef.cpp @@ -212,6 +212,7 @@ private: TEST_CASE(simplifyTypedef144); // #9353 TEST_CASE(simplifyTypedef145); // #9353 TEST_CASE(simplifyTypedef146); + TEST_CASE(simplifyTypedef147); TEST_CASE(simplifyTypedefFunction1); TEST_CASE(simplifyTypedefFunction2); // ticket #1685 @@ -3397,6 +3398,25 @@ private: 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\n" + " struct S {};\n" + "}\n" + "typedef N::S S;\n" + "namespace N {\n" + " template\n" + " struct U {\n" + " S 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"