Skip to content

Commit

Permalink
Merge pull request #3993 from klickverbot/2.066
Browse files Browse the repository at this point in the history
Fix Issue 13478 - [REG2.066] Templates not emitted when also referenced in speculative contexts
  • Loading branch information
9rnsr committed Sep 15, 2014
2 parents 9ca87d2 + 972c90f commit 0acbd54
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/template.c
Expand Up @@ -6259,8 +6259,13 @@ void TemplateInstance::semantic(Scope *sc, Expressions *fargs)
#if LOG
printf("\tit's a match with instance %p, %d\n", inst, inst->semanticRun);
#endif
if (!inst->instantiatingModule || inst->instantiatingModule->isRoot())
// If this is not a speculative instantiation, it might allow us to
// elide codegen for the template instance.
if (!speculative &&
(!inst->instantiatingModule || inst->instantiatingModule->isRoot()))
{
inst->instantiatingModule = mi;
}
errors = inst->errors;
return;
}
Expand Down
8 changes: 8 additions & 0 deletions test/runnable/imports/template13478a.d
@@ -0,0 +1,8 @@
module imports.template13478a;

bool foo(T)() {
// Make sure this is not inlined so template13478.o actually
// needs to reference it.
asm { nop; }
return false;
}
7 changes: 7 additions & 0 deletions test/runnable/imports/template13478b.d
@@ -0,0 +1,7 @@
import imports.template13478b;

import imports.template13478a;

// Note that foo is only used in the template constraint here.
T barImpl(T)(T t) if (is(typeof({ foo!T(); }))) { return t; }
int bar(int a) { return barImpl(a); }
10 changes: 10 additions & 0 deletions test/runnable/template13478.d
@@ -0,0 +1,10 @@
/// Tests emission of templates also referenced in speculative contexts.
/// Failure triggered with -inline.
module template13478;

import imports.template13478a;
import imports.template13478b;

int main() {
return foo!int();
}

0 comments on commit 0acbd54

Please sign in to comment.