[Issue 20722] typeid(X).initializer() breaks safety
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Apr 7 03:46:20 UTC 2020
https://issues.dlang.org/show_bug.cgi?id=20722
--- Comment #2 from Mathias LANG <pro.mathias.lang at gmail.com> ---
Not quite. It's true the `null` pointers are not considered unsafe, otherwise
we wouldn't be able to dereference anything in `@safe` code.
But one of the guarantee that `@safe` code offers is that you cannot create an
invalid, non null pointer. That's why, for example, you can't do `arr.ptr`, but
you can do `&arr[idx].ptr`.
And if you do:
```
const void* ptr = &typeid(int).initializer()[$-1];
assert(ptr !is null);
writeln(ptr);
```
You create a pointer with value `0x3`, which breaks `@safe`.
--
More information about the Digitalmars-d-bugs
mailing list