[Issue 22982] New: Can't copy scope range elements into a returned array

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Apr 4 09:09:46 UTC 2022


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

          Issue ID: 22982
           Summary: Can't copy scope range elements into a returned array
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: atila.neves at gmail.com

This code should, but doesn't, compile:

---------------------
void main() @safe pure {
    import std.range : only;
    scope rng = only("foo", "bar");
    oops(rng);
}

auto oops(Range)(return scope Range range) @safe {
    import std.range : ElementEncodingType;
    ElementEncodingType!Range[] result;
    foreach(e; range)
        result ~= e;
    return result;
}
------------------------

d.d(13): Error: scope variable `e` may not be copied into allocated memory
d.d(6): Error: template instance `d.oops!(OnlyResult!(string, string))` error
instantiating

--


More information about the Digitalmars-d-bugs mailing list