Opened 11 years ago

Closed 10 years ago

#6533 closed Bugs (fixed)

Can't use map with incomplete type and interprocess allocator

Reported by: Erik Jensen <Erik.Jensen@…> Owned by: Ion Gaztañaga
Milestone: To Be Determined Component: container
Version: Boost 1.48.0 Severity: Problem
Keywords: Cc:

Description

A boost::container::map using boost::interprocess::allocator cannot be instantiated with an incomplete value type, even though the allocator itself can be.

Sample code:

#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>, Allocator> IncompleteMap;
class Incomplete
{
    Allocator foo;      // No error here
    IncompleteMap bar;  // Error!
};

The error occurs as part of the instantiation of boost::container::container_detail::is_convertible by boost::container::container_detail::impl::extract_version. Using using boost::is_convertible instead fixes the problem on Visual Studio 20103

Change History (2)

comment:1 by Ion Gaztañaga, 11 years ago

First of all, the code is wrong as the first parameter of std::pair should be const:

boost::interprocess::allocator<std::pair<CONST std::string, Incomplete>,

Does this compile? My local version (for boost 1.50) compiles, so it will be fixed.

#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<const std::string, Incomplete>,

boost::interprocess::managed_shared_memory::segment_manager> Allocator;

typedef boost::interprocess::map<std::string, Incomplete,

std::less<std::string>, Allocator> IncompleteMap;

class Incomplete {

Allocator foo; No error here IncompleteMap bar; Error! public: Incomplete()

: foo(0), bar(IncompleteMap::key_compare(), foo)

{}

};

int main() {

Incomplete incomplete; return 0;

}

comment:2 by Ion Gaztañaga, 10 years ago

Resolution: fixed
Status: newclosed

Fixed in Boost 1.50

Note: See TracTickets for help on using tickets.