Skip to content

Commit

Permalink
fix Issue 10920 - template instantiation order dependent link failure…
Browse files Browse the repository at this point in the history
… problem
  • Loading branch information
9rnsr committed Feb 5, 2015
1 parent 5ba4026 commit 0b69523
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/template.c
Original file line number Diff line number Diff line change
Expand Up @@ -5690,6 +5690,12 @@ void TemplateInstance::semantic(Scope *sc, Expressions *fargs)

// Get the instantiating module from the scope minst
minst = sc->minst;
// Bugzilla 10920: If the enclosing function is non-root symbol,
// this instance should be speculative.
if (!tinst && sc->func && !sc->func->isInstantiated() && sc->func->inNonRoot())
{
minst = NULL;
}

gagged = (global.gag > 0);

Expand Down
19 changes: 19 additions & 0 deletions test/runnable/imports/link10920a.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module imports.link10920a;

struct FormatSpec(C)
{
void func() {}
}

struct BitArray
{
auto toString()
{
// An auto function may runs semantic3 to calculate return type,
// even if it's non-root symbol.
// But inside the function body, all instantiations should be treated
// as speculative.
FormatSpec!char fs;
fs.func();
}
}
19 changes: 19 additions & 0 deletions test/runnable/link10920.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// PERMUTE_ARGS: -version=A

// It's imported but won't be linked.
import imports.link10920a;

void main()
{
BitArray ba;
version(A)
{
// Run semantic3 of BitArray.toString()
// before the FormatSpec instantiation in main().
pragma(msg, typeof(ba.toString()));
}

// The instance codegen should be run always, unrelated with -version=A.
FormatSpec!char fs;
fs.func();
}

0 comments on commit 0b69523

Please sign in to comment.