diff options
| author | A. Jiang <de34@live.cn> | 2025-06-03 23:54:49 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-03 11:54:49 -0400 |
| commit | 769c42f4a552a75c8c38870ddc1b50d2ea874e4e (patch) | |
| tree | 512c741aca856780d500276025e812f0b95c8d4f /libcxx/include/__memory | |
| parent | 6ca59aae8e13168467f743c749a36bd9c5074b41 (diff) | |
[libc++] Fix padding calculation for function reference types (#142125)
#109028 caused `sizeof` to be sometimes applied to function reference
types, which makes a program ill-formed. This PR handles reference types
by specializations to prevent such bogus `sizeof` expression to be
instantiated.
Fixes #142118.
Diffstat (limited to 'libcxx/include/__memory')
| -rw-r--r-- | libcxx/include/__memory/compressed_pair.h | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/libcxx/include/__memory/compressed_pair.h b/libcxx/include/__memory/compressed_pair.h index 38798a21fa3c..fb7b7b7afcc8 100644 --- a/libcxx/include/__memory/compressed_pair.h +++ b/libcxx/include/__memory/compressed_pair.h @@ -15,7 +15,6 @@ #include <__type_traits/datasizeof.h> #include <__type_traits/is_empty.h> #include <__type_traits/is_final.h> -#include <__type_traits/is_reference.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -63,9 +62,17 @@ inline const size_t __compressed_pair_alignment = _LIBCPP_ALIGNOF(_Tp); template <class _Tp> inline const size_t __compressed_pair_alignment<_Tp&> = _LIBCPP_ALIGNOF(void*); -template <class _ToPad, - bool _Empty = ((is_empty<_ToPad>::value && !__libcpp_is_final<_ToPad>::value) || - is_reference<_ToPad>::value || sizeof(_ToPad) == __datasizeof_v<_ToPad>)> +template <class _ToPad> +inline const bool __is_reference_or_unpadded_object = + (is_empty<_ToPad>::value && !__libcpp_is_final<_ToPad>::value) || sizeof(_ToPad) == __datasizeof_v<_ToPad>; + +template <class _Tp> +inline const bool __is_reference_or_unpadded_object<_Tp&> = true; + +template <class _Tp> +inline const bool __is_reference_or_unpadded_object<_Tp&&> = true; + +template <class _ToPad, bool _Empty = __is_reference_or_unpadded_object<_ToPad> > class __compressed_pair_padding { char __padding_[sizeof(_ToPad) - __datasizeof_v<_ToPad>] = {}; }; |
