[libcxx-commits] [libcxx] [libc++][string] Remove potential non-trailing 0-length array (PR #105865)

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Wed Aug 28 00:58:19 PDT 2024


https://github.com/philnik777 commented:

> I have some questions and comments, but this generally LGTM. While I wouldn't go absolutely nuts to avoid using a compiler extension, I think it's better to strive towards using few-ish of those. I also think this is a good opportunity to do a small refactoring of `std::string`'s layout definition that has been on my mind for a while.
> 
> @philnik777 Please let me know if you feel strongly that this patch shouldn't move forward. I am weakly favourable to it, but I could also be convinced that the complexity isn't worth it.

The main reason I've been pushing back here is because I think there is a significantly simpler alternative and I don't think it's exactly urgent to remove the use of this extension. I know that the clang folks are thinking about removing it (since it is indeed heinous), but I'm not aware of anybody actively working on that at the moment.

Specifically, we could do
```c++
template <size_t _PaddingSize>
struct __padding {
  char __padding_[_PaddingSize];
};

template <>
struct __padding<0> {};
```

and then just have
```c++
struct __short {
  value_type __data_[__min_cap];
  _LIBCPP_NO_UNIQUE_ADDRESS __padding __padding_;
  unsigned char __size_ : 7;
  unsigned char __is_long_ : 1;
};
```
IMO this is significantly more readable.

But it requires the newer AppleClang.


https://github.com/llvm/llvm-project/pull/105865


More information about the libcxx-commits mailing list