Skip to content

Commit

Permalink
fix Issue 14834 - dirEntries with mask stopped working with "-inline …
Browse files Browse the repository at this point in the history
…-debug"
  • Loading branch information
9rnsr committed Jul 27, 2015
1 parent 3a8dc47 commit e5e0c3e
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/template.c
Expand Up @@ -7864,14 +7864,28 @@ bool TemplateInstance::needsCodegen()
//printf("%s minst = %s, enclosing (%s)->isNonRoot = %d\n",
// toPrettyChars(), minst ? minst->toChars() : NULL,
// enclosing ? enclosing->toPrettyChars() : NULL, enclosing && enclosing->inNonRoot());
if (enclosing && !tinst)
if (enclosing)
{
// Bugzilla 13415: If and only if the enclosing scope needs codegen,
// the nested templates would need code generation.
// Bugzilla 14588: If the captured context is not a function
// (e.g. class), the instance layout determination is guaranteed,
// because the semantic/semantic2 pass will be executed
// even for non-root instances.
if (!enclosing->isFuncDeclaration())
return true;

// Bugzilla 14834: If the captured context is a function,
// this excessive instantiation may cause ODR violation, because
// -allInst and others doesn't guarantee the semantic3 execution
// for that function.

// If the enclosing is also an instantiated function,
// we have to rely on the ancestor's needsCodegen() result.
if (TemplateInstance *ti = enclosing->isInstantiated())
return ti->needsCodegen();
else
return !enclosing->inNonRoot();

// Bugzilla 13415: If and only if the enclosing scope needs codegen,
// this nested templates would also need code generation.
return !enclosing->inNonRoot();
}
return true;
}
Expand Down
57 changes: 57 additions & 0 deletions test/runnable/extra-files/link14834a.d
@@ -0,0 +1,57 @@
module link14834a;

struct DirIterator
{
int i = 1;

@property bool empty() { return i == 0; }
@property int front() { return 10; }
void popFront() { --i; }
}

auto dirEntries(string path)
{
bool f(int x)
{
assert(path == "."); // should pass
return true;
}
return filter!f(DirIterator());
}

template filter(alias pred)
{
auto filter(R)(R range)
{
return FilterResult!(pred, R)(range);
}
}

struct FilterResult(alias pred, R)
{
R input;

this(R r)
{
input = r;
while (!input.empty && !pred(input.front))
{
input.popFront();
}
}

@property bool empty() { return input.empty; }

@property auto ref front()
{
return input.front;
}

void popFront()
{
do
{
input.popFront();
} while (!input.empty && !pred(input.front));
}
}
9 changes: 9 additions & 0 deletions test/runnable/extra-files/link14834b.d
@@ -0,0 +1,9 @@
import link14834a;

void main()
{
foreach (n; dirEntries("."))
{
assert(n == 10);
}
}

0 comments on commit e5e0c3e

Please sign in to comment.