Skip to content

Commit

Permalink
fix Issue 6356 - Pure/nothrow/@safe-inference failed for a template f…
Browse files Browse the repository at this point in the history
…unction if it is instantiated without evaluating at the global scope
  • Loading branch information
9rnsr committed Nov 3, 2012
1 parent 0c86463 commit 0c074ce
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/expression.c
Original file line number Diff line number Diff line change
Expand Up @@ -974,7 +974,7 @@ Type *functionParameters(Loc loc, Scope *sc, TypeFunction *tf,
t = t->semantic(loc, sc);
bool isSafe = fd ? fd->isSafe() : tf->trust == TRUSTsafe;
VarDeclaration *v = new VarDeclaration(loc, t, id,
isSafe ? NULL : new VoidInitializer(loc));
(isSafe && sc->func) ? NULL : new VoidInitializer(loc));
v->storage_class |= STCctfe;
v->semantic(sc);
v->parent = sc->parent;
Expand Down
10 changes: 10 additions & 0 deletions src/template.c
Original file line number Diff line number Diff line change
Expand Up @@ -2162,6 +2162,16 @@ FuncDeclaration *TemplateDeclaration::deduceFunctionTemplate(Scope *sc, Loc loc,
if (tf->next)
fd_best->type = tf->semantic(loc, sc);
}
if (fd_best->scope)
{
TemplateInstance *spec = fd_best->isSpeculative();
int olderrs = global.errors;
fd_best->semantic3(fd_best->scope);
// Update the template instantiation with the number
// of errors which occured.
if (spec && global.errors != olderrs)
spec->errors = global.errors - olderrs;
}

return fd_best;

Expand Down
21 changes: 21 additions & 0 deletions test/runnable/xtest46.d
Original file line number Diff line number Diff line change
Expand Up @@ -4769,6 +4769,26 @@ void test6056()
bar6056(&foo6056);
}

/***************************************************/
// 6356

int f6356()(int a)
{
return a*a;
}

alias f6356!() g6356; // comment this out to eliminate the errors

pure nothrow @safe int i6356()
{
return f6356(1);
}

void test6356()
{
assert(i6356() == 1);
}

/***************************************************/
// 7108

Expand Down Expand Up @@ -5701,6 +5721,7 @@ int main()
test2856();
test3091();
test6056();
test6356();
test7073();
test7150();
test7160();
Expand Down

0 comments on commit 0c074ce

Please sign in to comment.