Reputation: 1289
A user has come to me with compilation problems on OS X:
http://fpaste.org/77628/39251593/
After ruling out the obvious; using gcc rather than clang, and the "right" standard library, it became apparent that the issue was with the std::enable_shared_from_this<> part of the class declaration
The class itself has a declaration of
class Expression : public std::enable_shared_from_this<Expression> {
// ...
};
Some investigation shows that this could be a problem with Xcode/clang itself: https://github.com/kripken/emscripten/issues/270
https://code.google.com/p/alembic/issues/detail?id=315
Can someone confirm this? Alternatively, is there a way to solve this?
Code is located here with the file in question located here
EDIT: The code in question was unneeded, so was removed. Link updated with a specific commit (r1047)
Upvotes: 3
Views: 491
Reputation: 1672
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
.
Upvotes: 2