RVO force compilation error on failure

前端 未结 3 1590
梦毁少年i
梦毁少年i 2020-12-17 22:35

Lots of discussions here about when RVO can be done but not much about when it is actually done. As stated may times, RVO can not be guaranteed according to the Standard but

3条回答
  •  不知归路
    2020-12-17 23:26

    1. I don't believe there's any way to make such a guarantee. RVO is an optimization and as such the compiler may determine in a particular case that using it is actually a de-optimization and elect to not do so.

    2. I'm assuming you're referring to your first code snippet. In 32 bit bit compilation I'm unable to reproduce your assertion on g++ 4.4, 4.5, or 4.8 (through ideone.com) even with no optimization enabled at all. In 64 bit compilation I can reproduce your no-RVO behavior. This smells like a 64 bit code generation bug in g++.

    3. If in fact what I observed in (2) is a bug then once the bug is fixed it will just work.

    4. I can confirm that Sun CC also does not RVO your specific examples even in 32 bit compilation.

    I do wonder however if somehow your introspection code to print out the addresses is causing the compiler to inhibit the optimization (for example it may need to inhibit the optimization to prevent possible aliasing problems).

提交回复
热议问题