[libcxx-commits] [libcxx] [libc++] Replace `__compressed_pair` with `[[no_unique_address]]` (PR #76756)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Aug 29 09:50:18 PDT 2024
================
@@ -54,9 +54,13 @@ struct _FirstPaddingByte<_Tp, true> {
// the use as an extension.
_LIBCPP_DIAGNOSTIC_PUSH
----------------
ldionne wrote:
Patch for above:
```diff
diff --git a/libcxx/include/__type_traits/datasizeof.h b/libcxx/include/__type_traits/datasizeof.h
index 1b324e470d0b..657c7d917857 100644
--- a/libcxx/include/__type_traits/datasizeof.h
+++ b/libcxx/include/__type_traits/datasizeof.h
@@ -10,8 +10,6 @@
#define _LIBCPP___TYPE_TRAITS_DATASIZEOF_H
#include <__config>
-#include <__type_traits/is_class.h>
-#include <__type_traits/is_final.h>
#include <cstddef>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -30,25 +28,11 @@ _LIBCPP_BEGIN_NAMESPACE_STD
template <class _Tp>
inline const size_t __datasizeof_v = __datasizeof(_Tp);
#else
-// NOLINTNEXTLINE(readability-redundant-preprocessor) This is https://llvm.org/PR64825
-# if __has_cpp_attribute(__no_unique_address__)
template <class _Tp>
struct _FirstPaddingByte {
- [[__no_unique_address__]] _Tp __v_;
+ _LIBCPP_NO_UNIQUE_ADDRESS _Tp __v_;
char __first_padding_byte_;
};
-# else
-template <class _Tp, bool = __libcpp_is_final<_Tp>::value || !is_class<_Tp>::value>
-struct _FirstPaddingByte : _Tp {
- char __first_padding_byte_;
-};
-
-template <class _Tp>
-struct _FirstPaddingByte<_Tp, true> {
- _Tp __v_;
- char __first_padding_byte_;
-};
-# endif // __has_cpp_attribute(__no_unique_address__)
// _FirstPaddingByte<> is sometimes non-standard layout. Using `offsetof` is UB in that case, but GCC and Clang allow
// the use as an extension.
@@ -61,7 +45,7 @@ _LIBCPP_DIAGNOSTIC_POP
template <class _Tp>
inline const size_t __datasizeof_v<_Tp&> = __datasizeof_v<_Tp>;
-#endif // __has_extension(datasizeof)
+#endif // __has_extension(datasizeof)
_LIBCPP_END_NAMESPACE_STD
```
And this needs additional tests. Specifically, we found out that an empty and final type has `datasizeof == 1` when it should really have `datasizeof == 0`. This might be worth fixing on its own since this isn't related to this patch (in case e.g. this patch gets reverted).
https://github.com/llvm/llvm-project/pull/76756
More information about the libcxx-commits
mailing list