This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libstdc++/50118] New: node-based containers cannot use allocators with explicit constructor template


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50118

             Bug #: 50118
           Summary: node-based containers cannot use allocators with
                    explicit constructor template
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Keywords: rejects-valid
          Severity: normal
          Priority: P3
         Component: libstdc++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: redi@gcc.gnu.org


#include <memory>
#include <list>
#include <set>
#include <map>

template <class T>
struct Alloc : std::allocator<T>
{
    Alloc() { }

    template<class U>
        explicit   //  N.B. explicit ******
        Alloc(const Alloc<U>&) { }

    template<class U>
        struct rebind
        { typedef Alloc<U> other; };
};

Alloc<int> a;

std::list<int, Alloc<int> > l(a);

typedef std::less<int> Cmp;
Cmp cmp;

std::set<int, Cmp, Alloc<int> > s(cmp, a);
std::map<int, int, Cmp, Alloc<int> > m(cmp, a);

As far as I can tell there is no requirement in the standard that says Alloc<T>
must be implicitly convertible to Alloc<U>, so the node-based containers which
rebind allocators from Alloc<value_type> to Alloc<node_type> need to convert
explicitly

e.g. in stl_list.h

       _List_base(const allocator_type& __a)
-      : _M_impl(__a)
+      : _M_impl(_Node_alloc_type(__a))
       { _M_init(); }

Alternatively, _List_base::_List_impl could be constructible from the original
allocator_type and do the conversion there


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]