Skip to content

Commit

Permalink
Fix Issue 21927 - ICE (illegal instruction) with static foreach over …
Browse files Browse the repository at this point in the history
…empty member template
  • Loading branch information
BorisCarvajal committed May 21, 2021
1 parent 4ce4209 commit 96d3885
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/dmd/dinterpret.d
Expand Up @@ -71,6 +71,10 @@ public Expression ctfeInterpret(Expression e)
case TOK.super_:
case TOK.type:
case TOK.typeid_:
case TOK.template_: // non-eponymous template/instance
case TOK.scope_: // ditto
case TOK.dotTemplateDeclaration: // ditto, e.e1 doesn't matter here
case TOK.dot: // ditto
if (e.type.ty == Terror)
return ErrorExp.get();
goto case TOK.error;
Expand Down
30 changes: 30 additions & 0 deletions test/compilable/interpret5.d
@@ -0,0 +1,30 @@
// https://issues.dlang.org/show_bug.cgi?id=21927
/*
TEST_OUTPUT:
---
T1(Args...)
T1!()
T2(Args2...)
T2!()
this.T2(Args2...)
this.T2!()
---
*/
template T1(Args...) {}

pragma(msg, T1); // TOK.template_
pragma(msg, T1!()); // TOK.scope_

struct S
{
template T2(Args2...) {}

pragma(msg, S.T2); // TOK.template_
pragma(msg, S.T2!()); // TOK.scope_

void fun()
{
pragma(msg, this.T2); // TOK.dotTemplateDeclaration
pragma(msg, this.T2!()); // TOK.dot
}
}
22 changes: 22 additions & 0 deletions test/fail_compilation/test21927.d
@@ -0,0 +1,22 @@
// https://issues.dlang.org/show_bug.cgi?id=21927
/*
TEST_OUTPUT:
---
fail_compilation/test21927.d(19): Error: invalid `foreach` aggregate `this.T2(Args2...)`
fail_compilation/test21927.d(19): Error: invalid `foreach` aggregate `this.T2(Args2...)`
fail_compilation/test21927.d(20): Error: invalid `foreach` aggregate `this.T2!()`
fail_compilation/test21927.d(20): Error: invalid `foreach` aggregate `this.T2!()`
---
*/

struct S
{
template T2(Args2...) {}

void fun()
{
// original test case
static foreach (p; this.T2) {} // ICE
static foreach (p; this.T2!()) {} // ICE
}
}

0 comments on commit 96d3885

Please sign in to comment.