[Container][Interprocess] Can't use map with incomplete type and interprocess allocator

The following code gives me a compiler error on Visual Studio 2010 with both Boost 1.48 and 1.49beta1: #include <string> #include <boost/interprocess/allocators/allocator.hpp> #include <boost/interprocess/containers/map.hpp> #include <boost/interprocess/managed_shared_memory.hpp> class Incomplete; typedef boost::interprocess::allocator<std::pair<std::string, Incomplete>, boost::interprocess::managed_shared_memory::segment_manager> Allocator; typedef boost::interprocess::map<std::string, Incomplete, std::less<std::string>, Allocator1> IncompleteMap; class Incomplete { IncompleteMap blah; }; This code compiles fine if I instead use std::allocator. As best as I can tell from the compiler message, at some point in the instantiation of map, boost::container::container_detail::version<T> is instantiated with T=boost::interprocess::allocator< boost::container::container_detail::rbtree_node< std::pair<std::string,Incomplete>, boost::interprocess::offset_ptr<void> >, boost::interprocess::segment_manager< char, boost::interprocess::rbtree_best_fit< boost::interprocess::mutex_family >, boost::interprocess::iset_index >
Which results in boost::container::container_detail::is_convertable<T,U> being instantiated with T=boost::container::container_detail::version_type< boost::interprocess::allocator<...>, // Same as above 0
U=boost::container::container_detail::version_type< boost::interprocess::allocator<...>, 2
Somehow (I'm quite fuzzy on this), this results in boost::container::container_detail::rbtree_node<T,VoidPointer> being instantiated with T=std::pair<std::string,Incomplete>. This then results in the pair being instantiated, which has a member of type Incomplete... BOOM! If I replace container_detail::is_convertible in extract_version with boost::is_convertible from Boost.TypeTraits (or with std::is_convertible, for that matter), the code above successfully compiles. Is this a valid temporary workaround, or will it lead to other complications? Thank you, Erik Jensen

El 07/02/2012 20:12, Jensen, Erik A escribió:
The following code gives me a compiler error on Visual Studio 2010 with both Boost 1.48 and 1.49beta1:
There is no guarantee that you can build containers of incomplete types with any allocator type. The allocator might need to instantiate the type (say, because it uses sizeof(T) to calculate some compile-time internal static constants). Nevertheless, I would like to see if this is possible for Boost.Container and some basic Boost.Interprocess allocators. Can you please fill a bug on the track so that this issue is not forgotten? Best, Ion

On Tuesday, February 07, 2012 2:03 PM, Ion Gaztañaga wrote:
El 07/02/2012 20:12, Jensen, Erik A escribió:
The following code gives me a compiler error on Visual Studio 2010 with both Boost 1.48 and 1.49beta1:
There is no guarantee that you can build containers of incomplete types with any allocator type. The allocator might need to instantiate the type (say, because it uses sizeof(T) to calculate some compile-time internal static constants).
It definitely makes sense that some allocators wouldn't support incomplete types. In this case, however, the allocator itself can be instantiated without issue (T is only used in typedefs and member functions).
Nevertheless, I would like to see if this is possible for Boost.Container and some basic Boost.Interprocess allocators. Can you please fill a bug on the track so that this issue is not forgotten?
Ticket #6533 (https://svn.boost.org/trac/boost/ticket/6533)
Best,
Ion
Thanks again for your help, Erik Jensen
participants (2)
-
Ion Gaztañaga
-
Jensen, Erik A