Andrey Tarasevich wrote:
> Ian Collins wrote:
>>> ...
>>> I thought the copy ctor would be called when we invoke a.add(b)
>>> because Test::add() returns an object of Test type and here
>>> I expected the copy ctor to be called.
>>>
>> The compiler is free to optimise away the temporary return object (so
>> long as doing so doesn't change the behaviour of the program).
>
> In fact, the compiler is free to optimize away the temporary return object
> even if it _does_ change the behavior of the program.
Which is the reason why the OP didn't see any output from the copy
constructor. The 'missing' output is a change in behavior.