www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20725] New: Taking address of potentially null struct member

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

          Issue ID: 20725
           Summary: Taking address of potentially null struct member isn't
                    safe
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: safe
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: pro.mathias.lang gmail.com

```
import std.stdio;

struct Bar
{
    ubyte[0x7FFF_FFE] memory1 = void;
    ubyte[0x7FFF_FFE] memory2 = void;
    ubyte[0x7FFF_FFE] memory3 = void;
    int oops = void;
}

void main ()  safe
{
    Bar* b;
    int* ptr = &b.oops;
    assert(ptr !is null);
    writeln(ptr);
}
```

Ouputs:
```
17FFFFFC
```

And is very obviously violating  safety promises.
Originally reported by Rainers in
https://issues.dlang.org/show_bug.cgi?id=20722.

--
Apr 07 2020