https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118030
--- Comment #7 from Nathan Myers <ncm at gcc dot gnu.org> --- commit 14617bda37f8c7e2da8efa335b47b41332a559eb Author: Nathan Myers <[email protected]> Date: Tue May 26 10:41:27 2026 libstdc++: allocate_at_least ask only what it reports (P0401) allocate_at_least is rounding up the allocation request size to its default alignment, which may be more than an integral multiple of the object size requested. When the memory is freed, what the container reports it is freeing differs from the amount that was allocated. This patch rounds the request size back down to what will be reported to the caller. The algorithm to compute the allocation is altered in response to findings on godbolt.org, which indicate dropping to uint8 to perform the division is a pessimization everywhere other than x86. The new version emits code for multiplication, instead. In addition, the remaining -m32 test that failed under the new allocation method is fixed, and guards are added for building with -fno-aligned-new and for -fno-sized-deallocation. Tested on x86 -m64/-m32. libstdc++-v3/ChangeLog: * include/bits/new_allocator.h (allocate_at_least): Reduce allocation to match what is reported. * testsuite/20_util/allocator/allocate_at_least2.cc: Add tests. * testsuite/23_containers/vector/modifiers/insert_vs_emplace.cc: Fix, for -m32 and new allocation results.
