WTF: dmd 2.066 vs. dmd 2.067 really dangerous code breakage
John Colvin via Digitalmars-d
digitalmars-d at puremagic.com
Wed Apr 22 04:41:54 PDT 2015
On Wednesday, 22 April 2015 at 11:29:30 UTC, Daniel Kozak wrote:
> On Wednesday, 22 April 2015 at 11:28:44 UTC, Daniel Kozak wrote:
> static struct S
> {
> immutable FLAG_ON = 1;
> immutable FLAG_GPRS = 2;
> immutable FLAG_HIDDEN = 4;
> ubyte flags;
> ubyte value;
>
> bool isFlagSet(int flag)
> {
> return flags && flag == flag;
> }
> }
>
> void main(string[ ] args)
> {
> auto someData = [0x01, 0x10, 0x02, 0x16, 0x04, 0x08];
> auto countS = someData.length / S.sizeof;
>
> S[] sArray = (cast(S*)someData.ptr)[0 .. countS];
> assert(sArray.length == 3);
> }
I agree that the change should be more prominent in the changelog.
Having said that, if your code makes an assumption about the
layout (alignment and size) of a struct, it should `static
assert` that assumption, or at least have a test case that relies
it. You're just asking for trouble without that.
More information about the Digitalmars-d
mailing list