Fix 10506: Hang: template alias (TemplateSimplfier) (#3466)

This commit is contained in:
Paul Fultz II 2021-09-25 04:56:39 -05:00 committed by GitHub
parent 5c3b69fe96
commit d1181ad8e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 2 deletions

View File

@ -2244,10 +2244,9 @@ void TemplateSimplifier::expandTemplate(
// add new instantiations
for (const auto & inst : newInstantiations) {
std::string fullName = inst.scope + (inst.scope.empty() ? "" : " :: ") + inst.token->str();
simplifyTemplateArgs(inst.token->tokAt(2), inst.token->next()->findClosingBracket());
// only add recursive instantiation if its arguments are a constant expression
if (templateDeclaration.fullName() != fullName ||
if (templateDeclaration.name() != inst.token->str() ||
(inst.token->tokAt(2)->isNumber() || inst.token->tokAt(2)->isStandardType()))
mTemplateInstantiations.emplace_back(inst.token, inst.scope);
}

View File

@ -214,6 +214,7 @@ private:
TEST_CASE(template171); // crash
TEST_CASE(template172); // #10258 crash
TEST_CASE(template173); // #10332 crash
TEST_CASE(template174); // #10506 hang
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)
@ -4439,6 +4440,19 @@ private:
ASSERT_EQUALS(exp, tok(code));
}
void template174()
{ // #10506 hang
const char code[] = "namespace a {\n"
"template <typename> using b = int;\n"
"template <typename c> c d() { return d<b<c>>(); }\n"
"}\n"
"void e() { a::d<int>(); }\n";
const char exp[] = "namespace a { int d<int> ( ) ; } "
"void e ( ) { a :: d<int> ( ) ; } "
"int a :: d<int> ( ) { return d < 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"