I believe this is a bug in libc++ that I've run into. I submitted a bug report for this a little while ago (http://llvm.org/bugs/show_bug.cgi?id=18843).
The issue arises because a shared_ptr
to some const
version of the class that derives from std::enable_shared_from_this
is assigned a non-const pointer to that type. In libstdc++, this const
is stripped away internally in the functions that do the assignment to the internal weak_ptr
in std::enable_shared_from_this
, but this does not occur in libc++. The following code shows an example of what will cause this error under the current libc++:
struct A : std::enable_shared_from_this<A> {};
int main()
{
std::shared_ptr<A const> ptr( new A() );
}
You can work around this for now by doing something like:
std::shared_ptr<A const> ptr( std::const_pointer_cast<A const>( std::shared_ptr<A>( new A() ) ) );
Where the new A()
is just the pointer you are trying to get into the shared_ptr
.