if(arr) now a warning
Steven Schveighoffer via Digitalmars-d
digitalmars-d at puremagic.com
Wed Apr 29 19:41:59 PDT 2015
On 4/29/15 4:29 AM, Iain Buclaw via Digitalmars-d wrote:
> On 29 April 2015 at 06:38, Steven Schveighoffer via Digitalmars-d
> <digitalmars-d at puremagic.com> wrote:
>> FYI, Andrei and Walter are reversing this change barring any new evidence
>> it's helpful to people. Please speak up if you disagree.
>>
>> https://github.com/D-Programming-Language/dmd/pull/2885#issuecomment-97299912
>>
>
> I disagree, and I would extend my thoughts to say that I don't think
> that the change is enough. We should also be warning on delegates and
> associative arrays too!
>
> if (arr) // Implicitly converted to (arr.ptr | arr.length) != 0
if(arr) simply means if(arr.ptr) != 0. Length does not come into play.
> if (dg) // Implicitly converted to (dg.ptr | dg.funcptr) != 0
I don't know if I've ever expected that, you sure that's true? I would
actually expect if(dg) to be equivalent to if(dg.funcptr). I have no
idea how a dg would have a null pointer but valid funcptr.
> if (aa) // Implicitly converted to (aa.ptr != null)
This is easily fixed when we fix aa to be a library type. We don't need
compiler help to fix this issue (we do need compiler help to remove AA
specialty code from the compiler, but once it's out, we can fix this
without effort).
-Steve
More information about the Digitalmars-d
mailing list