[libcxx-commits] [PATCH] D128285: [libc++][AIX] Make basic_string layout compatible with earlier version

Nikolas Klauser via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Fri Jun 24 12:35:41 PDT 2022


philnik added inline comments.


================
Comment at: libcxx/include/string:758
 #endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
-
+    static_assert(sizeof(__long) == (sizeof(pointer) + 2 * sizeof(size_type) +
+                                     (sizeof(pointer) * ((2 * sizeof(size_type) - 1) / sizeof(pointer) + 1)) -
----------------
hubert.reinterpretcast wrote:
> This reduces to:
> ```
> ((2 * sizeof(size_type) - 1) / sizeof(pointer) + 2) * sizeof(pointer)
> ```
> but I think now that there are many other ways for this to go wrong (pointer requires less alignment than its size, alignment of size_type causes trailing padding, etc.).
> 
> Maybe:
> ```
> struct __long_size_ref {
>   size_type __x, __y;
>   pointer __z;
> };
> static_assert(sizeof(__long) == sizeof(__long_size_ref));
> ```
How about we just drop the `static_assert`? I've got a patch that adds tests which `static_assert`s the size and alignment of specific instantiations of `basic_string`. That's a lot more reliable than hoping to get the size and alignment right for user-defined types.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128285



More information about the libcxx-commits mailing list