Skip to content

Commit eee2f02

Browse files
authored
[libc++][modules] Get rid of <cstddef> dependency in __datasizeof (#107394)
All the compilers we support also provide __builtin_offsetof, so avoid using this macro and use the builtin directly instead. This allows removing a dependency on `<cstddef>`, which is heavier than we need.
1 parent 953af0e commit eee2f02

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

libcxx/include/__type_traits/datasizeof.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
#define _LIBCPP___TYPE_TRAITS_DATASIZEOF_H
1111

1212
#include <__config>
13+
#include <__cstddef/size_t.h>
1314
#include <__type_traits/is_class.h>
1415
#include <__type_traits/is_final.h>
15-
#include <cstddef>
1616

1717
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1818
# pragma GCC system_header
@@ -37,15 +37,15 @@ struct _FirstPaddingByte {
3737
char __first_padding_byte_;
3838
};
3939

40-
// _FirstPaddingByte<> is sometimes non-standard layout. Using `offsetof` is UB in that case, but GCC and Clang allow
41-
// the use as an extension.
40+
// _FirstPaddingByte<> is sometimes non-standard layout.
41+
// It is conditionally-supported to use __builtin_offsetof in that case, but GCC and Clang allow it.
4242
_LIBCPP_DIAGNOSTIC_PUSH
4343
_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Winvalid-offsetof")
4444
_LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Winvalid-offsetof")
4545
template <class _Tp>
46-
inline const size_t __datasizeof_v = offsetof(_FirstPaddingByte<_Tp>, __first_padding_byte_);
46+
inline const size_t __datasizeof_v = __builtin_offsetof(_FirstPaddingByte<_Tp>, __first_padding_byte_);
4747
_LIBCPP_DIAGNOSTIC_POP
48-
#endif // __has_extension(datasizeof)
48+
#endif // __has_extension(datasizeof)
4949

5050
_LIBCPP_END_NAMESPACE_STD
5151

0 commit comments

Comments
 (0)