Skip to content

Commit

Permalink
fix Issue 13630 - Senseless error with foreach over variadic list
Browse files Browse the repository at this point in the history
  • Loading branch information
9rnsr committed Oct 22, 2014
1 parent 739e6fa commit 60a8d00
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/interpret.c
Expand Up @@ -6301,7 +6301,16 @@ class Interpreter : public Visitor
}
else if (result->op == TOKaddress)
{
result = ((AddrExp*)result)->e1; // *(&x) ==> x
result = ((AddrExp *)result)->e1; // *(&x) ==> x

// Bugzilla 13630, convert *(&[1,2,3]) to [1,2,3][0]
if (result->op == TOKarrayliteral &&
result->type->toBasetype()->nextOf()->toBasetype()->equivalent(e->type))
{
IntegerExp *ofs = new IntegerExp(result->loc, 0, Type::tsize_t);
result = new IndexExp(e->loc, result, ofs);
result->type = e->type;
}
}
else if (result->op == TOKnull)
{
Expand Down
21 changes: 21 additions & 0 deletions test/compilable/interpret3.d
Expand Up @@ -6677,3 +6677,24 @@ void test12851()
const int[5] arr;
alias staticZip = TypeTuple!(arr[0]);
}

/**************************************************
13630 - indexing and setting array element via pointer
**************************************************/

struct S13630(T)
{
T[3] arr;

this(A...)(auto ref in A args)
{
auto p = arr.ptr;

foreach (ref v; args)
{
*p = 0;
}
}
}

enum s13630 = S13630!float(1);

0 comments on commit 60a8d00

Please sign in to comment.