Skip to content

Commit

Permalink
fix Issue 15021 - linker error with speculative instantiation and -in…
Browse files Browse the repository at this point in the history
…line
  • Loading branch information
9rnsr committed Sep 8, 2015
1 parent c9c12bf commit 61f79a8
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/inline.c
Original file line number Diff line number Diff line change
Expand Up @@ -1896,9 +1896,9 @@ static Expression *expandInline(FuncDeclaration *fd, FuncDeclaration *parent,
// When the function is actually expanded
if (TemplateInstance *ti = fd->isInstantiated())
{
// change ti to non-speculative instance
// change ti to non-speculative root instance
if (!ti->minst)
ti->minst = ti->tempdecl->getModule();
ti->minst = ti->tempdecl->getModule()->importedFrom;
}

if (ps)
Expand Down
13 changes: 13 additions & 0 deletions src/template.c
Original file line number Diff line number Diff line change
Expand Up @@ -7949,6 +7949,19 @@ bool TemplateInstance::needsCodegen()
return false;
}

/* Even when this is reached to the codegen pass,
* a non-root nested template should not generate code,
* due to avoid ODR violation.
*/
if (enclosing && enclosing->inNonRoot())
{
if (tinst)
return tinst->needsCodegen();
if (tnext)
return tnext->needsCodegen();
return false;
}

/* The issue is that if the importee is compiled with a different -debug
* setting than the importer, the importer may believe it exists
* in the compiled importee when it does not, when the instantiation
Expand Down
13 changes: 13 additions & 0 deletions test/runnable/imports/std15021conv.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module imports.std15021conv;

T to(T, A...)(A args)
{
return toImpl!T(args);
}

T toImpl(T, S)(S value)
{
import imports.std15021format;
enforceValidFormatSpec!(S, char)('c');
return "";
}
12 changes: 12 additions & 0 deletions test/runnable/imports/std15021format.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module imports.std15021format;

T enforceEx(T)(T value, lazy string msg = "")
{
if (!value) throw new Exception(msg);
return value;
}

void enforceValidFormatSpec(T, Char)(int spec)
{
enforceEx(spec == 's');
}
18 changes: 18 additions & 0 deletions test/runnable/link15021.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// PERMUTE_ARGS: -inline -g -debug -unittest

import imports.std15021conv;

class AliasDecl {}

void aliasDecl(AliasDecl ad)
{
AliasDecl* zis;

static if (is(typeof(to!string(*zis))))
{
pragma(msg, "hit!");
to!string(*zis);
}
}

void main() {}

0 comments on commit 61f79a8

Please sign in to comment.