www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22023] New: adding `return` to escaped argument of a variadic

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

          Issue ID: 22023
           Summary: adding `return` to escaped argument of a variadic
                    defeats  safe
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: iamthewilsonator hotmail.com

Given 
```
Foo createFoo()  safe {
    return Foo(1, 2, 3);
}

void main()  safe {
    import std.stdio : writeln;
    auto foo = createFoo();
    foreach (f; foo.e) writeln(f, " ");
}
```

Defining Foo as:
```
struct Foo {
    this(int[] e...)  safe {
        this.e = e;
    }
    int[] e;
}
```
correctly errors as "Error: scope variable `e` assigned to `this` with longer
lifetime"
Adding return to the variadic argument 
```
struct Foo {
    this(return int[] e...)  safe {
        this.e = e;
    }
    int[] e;
}
```

Compiles and prints garbage: e.g. 
1 
0 
2003568368

--
Jun 14