Skip to content

Commit

Permalink
fix Issue 13899 - Unwanted warning for pure opApply
Browse files Browse the repository at this point in the history
Add explicit cast(void) to discard return value of opApply.
  • Loading branch information
9rnsr committed Dec 28, 2014
1 parent 22611aa commit e57d8c0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/statement.c
Expand Up @@ -2501,6 +2501,7 @@ Statement *ForeachStatement::semantic(Scope *sc)
if (!cases->dim)
{
// Easy case, a clean exit from the loop
e = new CastExp(loc, e, Type::tvoid); // Bugzilla 13899
s = new ExpStatement(loc, e);
}
else
Expand Down
20 changes: 19 additions & 1 deletion test/compilable/warn3882.d
Expand Up @@ -8,7 +8,7 @@ TEST_OUTPUT:
@safe pure nothrow void strictVoidReturn(T)(T x) {}
@safe pure nothrow void nonstrictVoidReturn(T)(ref T x) {}

void main()
void test3882()
{
int x = 3;
strictVoidReturn(x);
Expand Down Expand Up @@ -64,3 +64,21 @@ void test12909()
const(int[])[int] makeAA() { return null; } // to make r-value
makeAA().rehash();
}

/******************************************/
// 13899

const struct Foo13899
{
int opApply(immutable int delegate(in ref int) pure nothrow dg) pure nothrow
{
return 1;
}
}

void test13899()
{
foreach (x; Foo13899())
{
}
}

0 comments on commit e57d8c0

Please sign in to comment.