opAssign() still accepted for classes???

Steven Schveighoffer schveiguy at yahoo.com
Fri Apr 29 08:05:09 PDT 2011


On Fri, 29 Apr 2011 10:43:56 -0400, Alexander <aldem+dmars at nk7.net> wrote:

> Doing some experiments, and after conversion of struct into a class I've  
> found that opAssign(), contrary to what documentation says, is silently  
> accepted for classes (in D 2.052)

opAssign is only invalid if you are assigning something that implicitly  
converts to that type.

So this will fail:

typeof(this) opAssign(typeof(this) otherthing) {...}

> What is worse, it segfaults when object is not constructed first:

x = y is equivalent to x.opAssign(y).  So x is null, you are dereferencing  
a null pointer.

-Steve


More information about the Digitalmars-d mailing list