mirror of
https://github.com/dlang/dmd.git
synced 2025-04-26 05:00:16 +03:00
fix Issue 22854 - static foreach byCodepoint segfault (2.099-rc.1)
This commit is contained in:
parent
a6e34f8ae8
commit
77935bf494
3 changed files with 49 additions and 2 deletions
|
@ -218,12 +218,12 @@ extern (C++) final class StaticForeach : RootObject
|
|||
{
|
||||
if (aggrfe)
|
||||
{
|
||||
return new ForeachStatement(loc, aggrfe.op, parameters, aggrfe.aggr.syntaxCopy(), s, loc);
|
||||
return new ForeachStatement(loc, aggrfe.op, parameters, aggrfe.aggr, s, loc);
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(rangefe && parameters.dim == 1);
|
||||
return new ForeachRangeStatement(loc, rangefe.op, (*parameters)[0], rangefe.lwr.syntaxCopy(), rangefe.upr.syntaxCopy(), s, loc);
|
||||
return new ForeachRangeStatement(loc, rangefe.op, (*parameters)[0], rangefe.lwr, rangefe.upr, s, loc);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
20
compiler/test/compilable/issue22854.d
Normal file
20
compiler/test/compilable/issue22854.d
Normal file
|
@ -0,0 +1,20 @@
|
|||
// https://issues.dlang.org/show_bug.cgi?id=22854
|
||||
void test22854()
|
||||
{
|
||||
static foreach (ch; SomeContainer().range) { }
|
||||
}
|
||||
|
||||
struct SomeContainer
|
||||
{
|
||||
SomeRange range() { return SomeRange(); }
|
||||
TypeWithDestructor data;
|
||||
}
|
||||
|
||||
struct TypeWithDestructor { ~this() { } }
|
||||
|
||||
struct SomeRange
|
||||
{
|
||||
int front() { return 0; }
|
||||
bool empty() { return true; }
|
||||
void popFront() { }
|
||||
}
|
27
compiler/test/runnable/issue22854.d
Normal file
27
compiler/test/runnable/issue22854.d
Normal file
|
@ -0,0 +1,27 @@
|
|||
// https://issues.dlang.org/show_bug.cgi?id=22854
|
||||
void main()
|
||||
{
|
||||
uint loops = 0;
|
||||
static foreach (i; 0 .. 50)
|
||||
{
|
||||
static foreach (ch; SomeContainer().range)
|
||||
loops++;
|
||||
}
|
||||
assert(loops == 50 * 50);
|
||||
}
|
||||
|
||||
struct SomeContainer
|
||||
{
|
||||
SomeRange range() { return SomeRange(); }
|
||||
TypeWithDestructor data;
|
||||
}
|
||||
|
||||
struct TypeWithDestructor { ~this() { } }
|
||||
|
||||
struct SomeRange
|
||||
{
|
||||
int count = 50;
|
||||
int front() { return count; }
|
||||
bool empty() { return count <= 0; }
|
||||
void popFront() { count--; }
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue