Skip to content

Commit

Permalink
Merge pull request #3840 from 9rnsr/fix13225
Browse files Browse the repository at this point in the history
Issue 13225 - [ICE] Access violation on invalid mixin template instantiation
  • Loading branch information
WalterBright authored and 9rnsr committed Aug 6, 2014
1 parent 6c6db06 commit 5f95454
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 18 deletions.
6 changes: 6 additions & 0 deletions src/func.c
Original file line number Diff line number Diff line change
Expand Up @@ -4492,6 +4492,12 @@ const char *FuncLiteralDeclaration::kind()

void FuncLiteralDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
{
if (type->ty == Terror)
{
buf->writestring("__error");
return;
}

if (tok != TOKreserved)
{
buf->writestring(kind());
Expand Down
6 changes: 4 additions & 2 deletions src/mtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -9609,11 +9609,13 @@ int Parameter::foreach(Parameters *args, Parameter::ForeachDg dg, void *ctx, siz
size_t n = pn ? *pn : 0; // take over index
int result = 0;
for (size_t i = 0; i < args->dim; i++)
{ Parameter *arg = (*args)[i];
{
Parameter *arg = (*args)[i];
Type *t = arg->type->toBasetype();

if (t->ty == Ttuple)
{ TypeTuple *tu = (TypeTuple *)t;
{
TypeTuple *tu = (TypeTuple *)t;
result = foreach(tu->arguments, dg, ctx, &n);
}
else
Expand Down
22 changes: 6 additions & 16 deletions src/template.c
Original file line number Diff line number Diff line change
Expand Up @@ -8075,24 +8075,15 @@ void TemplateMixin::semantic(Scope *sc)
#endif
if (semanticRun != PASSinit)
{
// This for when a class/struct contains mixin members, and
// is done over because of forward references
if (parent && toParent()->isAggregateDeclaration())
{
if (sc->parent != parent)
return;
semanticRun = PASSsemantic; // do over
}
else
{
// When a class/struct contains mixin members, and is done over
// because of forward references, never reach here so semanticRun
// has been reset to PASSinit.
#if LOG
printf("\tsemantic done\n");
printf("\tsemantic done\n");
#endif
return;
}
return;
}
if (semanticRun == PASSinit)
semanticRun = PASSsemantic;
semanticRun = PASSsemantic;
#if LOG
printf("\tdo semantic\n");
#endif
Expand All @@ -8105,7 +8096,6 @@ void TemplateMixin::semantic(Scope *sc)
scope = NULL;
}


/* Run semantic on each argument, place results in tiargs[],
* then find best match template with tiargs
*/
Expand Down
5 changes: 5 additions & 0 deletions test/compilable/ice13245.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// REQUIRED_ARGS: -o-
// PERMUTE_ARGS:

template T(alias f) {}
static assert(!is(T!( (int x){ return invalid; } )));
14 changes: 14 additions & 0 deletions test/fail_compilation/ice13225.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
TEST_OUTPUT:
---
fail_compilation/ice13225.d(13): Error: undefined identifier undefined
---
*/

mixin template M(T) {}

struct S
{
mixin M!((typeof(this)) => 0);
mixin M!(() => undefined);
}

0 comments on commit 5f95454

Please sign in to comment.