This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ 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]

[patch] fix a couple of std::allocator_traits bugs


std::allocator_traits<A>::allocate(a, n, hint) could fail to compile
if the const_void_pointer passed as the hint was a non-trivial type,
because it was passed to a varargs function.

std::vector was not using std::allocator_traits<A> for calls to
A::allocate and A::deallocate.

Also remove some redundant conditions in std::vector and _Rb_tree and
in allocator_traits simplify SFINAE uses and use true_type / false_type
to avoid needing definitions for static const bool members.

I added PointerBase to testsuite_allocator.h to help create custom
pointer types for testing because it's non-trivial to define the whole
thing every time you need one. There's also a new test to verify the
allocator_traits typedefs are correct.

Tested x86_64-linux, committed to trunk.
(I didn't fix up some dg-error line numbers relating to stl_vector.h
because I'm also committing another patch that changes them again, so
I only did it once.)

       * include/bits/alloc_traits.h (allocator_traits::_S_allocate): Do
       not use varargs when argument could be non-POD.
       (__alloctr_rebind_helper): Eliminate static const bool member by
       using true_type and false_type.
       (allocator_traits::__allocate_helper): Likewise.
       (allocator_traits::__construct_helper): Likewise.
       (allocator_traits::__destroy_helper): Likewise.
       (allocator_traits::__maxsize_helper): Likewise.
       (allocator_traits::__select_helper): Likewise.
       * include/bits/ptr_traits.h (__ptrtr_rebind_helper): Likewise.
       * include/bits/stl_tree.h (_Rb_tree::operator=(const _Rb_tree&)):
       Remove redundant condition.
       * include/bits/stl_vector.h (vector::operator=(const vector&)):
       Likewise.
       (_Vector_impl::_M_allocate, _Vector_impl::_M_deallocate): Use
       indirection through __alloc_traits.
       * include/ext/alloc_traits.h (__allocator_always_compares_equal):
       Eliminate static const bool members by using true_type and false_type.
       (__gnu_cxx::__alloc_traits::__is_custom_pointer): Optimize.
       * testsuite/util/testsuite_allocator.h (PointerBase): Define.
       * testsuite/20_util/allocator_traits/members/allocate_hint_nonpod.cc:
       New.
       * testsuite/20_util/allocator_traits/requirements/typedefs2.cc: New.

Attachment: patch.txt
Description: Text document


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