Bug 6281 – [CTFE] A null pointer '!is null' returns 'true'.

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Mac OS X
Creation time
2011-07-10T11:15:00Z
Last change time
2011-07-26T13:45:26Z
Keywords
patch, wrong-code
Assigned to
nobody
Creator
kennytm

Comments

Comment #0 by kennytm — 2011-07-10T11:15:16Z
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.
Comment #1 by kennytm — 2011-07-10T11:23:03Z
Comment #2 by clugdbug — 2011-07-20T16:23:32Z
(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.
Comment #3 by bugzilla — 2011-07-26T13:45:26Z