[Issue 22854] static foreach byCodepoint segfault (2.099-rc.1)

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Dec 20 17:20:46 UTC 2022


https://issues.dlang.org/show_bug.cgi?id=22854

--- Comment #4 from Iain Buclaw <ibuclaw at gdcproject.org> ---
Tweaking the code to use a regular foreach:
---
void main() {
    foreach (ch; SomeContainer().range) { }
}
pragma(msg, main());
---

This is where the temporary gets *pushed* onto the CTFE stack.
---
// If the comma returns a temporary variable, it needs to be an lvalue
// (this is particularly important for struct constructors)
if (e.e1.op == EXP.declaration &&
    e.e2.op == EXP.variable &&
    e.e1.isDeclarationExp().declaration == e.e2.isVarExp().var &&
    e.e2.isVarExp().var.storage_class & STC.ctfe)
{
    VarExp ve = e.e2.isVarExp();
    VarDeclaration v = ve.var.isVarDeclaration();
    ctfeGlobals.stack.push(v);  // <--- here
---

However for `static foreach`, this is never done because of the equality
condition (declaration == var) is not true.

This despite both declarationexp and varexp having the same identifier name
(__slSomeCo3).

Obviously, *something* has been copied that really shouldn't have been.

--


More information about the Digitalmars-d-bugs mailing list