Opened 9 years ago
Closed 9 years ago
#9328 closed Bugs (wontfix)
Error initializing a boost:container's allocator with a reference.
Reported by: | Owned by: | Ion Gaztañaga | |
---|---|---|---|
Milestone: | To Be Determined | Component: | container |
Version: | Boost 1.54.0 | Severity: | Problem |
Keywords: | container scoped_allocator_adaptor | Cc: |
Description
Consider the following:
struct arena;
struct A : std::allocator<int> {
A(arena {} A(arena*) {}
};
typedef boost::container::vector<int,boost::container::scoped_allocator_adaptor<A> > avector;
void foo(arena a) {
avector v1(a); error: can't bind a mutable & to a const& avector v2(&a); fine avector v3(A(a)); fine avector v3(A(&a)); fine
}
The initialization of v1 generates the following compilation error (under GCC 4.4.7):
/opt/scidb/13.9/3rdparty/boost/include/boost/container/scoped_allocator.hpp: In constructor ‘boost::container::container_detail::scoped_allocator_adaptor_base<OuterAlloc, true, boost::container::container_detail::nat, boost::container::container_detail::nat, boost::container::container_detail::nat, boost::container::container_detail::nat, boost::container::container_detail::nat, boost::container::container_detail::nat, boost::container::container_detail::nat, boost::container::container_detail::nat, boost::container::container_detail::nat, boost::container::container_detail::nat>::scoped_allocator_adaptor_base(const OuterA2&) [with OuterA2 = ARENA, OuterAlloc = A]’: /opt/scidb/13.9/3rdparty/boost/include/boost/preprocessor/iteration/detail/local.hpp:34: instantiated from ‘boost::container::scoped_allocator_adaptor<OuterAlloc, P0, P1, P2, P3, P4, P5, P6, P7, P8, P9>::scoped_allocator_adaptor(const OuterA2&) [with OuterA2 = ARENA, OuterAlloc = A, Q0 = boost::container::container_detail::nat, Q1 = boost::container::container_detail::nat, Q2 = boost::container::container_detail::nat, Q3 = boost::container::container_detail::nat, Q4 = boost::container::container_detail::nat, Q5 = boost::container::container_detail::nat, Q6 = boost::container::container_detail::nat, Q7 = boost::container::container_detail::nat, Q8 = boost::container::container_detail::nat, Q9 = boost::container::container_detail::nat]’ /local/mem/src/tests/unit/ArenaUnitTests.h:743: instantiated from here /opt/scidb/13.9/3rdparty/boost/include/boost/container/scoped_allocator.hpp:890: error: no matching function for call to ‘A::A(const ARENA&)’ /local/mem/src/tests/unit/ArenaUnitTests.h:736: note: candidates are: A::A(ARENA*) /local/mem/src/tests/unit/ArenaUnitTests.h:735: note: A::A(ARENA&) /local/mem/src/tests/unit/ArenaUnitTests.h:734: note: A::A(const A&)
Notice that the implementation of scoped_allocator_adaptor is attempting to initialize the adaptor with a *const* reference to an ARENA when a mutable reference was in fact supplied to the container's constructor.
Change History (2)
comment:1 by , 9 years ago
Component: | None → container |
---|---|
Owner: | set to |
comment:2 by , 9 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
It's a limitation of Boost.Move. It only accepts const references or rvalue references for constructor forwarding. Otherwise it would need thousands of overloads for a dozen of arguments. It's a pain but supporting move semantics also for allocator was considered more important than this annoyance.