Test case: ------------------------ static assert(!{ auto p = null; return p !is null; }()); ------------------------ x.d(1): Error: static assert (!true) is false ------------------------ The problem is the strange statement 'cmp ^= -1' in https://github.com/D-Programming-Language/dmd/blob/master/src/interpret.c#L2338. When two pointers are both null, 'cmp' will be 1, and 'cmp ^ -1' is -2 which is also true.
DMD pull #229. https://github.com/D-Programming-Language/dmd/pull/229
(In reply to comment #0) > Test case: > > ------------------------ > static assert(!{ > auto p = null; > return p !is null; > }()); > ------------------------ > x.d(1): Error: static assert (!true) is false > ------------------------ > > The problem is the strange statement 'cmp ^= -1' in > https://github.com/D-Programming-Language/dmd/blob/master/src/interpret.c#L2338. > When two pointers are both null, 'cmp' will be 1, and 'cmp ^ -1' is -2 which is > also true. IIRC that was copied from Equals() in constfold.c. The bug probably exists there as well.
https://github.com/D-Programming-Language/dmd/commit/90f82ecf1376a20d39326c9033115f43fd8569dd https://github.com/D-Programming-Language/dmd/commit/000097b71f8ed2be69be36c1094efe694fb82a72