Opened 10 years ago

Closed 9 years ago

#7654 closed Bugs (worksforme)

offset_ptr can't be evaluated a pointer to a container in shared memory

Reported by: hongchenbo@… Owned by: Ion Gaztañaga
Milestone: To Be Determined Component: interprocess
Version: Boost 1.52.0 Severity: Problem
Keywords: offset_ptr boost::container Cc:

Description

i created a container(boost::container::set) in shared memory by managed_shared_memeory::construct,i wanted to put the pointer of container into a offset_ptr,codes as: typedef boost::container::set<int, less<int>, int_allocator_type> values_type; values_ptr_ = segment_manager_->construct<values_type>( boost::interprocess::anonymous_instance )( std::less<int>(), int_allocator_type( segment_manager_ ) );

when compiling: error C2512: 'boost::interprocess::allocator<T,SegmentManager>' : no appropriate default constructor available

with [

T=boost::container::container_detail::rbtree_node<unsigned int64,boost::interprocess::offset_ptr<void>>, SegmentManager=segment_manager_type

]

the related codes as: template <class T>

offset_ptr( T *ptr

, typename ipcdetail::enable_if< ipcdetail::is_convertible<T*, PointedType*> >::type * = 0)

{ this->set_offset(static_cast<PointedType*>(ptr)); }

template <bool B, class T = void> struct enable_if_c {

typedef T type;

};

template <class T> struct enable_if_c<false, T> {};

template <class Cond, class T = void> struct enable_if : public enable_if_c<Cond::value, T> {};

template <class Cond, class T = void> struct disable_if : public enable_if_c<!Cond::value, T> {};

template <class T, class U> class is_convertible {

typedef char true_t; class false_t { char dummy[2]; }; static true_t dispatch(U); static false_t dispatch(...); static T trigger(); public: static const bool value = sizeof(dispatch(trigger())) == sizeof(true_t);

};

i thougnt that T and U are values_type*,it's unnecessary to instantiate a values_type,but why called allocator's constructor ?

the boost::container's allocator must have a default constructor,but,in fact,boost::interprocess::allocator is stateful,its constructor need the pointer to segment_manager。is it a bug? or my codes is fault?

Change History (3)

comment:1 by hongchenbo@…, 10 years ago

sorry,i forgot to tell you i used visual studio 2010.the problem present in boost1.51 and boost1.52.

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

I can't reproduce the bug. Could you provide a full compilable example, please?

comment:3 by Ion Gaztañaga, 9 years ago

Resolution: worksforme
Status: newclosed

Please reopen the bug if you reproduce the issue and send a test case if possible.

Note: See TracTickets for help on using tickets.