https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87544
--- Comment #18 from Jonathan Wakely <redi at gcc dot gnu.org> --- Author: redi Date: Wed Oct 10 15:39:33 2018 New Revision: 265021 URL: https://gcc.gnu.org/viewcvs?rev=265021&root=gcc&view=rev Log: 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. Added: trunk/libstdc++-v3/testsuite/23_containers/vector/capacity/87544.cc Modified: trunk/libstdc++-v3/ChangeLog trunk/libstdc++-v3/include/bits/stl_vector.h trunk/libstdc++-v3/include/ext/malloc_allocator.h trunk/libstdc++-v3/include/ext/new_allocator.h trunk/libstdc++-v3/testsuite/23_containers/vector/allocator/minimal.cc