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

Howard Hinnant hhinnant at apple.com
Mon Jan 2 06:47:24 PST 2012

On Jan 2, 2012, at 2:21 AM, redballoon36 at gmail.com wrote:

> (Howard: Sorry, I hadn't meant to send that email just yet.)
> I'm attempting to get Cinder (libcinder.org) to compile with libc++.  It uses things like std::shared_ptr<const __CFDictionary>, which is returned const from CFDictionaryCreate(...).  There's no need to modify the resulting Dictionary (and they are immutable anyway?), so it makes sense to keep the value const.  Thinking "aloud," I could have a GUI element that uses a shared_ptr to reference a color from the user's preferences in order to draw itself, that the GUI element shouldn't ever modify, so the value should be const.  This way, when the GUI dies, the shared_ptr does it thing and cleans up the color.
> In terms of fixes, the thing that causes this is that a const type is passed into the shared_ptr.  Removing the const where the shared_ptr instantiates the allocator should also fix this.  Similarly the const-ness could be removed(cast/type_trait-ed) in the Cinder code, avoiding any changes to the library.
> At this point, though, I'm arguing with the standard, so I lose for now.  I'll get you next time, C++!
> Thanks,
> Paul O'Neil
> On Mon, Jan 2, 2012 at 1:55 AM, Paul O'Neil <redballoon36 at gmail.com> wrote:
> I'm attempting to get Cinder (libcinder.org) to compile with libc++.  It uses a std::shared_ptr<const __CFDictionary>, which is returned from CFDictionaryCreate(...).

This is now looking like a libc++ bug.  std::shared_ptr<const __CFDictionary> should work.  And it does if you don't use make_shared<const __CFDictionary>().  make_shared<const __CFDictionary>() should also work.  I will fix this.  As a workaround, try:

   shared_ptr<const __CFDictionary> = make_shared<const __CFDictionary>();


More information about the cfe-dev mailing list