Fix #12014 syntaxError due to bad typedef simplification (#5493)

This commit is contained in:
chrchr-github 2023-09-28 19:26:12 +02:00 committed by GitHub
parent 033cf64961
commit 6773cdb34b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 0 deletions

View File

@ -1849,6 +1849,7 @@ void Tokenizer::simplifyTypedefCpp()
} }
simplifyType = simplifyType && (!inEnumClass || Token::simpleMatch(tok2->previous(), "=")); simplifyType = simplifyType && (!inEnumClass || Token::simpleMatch(tok2->previous(), "="));
simplifyType = simplifyType && !(Token::simpleMatch(tok2->next(), "<") && Token::simpleMatch(typeEnd, ">"));
if (simplifyType) { if (simplifyType) {
mTypedefInfo.back().used = true; mTypedefInfo.back().used = true;

View File

@ -212,6 +212,7 @@ private:
TEST_CASE(simplifyTypedef144); // #9353 TEST_CASE(simplifyTypedef144); // #9353
TEST_CASE(simplifyTypedef145); // #9353 TEST_CASE(simplifyTypedef145); // #9353
TEST_CASE(simplifyTypedef146); TEST_CASE(simplifyTypedef146);
TEST_CASE(simplifyTypedef147);
TEST_CASE(simplifyTypedefFunction1); TEST_CASE(simplifyTypedefFunction1);
TEST_CASE(simplifyTypedefFunction2); // ticket #1685 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)); 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() { void simplifyTypedefFunction1() {
{ {
const char code[] = "typedef void (*my_func)();\n" const char code[] = "typedef void (*my_func)();\n"