Opened 6 years ago

Last modified 6 years ago

#6981 new Bugs

Can't use boost::ptr_vector<T>::auto_type as data member in GCC 4.6

Reported by: Shuo Chen <giantchen@…> Owned by: Thorsten Ottosen
Milestone: To Be Determined Component: ptr_container
Version: Boost 1.49.0 Severity: Problem
Keywords: Cc:

Description

The following code failed to compile with g++ 4.6.3 on Ubuntu Linux 12.04 LTS.

#include <boost/noncopyable.hpp>
#include <boost/ptr_container/ptr_vector.hpp>

class Test : boost::noncopyable
{
};

class Pool : boost::noncopyable
{
 public:
  Pool();

 private:
  boost::ptr_vector<Test>::auto_type p_;
};

Pool::Pool()
{
}

the error is

In file included from /usr/include/boost/ptr_container/detail/reversible_ptr_container.hpp:22:0,
                 from /usr/include/boost/ptr_container/ptr_sequence_adapter.hpp:20,
                 from /usr/include/boost/ptr_container/ptr_vector.hpp:20,
                 from ptr_vec.cc:2:
/usr/include/boost/ptr_container/detail/static_move_ptr.hpp: 
In instantiation of 'boost::ptr_container_detail::static_move_ptr<Test, boost::ptr_container_detail::clone_deleter<...> >
::cant_move_from_const<const boost::ptr_container_detail::static_move_ptr<Test, boost::ptr_container_detail::clone_deleter<...> > >':
ptr_vec.cc:17:12:   instantiated from here
/usr/include/boost/ptr_container/detail/static_move_ptr.hpp:168:57: error: no type named 'error' in 'class boost::ptr_container_detail::static_move_ptr<Test, boost::ptr_container_detail::clone_deleter<boost::ptr_container_detail::reversible_ptr_container<boost::ptr_container_detail::sequence_config<Test, std::vector<void*, std::allocator<void*> > >, boost::heap_clone_allocator>::null_clone_allocator<false> > >'

However, if I inline the constructor, it compiles fine.

class PoolOkay : boost::noncopyable
{
 public:
  PoolOkay()
  {
    // okay to inline constructor
  }

 private:
  boost::ptr_vector<Test>::auto_type p_;
};

Note: there is no error when compiling with g++ 4.4.3

I am not sure if it's a bug of ptr_container or gcc itself.

Change History (2)

comment:1 Changed 6 years ago by Shuo Chen <giantchen@…>

update: the inline constructor is irrelevant, when I create an object of PoolOkay?, the same error appears.

comment:2 Changed 6 years ago by Shuo Chen <giantchen@…>

Workaround by declaring but not defining assignment operator and copy constructor.

class Pool
{
 // ...
 private:
  void operator=(const Pool&);
  Pool(const Pool&);
};

Looks like the error was trigger by compiler-generated copy ctor and/or assignment operator.

Worth mention that in the doc and put auto_type in regression tests, IMO.

Note: See TracTickets for help on using tickets.