dmd
dmd copied to clipboard
placement new returns bad pointer
This is really strange!
enum Bytes = 16; // set this to whatever you like
struct S {
ubyte[Bytes] poo;
}
void main()
{
ubyte[Bytes] buf = void;
S* t = new(buf) S();
assert(cast(ubyte*)t == buf.ptr); // FAILS!
assert(cast(ubyte*)t == buf.ptr + Bytes*2); // THIS WORKS! (this should NOT be correct)
}
For reasons unknown; t is equal to buf.ptr + Bytes*2... why would this new expression produce a result with offset of exactly Bytes*2 from the target?
If you change Bytes, you'll notice the offset is always Bytes*2
@WalterBright here's another super weird one...