This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libstdc++/61458] std::aligned_storage is bigger than expected


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61458

Arthur O'Dwyer <arthur.j.odwyer at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |arthur.j.odwyer at gmail dot com

--- Comment #10 from Arthur O'Dwyer <arthur.j.odwyer at gmail dot com> ---
Could we revisit this issue? Libstdc++'s behavior here seems to be "conforming
but sadistic," in that it gratuitously breaks the ABI of user/library code that
assumes aligned_storage_t<Cap> is appropriately aligned for objects of size
Cap.

For example, SG14's "stdext::inplace_function" was recently declared as
follows:

  template<
    typename Signature,
    size_t Capacity = detail::InplaceFunctionDefaultCapacity,
    size_t Alignment =
std::alignment_of<std::aligned_storage_t<Capacity>>::value
  >
  class inplace_function;

This works great on Clang/libc++, but gives a different ABI on GCC/libstdc++
because on libstdc++ the default alignment is "always 16 bytes" instead of
"appropriately aligned for Capacity".

    using IPF = stdext::inplace_function<void(), 8>;
    if (sizeof(IPF) == 16) {
        puts("MSVC and libc++ pack aligned_storage_t appropriately!");
    } else if (sizeof(IPF) == 32) {
        puts("libstdc++ breaks ABI by adding lots of padding for no reason!");
    }

I'm not 100% sure yet, but it *seems* like the only workaround is for all
library writers to implement their own version of aligned_storage_t; the
standard version is not portable to platforms that use libstdc++.

Here is a conforming version of "aligned_storage", checked into the SG14 repo
as a workaround for the ongoing libstdc++ issue.
https://github.com/WG21-SG14/SG14/commit/98baf1aeab

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]