This patch updates allocate_shared to call allocator_traits::construct when creating the object held inside the shared_pointer, and allocator_traits::destroy when destroying it. This resolves the part of P0674R1 that was originally filed as LWG2070.
This change is landed separately from the rest of P0674R1 because it is incredibly tricky from an ABI perspective.
This is the reason why this change is so tricky, as explained in the code:
Prior to C++20 (or if the compiler doesn't support [[no_unique_address]]), we use an implementation that performs EBO for both the allocator and the object type stored in the `shared_ptr`. This is the original implementation that has been used in libc++, and we must be ABI compatible with it. Starting in C++20, P0674 requires us to use Allocator construction for initializing the object type. That requirement rules out the use of the EBO for the object type, since using the EBO implies that the base will be initialized when the control block is initialized (and hence we can't do it through Allocator construction). Hence, supporting P0674 requires changing how we store the object type inside the control block, which we do while being ABI compatible by using [[no_unique_address]].
To achieve ABI compatibility, this patch implements an ABI-compatible type equivalent to __compressed_pair, but where the data member is stored in a union, and hence available to be initialized via Allocator construction. The tricky part with this emulation is that it needs to be 100% ABI compatible with __compressed_pair, which means also emulating its drawbacks, such as the inability to elide storage for final classes.
Fixes https://llvm.org/PR41900
Supersedes https://llvm.org/D62760
This reminds me that we should support/test move-only allocator types.