[Issue 22023] New: adding `return` to escaped argument of a variadic defeats @safe
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Jun 14 15:23:14 UTC 2021
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 at puremagic.com
Reporter: iamthewilsonator at 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
--
More information about the Digitalmars-d-bugs
mailing list