fix Issue 23391 - [Reg 2.098.1] Segmentation fault with static foreach + range + inout

This commit is contained in:
Iain Buclaw 2022-12-19 06:57:49 +01:00
parent 07ece2730b
commit b953c592c1
2 changed files with 39 additions and 1 deletions

View file

@ -1249,7 +1249,14 @@ UnionExp Slice(Type type, Expression e1, Expression lwr, Expression upr)
}
}
if (e1.op == EXP.string_ && lwr.op == EXP.int64 && upr.op == EXP.int64)
if (!lwr)
{
if (e1.op == EXP.string_)
emplaceExp(&ue, e1);
else
cantExp(ue);
}
else if (e1.op == EXP.string_ && lwr.op == EXP.int64 && upr.op == EXP.int64)
{
StringExp es1 = e1.isStringExp();
const uinteger_t ilwr = lwr.toInteger();

View file

@ -0,0 +1,31 @@
struct MyTuple {
string s;
}
inout(string) myfront(inout(string)[] a)
{
return a[0];
}
MyTuple[] myarray(MyZip r)
{
MyTuple[] result;
foreach (e; r)
result ~= e;
return result;
}
struct MyZip
{
bool empty = false;
MyTuple front()
{
return MyTuple([""].myfront);
}
void popFront()
{
empty = true;
}
}
static foreach(t; MyZip().myarray) {}