Fix #9224 (Performance regression in template parsing: 250x - 1200x slower) (#2046)

This commit is contained in:
IOBYTE 2019-07-28 03:25:18 -04:00 committed by Daniel Marjamäki
parent f7f60a8da6
commit badc573b80
2 changed files with 17 additions and 0 deletions

View File

@ -2872,6 +2872,10 @@ bool TemplateSimplifier::simplifyTemplateInstantiations(
continue;
}
// A global function can't be called through a pointer.
if (templateDeclaration.isFunction() && templateDeclaration.scope.empty() && instantiation.token->strAt(-1) == ".")
continue;
if (!matchSpecialization(templateDeclaration.nameToken, instantiation.token, specializations))
continue;

View File

@ -165,6 +165,7 @@ private:
TEST_CASE(template125);
TEST_CASE(template126); // #9217
TEST_CASE(template127); // #9225
TEST_CASE(template128); // #9224
TEST_CASE(template_specialization_1); // #7868 - template specialization template <typename T> struct S<C<T>> {..};
TEST_CASE(template_specialization_2); // #7868 - template specialization template <typename T> struct S<C<T>> {..};
TEST_CASE(template_enum); // #6299 Syntax error in complex enum declaration (including template)
@ -3034,6 +3035,18 @@ private:
}
}
void template128() { // #9224
const char code[] = "template <typename> struct a { };\n"
"template <typename j> void h() { k.h<a<j>>; }\n"
"void foo() { h<int>(); }";
const char exp[] = "struct a<int> ; "
"void h<int> ( ) ; "
"void foo ( ) { h<int> ( ) ; } "
"void h<int> ( ) { k . h < a<int> > ; } "
"struct a<int> { } ;";
ASSERT_EQUALS(exp, tok(code));
}
void template_specialization_1() { // #7868 - template specialization template <typename T> struct S<C<T>> {..};
const char code[] = "template <typename T> struct C {};\n"
"template <typename T> struct S {a};\n"