https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70940
Jonathan Wakely <redi at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|ASSIGNED |RESOLVED Resolution|--- |FIXED Target Milestone|--- |9.0 --- Comment #9 from Jonathan Wakely <redi at gcc dot gnu.org> --- (In reply to Eric Fiselier from comment #0) > Furthermore it seems that do_allocate returns ill-aligned pointers. It seems > that do_allocate(s, a) returns the pointers from > 'Allocator<char>.allocate(...)' directly even though they have no alignment > guarantees. Fixed by allocating a buffer with additional space. The returned pointer is adjusted to the next alignment boundary, and a token is stored at the end of the allocated buffer to allow removing the adjustment to retrieve the original pointer for deallocation. (In reply to Jonathan Wakely from comment #1) > __null_memory_resource doesn't need to be a class template. Fixed by using a local class. > new_delete_resource() returns something that: > - doesn't have the required is_equal() behaviour. > - only uses new/delete if std::allocator uses __gnu_cxx::new_allocator. Fixed by using new_allocator directly. > And another one from Eric: > Your new_delete_resource() also unnecessarily pads the allocation size > before invoking ::operator new, but that isn't a real bug. I'm not going to fix that for the TS. Without C++17's aligned new we can't rely on calling new/delete directly (at least not for extended alignments). Going via resource_adaptor<__gnu_cxx::new_allocator> gives us the alignment guarantees, at the expense of some extra padding. I considered adding specialization to resource_adaptor so that when using new_allocator (or std::allocator when that uses new_allocator) it would avoid doing the padding for fundamental alignments. Maybe at a later date. For C++17's std::pmr::new_delete_resource() we can just use aligned new directly and don't need to wrap new_allocator<char> and over-allocate (and if the user uses -fno-aligned-new they don't get a new_delete_resource). Closing as fixed on trunk.