[Issue 17218] New: foreach on tupleof inside switch returns ref to undefined address

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Thu Feb 23 05:36:08 PST 2017


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

          Issue ID: 17218
           Summary: foreach on tupleof inside switch returns ref to
                    undefined address
           Product: D
           Version: D2
          Hardware: x86
                OS: Mac OS X
            Status: NEW
          Severity: minor
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: alex.goltman at gmail.com

```
import std.stdio;

struct S {
    int x;
}
S s;
void main() {
    foreach (i, ref m; s.tupleof) {
        writefln("%s %s, %s", &s.tupleof[i], &m, m);
    }
    switch (0) {
        foreach (i, ref m; s.tupleof) {
            case i:
                writefln("%s %s, %s", &s.tupleof[i], &m, m);
        }
        default:
    }
}
```

Output:
```
7FAEC3D00260 7FAEC3D00260, 0
7FAEC3D00260 10DBF58F7, 15760771
```

Sometimes it crashes on segmentation fault since it doesn't really copy `m`
where it thinks it is.
Same happens when `s` is `__gshared S s;`.
Reproduces both on `dmd v2.071.0 on OSX` and `ldc2 1.1.0git-3139c87 on linux`.

--


More information about the Digitalmars-d-bugs mailing list