[cfe-dev] const-ness in libc++ allocator

redballoon36 at gmail.com redballoon36 at gmail.com
Thu Dec 29 16:29:27 PST 2011


Hello,

I've encountered a compiler error using shared_ptr and allocator from the
libc++ header <memory>.  I'm running OS X 10.7.2, and I first noticed this
while using the libc++ implementation with Xcode 4.2.1, though I believe
this still exists in svn 147357.

The problem is caused by instantiating std::allocator<> (in the memory
header) with a const type.  This causes the pointer and const_pointer types
to be the same, which results in methods using these to have the same
signatures, which gives a compiler error (as it should, given that methods
are colliding).  Is this supposed to happen? I haven't read the standard,
but it seems like it should work, that is, that std::allocator<const int>
should be allowed to exist.

A bit of background. This gets triggered when using:
std::shared_ptr<const int> ptr(new const int(4));
which also seems like a reasonable thing to do.

Thanks,
Paul O'Neil
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20111229/2f60e4ca/attachment.html>


More information about the cfe-dev mailing list