-1

Possible Duplicate:
How to disable return value optimization in Visual Studio 2010?

I am implement my intrusive ptr and have a problem. When some method return my smart pointer than don't called copy constructor. How to disable RVO in MS VS2012 ?

Community
  • 1
  • 1
Dzmitry93
  • 13
  • 2
  • Please post code that exhibits your issue. – Michael Foukarakis Jan 05 '13 at 06:50
  • See my comment on the downvoted answer to the duplicate question; declaring returned the smart pointer object `volatile` will prevent RVO from applying. From there you can hopefully debug the class so it works with RVO. – Potatoswatter Jan 05 '13 at 07:02
  • @Potatoswatter : When i try compile code with volatile object that i returning i have an error : error C2558: class 'A' > : no copy constructor available or copy constructor is declared > 'explicit' – Dzmitry93 Jan 05 '13 at 08:07

1 Answers1

2

You don't need to disable RVO, because you don't need the copy constructor call, because the RVO elision means that the object isn't copied, so there's no extra reference counting to be done.

In short, the optimization doesn't change a thing for correct code, other than speed and memory consumption.

Cheers and hth. - Alf
  • 142,714
  • 15
  • 209
  • 331
  • Perhaps OP has some code in the copy constructor which produces *side effects* & copy constructor not being called affects this side effect prone book keeping. – Alok Save Jan 05 '13 at 06:34
  • @Alok: then it's not correct code :-). – Cheers and hth. - Alf Jan 05 '13 at 06:35
  • Indeed, it is not correct :) The problem is OPs implementation for reference counting is side effect prone. In short the implementation is incorrect. Also, I don't think one can disable RVO in MSVC, one can only disable NRVO AFAIK. – Alok Save Jan 05 '13 at 06:36