Opened 9 years ago

Closed 6 years ago

#9003 closed Bugs (wontfix)

Compiler error when trying to return and assign a vector of non-copyables but movables from a function in C++03

Reported by: Adam Romanek <romanek.adam@…> Owned by: Ion Gaztañaga
Milestone: To Be Determined Component: container
Version: Boost 1.54.0 Severity: Problem
Keywords: Cc:

Description

I get a compiler error when when trying to return and assign a vector of non-copyables but movables from a function in C++03:

g++ -I/home/A.Romanek/tmp/boost/boost_1_54_0 -O3    main.cpp   -o main
In file included from /home/A.Romanek/tmp/boost/boost_1_54_0/boost/container/allocator_traits.hpp:388:0,
                 from /home/A.Romanek/tmp/boost/boost_1_54_0/boost/container/detail/utilities.hpp:28,
                 from /home/A.Romanek/tmp/boost/boost_1_54_0/boost/container/vector.hpp:37,
                 from main.cpp:1:
/home/A.Romanek/tmp/boost/boost_1_54_0/boost/preprocessor/iteration/detail/local.hpp: In static member function ‘static void boost::container::allocator_traits<Alloc>::priv_construct_dispatch2(boost::false_type, Alloc&, T*, const P0&) [with T = non_copyable, P0 = non_copyable, Alloc = std::allocator<non_copyable>, boost::false_type = boost::integral_constant<bool, false>]’:
/home/A.Romanek/tmp/boost/boost_1_54_0/boost/preprocessor/iteration/detail/local.hpp:37:1:   instantiated from ‘static void boost::container::allocator_traits<Alloc>::priv_construct(boost::true_type, Alloc&, T*, const P0&) [with T = non_copyable, P0 = non_copyable, Alloc = std::allocator<non_copyable>, boost::true_type = boost::integral_constant<bool, true>]’
/home/A.Romanek/tmp/boost/boost_1_54_0/boost/preprocessor/iteration/detail/local.hpp:37:1:   instantiated from ‘static void boost::container::allocator_traits<Alloc>::construct(Alloc&, T*, const P0&) [with T = non_copyable, P0 = non_copyable, Alloc = std::allocator<non_copyable>]’
/home/A.Romanek/tmp/boost/boost_1_54_0/boost/container/detail/utilities.hpp:555:10:   instantiated from ‘typename boost::container::container_detail::disable_if_memcpy_copy_constructible<I, F, F>::type boost::container::uninitialized_copy_alloc_n(A&, I, typename std::iterator_traits<_II>::difference_type, F) [with A = std::allocator<non_copyable>, I = non_copyable*, F = non_copyable*, typename boost::container::container_detail::disable_if_memcpy_copy_constructible<I, F, F>::type = non_copyable*, typename std::iterator_traits<_II>::difference_type = int]’
/home/A.Romanek/tmp/boost/boost_1_54_0/boost/container/vector.hpp:734:7:   instantiated from ‘boost::container::vector<T, Allocator>::vector(const boost::container::vector<T, Allocator>&) [with T = non_copyable, Allocator = std::allocator<non_copyable>, boost::container::vector<T, Allocator> = boost::container::vector<non_copyable>]’
main.cpp:14:49:   instantiated from here
/home/A.Romanek/tmp/boost/boost_1_54_0/boost/preprocessor/iteration/detail/local.hpp:37:1: error: passing ‘const non_copyable’ as ‘this’ argument of ‘non_copyable::operator boost::rv<non_copyable>&()’ discards qualifiers [-fpermissive]

The problem was discussed on Boost-users list: http://lists.boost.org/boost-users/2013/08/79697.php

See the attachment for a code example.

The problem can be reproduced on gcc 4.6.3.

NOTE: using -std=c++0x makes the code example compile without any problems.

Attachments (1)

test.cpp (664 bytes ) - added by Adam Romanek <romanek.adam@…> 9 years ago.

Download all attachments as: .zip

Change History (3)

by Adam Romanek <romanek.adam@…>, 9 years ago

Attachment: test.cpp added

comment:1 by Adam Romanek <romanek.adam@…>, 9 years ago

Component: Nonecontainer
Owner: set to Ion Gaztañaga

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

Resolution: wontfix
Status: newclosed

Reviewing old bugs sorry for the huge delay. Replying to document the existing workaround to future bug readers. The problem is related to move emulation as explained in:

http://www.boost.org/doc/libs/1_61_0/doc/html/move/move_return.html

Changing the generation function to:

nc_vector create() { 
   nc_vector nc_temp;
   return BOOST_MOVE_RET(nc_vector, nc_temp);
} 

workarounds the problem.

Note: See TracTickets for help on using tickets.