[LLVMbugs] [Bug 11616] New: std::make_shared call will fail to compile for a class with a non-copyable member and a non-default constructor

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Mon Dec 19 04:05:52 PST 2011


http://llvm.org/bugs/show_bug.cgi?id=11616

             Bug #: 11616
           Summary: std::make_shared call will fail to compile for a class
                    with a non-copyable member and a non-default
                    constructor
           Product: libc++
           Version: unspecified
          Platform: Macintosh
        OS/Version: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: All Bugs
        AssignedTo: hhinnant at apple.com
        ReportedBy: alexander.bolodurin at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified


I've tested with Clang 3.0, but it's probably in the latest too, given that the
release wasn't that far off.

This compiles:
-------------------8<-------------------
#include <memory>

class Foo
{
public:
    Foo()
        : mem_(new int(10))
    {
    }
    std::unique_ptr<int> mem_;
};

int main()
{
    auto foo = std::make_shared<Foo>();
    return 0;
}
-------------------8<-------------------

This doesn't:

-------------------8<-------------------
#include <memory>
#include <string>

class Foo
{
public:
    Foo(const std::string& s)
        : mem_(new int(10))
    {
    }
    std::unique_ptr<int> mem_;
};

int main()
{
    auto foo = std::make_shared<Foo>("aaa");
    return 0;
}
-------------------8<-------------------

The fix to the above is to introduce an explicit move constructor (so it
compiles again):

-------------------8<-------------------
#include <memory>
#include <string>

class Foo
{
public:
    Foo(const std::string& s)
        : mem_(new int(10))
    {
    }
    Foo(Foo&& other)
        : mem_(std::move(other.mem_))
    {
    }
    std::unique_ptr<int> mem_;
};

int main()
{
    auto foo = std::make_shared<Foo>("aaa");
    return 0;
}
-------------------8<-------------------

But the second example should be working fine as far as I can see (gcc happily
accepts it).

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list