Skip to content

Commit

Permalink
fix Issue 6574 - Erroneous recursive call in template instantiation
Browse files Browse the repository at this point in the history
  • Loading branch information
9rnsr committed Jan 9, 2015
1 parent 6983006 commit fe6d7d7
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/template.c
Expand Up @@ -7199,6 +7199,7 @@ bool TemplateInstance::hasNestedArgs(Objects *args, bool isstatic)

Identifier *TemplateInstance::genIdent(Objects *args)
{
TemplateDeclaration *tempdecl = this->tempdecl->isTemplateDeclaration();
assert(tempdecl);

//printf("TemplateInstance::genIdent('%s')\n", tempdecl->ident->toChars());
Expand All @@ -7211,6 +7212,7 @@ Identifier *TemplateInstance::genIdent(Objects *args)
}
else
buf.printf("__T%llu%s", (ulonglong)strlen(id), id);
size_t nparams = tempdecl->parameters->dim - (tempdecl->isVariadic() ? 1 : 0);
for (size_t i = 0; i < args->dim; i++)
{
RootObject *o = (*args)[i];
Expand All @@ -7219,6 +7221,8 @@ Identifier *TemplateInstance::genIdent(Objects *args)
Dsymbol *sa = isDsymbol(o);
Tuple *va = isTuple(o);
//printf("\to [%d] %p ta %p ea %p sa %p va %p\n", i, o, ta, ea, sa, va);
if (i < nparams && (*tempdecl->parameters)[i]->specialization())
buf.writeByte('H'); // Bugzilla 6574
if (ta)
{
buf.writeByte('T');
Expand Down
45 changes: 45 additions & 0 deletions test/runnable/link6574.d
@@ -0,0 +1,45 @@
// PERMUTE_ARGS:
module link6574;

enum Method { A, B, }

int foo(Method method = Method.A)()
{
static assert(foo.mangleof == "_D8link657428__T3fooVE8link65746Methodi0Z3fooFZi");
return 10 * foo!method();
}
int foo(Method method : Method.A)()
{
static assert(foo.mangleof == "_D8link657429__T3fooHVE8link65746Methodi0Z3fooFZi");
return 2;
}
int foo(Method method : Method.B)()
{
static assert(0);
return 3;
}

int bar(Method method = Method.B)()
{
static assert(bar.mangleof == "_D8link657428__T3barVE8link65746Methodi1Z3barFZi");
return 10 * bar!method();
}
int bar(Method method : Method.A)()
{
static assert(0);
return 2;
}
int bar(Method method : Method.B)()
{
static assert(bar.mangleof == "_D8link657429__T3barHVE8link65746Methodi1Z3barFZi");
return 3;
}

void main()
{
assert(foo!() == 10 * 2);
assert(foo() == 10 * 2);

assert(bar!() == 10 * 3);
assert(bar() == 10 * 3);
}

0 comments on commit fe6d7d7

Please sign in to comment.