Bug 5416 – null should have a type of its own

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-01-05T16:30:00Z
Last change time
2011-11-25T00:29:16Z
Keywords
patch
Assigned to
nobody
Creator
simen.kjaras

Comments

Comment #0 by simen.kjaras — 2011-01-05T16:30:53Z
Currently, it is impossible to special-case comparisons with null. If instead null had its own type, one could allow direct comparisons between user-defined types and null, instead of supporting comparison with any and all void*s. For structs, such a comparison function could then be used for both 'foo == null' and 'foo is null'. For classes, neither likely makes sense.
Comment #1 by code — 2011-10-07T09:08:52Z
Also if you pass null to a template it completely looses its implict conversion abilites. See following example. void foo(Object o){ } void fooHelper(T)(T o){ foo(o); } void main(string[] args){ fooHelper(null); //can not implicitly convert void* to Object } This also stops std.conv.emplace to work correctly with constructors you want to pass null to.
Comment #2 by bugzilla — 2011-10-27T01:12:57Z
Comment #3 by timon.gehr — 2011-10-27T02:07:54Z
(In reply to comment #1) > Also if you pass null to a template it completely looses its implict conversion > abilites. See following example. > > void foo(Object o){ > } > > void fooHelper(T)(T o){ > foo(o); > } > > void main(string[] args){ > fooHelper(null); //can not implicitly convert void* to Object > } > > This also stops std.conv.emplace to work correctly with constructors you want > to pass null to. This is still true if 'Object' is replaced by Object[], 'null' is replaced by '[]' and 'void*' by 'void[]'. Therefore, '[]' needs an own type too. (I think it is the same issue, or should I file a separate bug for it?)
Comment #4 by k.hara.pg — 2011-10-27T05:05:57Z
Comment #5 by bugzilla — 2011-11-25T00:29:16Z