[libcxx-commits] [PATCH] D122598: [libcxx] avoid using anonymous struct with base classes (fixes gcc-12)

Louis Dionne via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon Mar 28 11:09:41 PDT 2022


ldionne requested changes to this revision.
ldionne added inline comments.
This revision now requires changes to proceed.


================
Comment at: libcxx/include/string:707
         {
+            __padding<value_type> __padding_;
             unsigned char __size_;
----------------
This is an ABI break, since `__padding<char, 1>` is normally elided via the empty base optimization. This change prevents that from happening.

Instead, I believe we should give a name to this anonymous struct, since the lack thereof is non-standard and also pretty surprising. I would do:

```
struct __short
{
    value_type __data_[__min_cap];
    struct
        : __padding<value_type>
    {
        unsigned char __size_;
    } __padded_;
};
```

Then, you'll have to change places where we access `.__size_` directly into accessing `.__padded_.__size_` instead. Note that `__padded_` isn't a great name, but I couldn't think of anything better. Suggestions are welcome.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D122598/new/

https://reviews.llvm.org/D122598



More information about the libcxx-commits mailing list