[LLVMbugs] [Bug 18843] New: Cannot create shared_ptr to const derived from enable_shared_from_this

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Feb 14 11:31:08 PST 2014


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

            Bug ID: 18843
           Summary: Cannot create shared_ptr to const derived from
                    enable_shared_from_this
           Product: libc++
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: All Bugs
          Assignee: hhinnant at apple.com
          Reporter: w.shane.grant at gmail.com
                CC: llvmbugs at cs.uiuc.edu, mclow.lists at gmail.com
    Classification: Unclassified

Using the latest svn checkout of libc++ with clang 3.3, the following code does
not compile, although it does compile under libstdc++:

--------------

#include <memory>

struct A : std::enable_shared_from_this<A>
{};

int main()
{
  std::shared_ptr<A const>( new A() );
};

--------------

It seems that internally this tries to assign a shared_ptr<const A> to a
weak_ptr<A>, which obviously isn't valid, but it seems like very strange
behavior to be unable to create shared_ptr to constant classes derived from
enable_shared_from_this.  In libstdc++ they seem to use const_cast to get
around this.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20140214/bf2ed462/attachment.html>


More information about the llvm-bugs mailing list