Unexpected copy constructor behavior

Steven Schveighoffer schveiguy at gmail.com
Fri Jul 10 12:05:35 UTC 2020


On 7/10/20 3:31 AM, psycha0s wrote:
> On Thursday, 9 July 2020 at 22:18:59 UTC, Steven Schveighoffer wrote:
>> Looking at the generated AST, it's because the compiler is adding an 
>> auto-generated opAssign, which accepts a Foo by value. It is that 
>> object that is being created and destroyed.
> 
> Is there a reason the autogenerated opAssign accepts its argument by 
> value? Honestly, it looks like a premature pessimisation to me.

If it accepts the value by ref, then it will not bind to rvalues. 
Accepting by value accepts anything.

-Steve


More information about the Digitalmars-d-learn mailing list