opAssign() still accepted for classes???

Steven Schveighoffer schveiguy at yahoo.com
Fri Apr 29 10:19:26 PDT 2011


On Fri, 29 Apr 2011 13:03:05 -0400, KennyTM~ <kennytm at gmail.com> wrote:

> On Apr 30, 11 00:14, Alexander wrote:
>> On 29.04.2011 17:05, Steven Schveighoffer wrote:
>>
>>> x = y is equivalent to x.opAssign(y).  So x is null, you are  
>>> dereferencing a null pointer.
>>
>>    Second thought... Since compiler *knows* that the pointer is null at  
>> this point, shouldn't it produce a warning at least?
>>
>> /Alexander
>
> That requires data flow analysis. For example, how could the compiler  
> knows the 'x' below is 'null'?
>
>      K x;
>      if (veryComplexCondition(y))
>         x = new K;
>      x = 4.0;   // <----
>
> See http://www.digitalmars.com/d/2.0/faq.html#nan.
>
> (That said, I see no problem treating this as a warning (which is  
> outside of the D spec) if a variable is provable 'null'.)

I think he was referring to the line:

X x = 0;

Where x could not possibly be anything other than null.

-Steve


More information about the Digitalmars-d mailing list