PR libstdc++/87544 limit max_size() to PTRDIFF_MAX / sizeof(T)
authorJonathan Wakely <jwakely@redhat.com>
Wed, 10 Oct 2018 15:39:33 +0000 (16:39 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Wed, 10 Oct 2018 15:39:33 +0000 (16:39 +0100)
commit422a9f77892599ecf8e498d0e5e32b1db3cab559
tree793ea99effcef869eeff038bf4f2893773e0b797
parentd3a46ecb386b46dfc8e01a2f50c77804e484c4c5
PR libstdc++/87544 limit max_size() to PTRDIFF_MAX / sizeof(T)

The C++17 standard requires the default implementation for
allocator_traits::max_size to return SIZE_MAX / sizeof(value_type).
That causes GCC to warn because the value could be larger than can
sensibly be passed to malloc. This patch changes the new_allocator and
malloc_allocator max_size() members to use PTRDIFF_MAX instead of
SIZE_MAX (and because they define it, the allocator_traits default isn't
used). This also changes vector::max_size to impose a sensible limit
using PTRDIFF_MAX for cases where the value from the allocator or
allocator_traits is not sensible.

PR libstdc++/87544
* include/bits/stl_vector.h (vector::_S_max_size): Limit size to
PTRDIFF_MAX / sizeof(value_type).
* include/ext/malloc_allocator.h (malloc_allocator::max_size):
Likewise.
* include/ext/new_allocator.h (new_allocator::max_size): Likewise.
* testsuite/23_containers/vector/allocator/minimal.cc: Adjust
expected value for max_size().
* testsuite/23_containers/vector/capacity/87544.cc: New test.

From-SVN: r265021
libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/stl_vector.h
libstdc++-v3/include/ext/malloc_allocator.h
libstdc++-v3/include/ext/new_allocator.h
libstdc++-v3/testsuite/23_containers/vector/allocator/minimal.cc
libstdc++-v3/testsuite/23_containers/vector/capacity/87544.cc [new file with mode: 0644]