[libcxx-commits] [libcxx] [libc++] Use __datasizeof for __libcpp_datasizeof if available (PR #72104)
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Sat Dec 23 02:22:48 PST 2023
https://github.com/philnik777 updated https://github.com/llvm/llvm-project/pull/72104
>From 2b0f11626dac4a1808d7c81886a34f4a06b9b52f Mon Sep 17 00:00:00 2001
From: Nikolas Klauser <nikolasklauser at berlin.de>
Date: Mon, 13 Nov 2023 11:28:40 +0100
Subject: [PATCH] [libc++] Use __datasizeof for __libcpp_datasizeof if
available
---
libcxx/include/__type_traits/datasizeof.h | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/libcxx/include/__type_traits/datasizeof.h b/libcxx/include/__type_traits/datasizeof.h
index 5688e3293a69eb5..628e2326c079774 100644
--- a/libcxx/include/__type_traits/datasizeof.h
+++ b/libcxx/include/__type_traits/datasizeof.h
@@ -28,13 +28,17 @@ _LIBCPP_BEGIN_NAMESPACE_STD
template <class _Tp>
struct __libcpp_datasizeof {
-#if __has_cpp_attribute(__no_unique_address__)
+#if __has_extension(datasizeof)
+ static const size_t value = __datasizeof(_Tp);
+#else
+// NOLINTNEXTLINE(readability-redundant-preprocessor) This is https://llvm.org/PR64825
+# if __has_cpp_attribute(__no_unique_address__)
template <class = char>
struct _FirstPaddingByte {
[[__no_unique_address__]] _Tp __v_;
char __first_padding_byte_;
};
-#else
+# else
template <bool = __libcpp_is_final<_Tp>::value || !is_class<_Tp>::value>
struct _FirstPaddingByte : _Tp {
char __first_padding_byte_;
@@ -45,7 +49,7 @@ struct __libcpp_datasizeof {
_Tp __v_;
char __first_padding_byte_;
};
-#endif
+# 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.
@@ -53,6 +57,7 @@ struct __libcpp_datasizeof {
_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Winvalid-offsetof")
static const size_t value = offsetof(_FirstPaddingByte<>, __first_padding_byte_);
_LIBCPP_DIAGNOSTIC_POP
+#endif // __has_extension(datasizeof)
};
_LIBCPP_END_NAMESPACE_STD
More information about the libcxx-commits
mailing list