[Issue 23440] closure over typesafe variadic or scope array passes safe though leads to stack corruption

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Mar 28 15:18:06 UTC 2023


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

Ate Eskola <Ajieskola at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |Ajieskola at gmail.com

--- Comment #3 from Ate Eskola <Ajieskola at gmail.com> ---
This isn't due to any bug in variadic arrays. They are (as far as I tested)
properly treated as `scope` arrays with the `-preview=dip1000` flag.

The real failure is in creation of the closure. This compiles and behaves
exactly like the original example:

---
void delegate() @safe foo(scope int[] stuff) @safe { 
        return () {
                assert(stuff == [1,2,3]);
                foreach(item; stuff) {}
        };
}

void delegate() @safe helper() @safe {
        int[3] stArray = [1, 2, 3];
        return foo(stArray);
}

void bar() @safe {
        int[2048] pwned; // just to smash the stack
}

void main() @safe {
        auto dg = helper();
        bar();
        dg();
}
---

--


More information about the Digitalmars-d-bugs mailing list