opAssign(int) necessitates this(this) for automatic opAssign to work

Ali Çehreli acehreli at yahoo.com
Sat Dec 26 17:23:47 PST 2009


Simen kjaeraas wrote:
 > On Sun, 27 Dec 2009 01:42:07 +0100, Ali Çehreli <acehreli at yahoo.com> 
wrote:
 >
 >> I've tested the following with dmd 2.037.
 >>
 >> The compiler generated opAssign is disabled by the definition of
 >> opAssign(int). The compiler rejects the following assignment
 >> operation. (The error message is in the comment below.)
 >>
 >> Is this by design?
 >>
 >> When I also define post-blit, the compiler generated opAssign is
 >> available again and seems to work correctly. (My struct doesn't have
 >> any members for brevity.)
 >>
 >> The program below compiles when this(this) is provided.
 >>
 >> void main()
 >> {
 >>      S s0;
 >>      s0 = s0;    // ERROR
 >> }
 >
 > This piece of code does post-blit, not opAssign(int).

post-blit is when an object is constructed from another one. The above 
has two already constructed objects on both sides. So I think it is 
assignment.

 > Try defining opAssign(S). That should work here.

I know; but the problem is, defining opAssign(int) disables the 
compiler-generated opAssign(S); which is then interestingly available 
again, once this(this) is defined.

I just wanted to know whether there is a compiler bug in this behavior.

Ali



More information about the Digitalmars-d mailing list