D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6281 - [CTFE] A null pointer '!is null' returns 'true'.
Summary: [CTFE] A null pointer '!is null' returns 'true'.
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other Mac OS X
: P2 normal
Assignee: No Owner
URL:
Keywords: patch, wrong-code
Depends on:
Blocks:
 
Reported: 2011-07-10 11:15 UTC by kennytm
Modified: 2011-07-26 13:45 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description kennytm 2011-07-10 11:15:16 UTC
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 kennytm 2011-07-10 11:23:03 UTC
DMD pull #229.

https://github.com/D-Programming-Language/dmd/pull/229
Comment 2 Don 2011-07-20 16:23:32 UTC
(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.