Boost logo

Boost :

Subject: Re: [boost] [operators] The Dangling Reference Polarization
From: Michael Marcin (mike.marcin_at_[hidden])
Date: 2013-05-04 19:22:18


On 5/4/2013 5:36 PM, Daniel Frey wrote:
> On 04.05.2013, at 21:45, Michael Marcin <mike.marcin_at_[hidden]> wrote:
>
>> Here is another data point:
>> http://ideone.com/GgaZZV
>>
>> And here are msvc11 results:
>> http://codepad.org/XFT5qVyE
>>
>> based on:
>> http://stackoverflow.com/questions/1693005/copy-elision-on-visual-c-2010-beta-2
>
> From what I can see these are some more basic tests and they confirm that copy elision does not take place for pass-by-value (for MSVC, but my tests also confirmed that for GCC/Clang), i.e., the last test case "identity( rvalue() )" does not eliminate the temporary. Is there anything else that can be learned from the above that I missed?
>

MSVC11 does do copy elision when only trivial types are involved it
seems. For example try instead of std::vector try:
typedef std::array<std::pair<int,int>,4> pod;

Direct initialization from rvalue, constructed with pod
X a(( rvalue(pod()) ))
===========
X5: construct (with pod)
X5: destroy
-----------
0/1 possible copies made
0/1 possible moves made
1/1 possible elisions performed

However any more complicated it seems to give up.
To my mind the following should be a trivial change that has no impact.
Indeed gcc-4.7.2 has no change but msvc11:

Direct initialization from rvalue, constructed with pod
X a(( true, rvalue(pod()) ))
===========
X3: construct (with pod)
X4: <- X3: **move**
X3: destroy
X4: destroy
-----------
0/1 possible copies made
1/1 possible moves made
0/1 possible elisions performed


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk