#177 SmartPtr: destructive copy from an rvalue is not working


SmartPtr with DestructiveCopy ownership policy can't perform copy construction from an rvalue.

#include <Loki/SmartPtr.h>

typedef Loki::SmartPtr<int, Loki::DestructiveCopy> Ptr;

Ptr makePtr() {
return Ptr(new int);

int main() {
Ptr ptr = makePtr(); // error!

Constructor taking RefToValue seems to be never called because template constructor with const argument is favoured. Also there is no conversion between RevToValue holding reference to SmartPtr with different pointee types.

It seems that the desired behaviour could be achieved by Colvin-Gibbons trick used in std::auto_ptr. However, it's more difficult to implement it in this SmartPtr. I've tried to write my own more lightweight policy-based SmartPtr and came up to some code which I attach here. It's not finished yet, but DestructiveCopy seems to be working.


  • Comment has been marked as spam. 

    You can see all pending comments posted by this user  here

    Anonymous - 2011-03-19

    My example of SmartPtr with DestructiveCopy

  • Richard Sposato

    Richard Sposato - 2011-09-08
    • assigned_to: nobody --> rich_sposato
    • status: open --> open-accepted
  • Richard Sposato

    Richard Sposato - 2011-09-08

    Added tests for DestructiveCopy policy. One test is commented out until this bug gets fixed.

    I did confirm compiler calls wrong constructor when SmartPtr is returned by value - thus leading to bug described here.

    revision 1097.

  • Richard Sposato

    Richard Sposato - 2011-09-13
    • status: open-accepted --> closed-duplicate
  • Richard Sposato

    Richard Sposato - 2011-09-13

    This is a duplicate of bug 2080889.

    Closing this bug report so only one report exists for this problem.

  • Richard Sposato

    Richard Sposato - 2011-09-17

    Fixed bug by adding const overload of Clone function in DestructiveCopy policy class.

    Fixed in revision 1101.
    Test for fix is available in revision 1102.


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks