Skip to content

[libc++] Remove potential 0-sized array in __compressed_pair_padding #109028

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions libcxx/include/__format/format_arg_store.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,11 @@ struct __packed_format_arg_store {
uint64_t __types_ = 0;
};

template <class _Context>
struct __packed_format_arg_store<_Context, 0> {
uint64_t __types_ = 0;
};

template <class _Context, size_t _Np>
struct __unpacked_format_arg_store {
basic_format_arg<_Context> __args_[_Np];
Expand Down
11 changes: 7 additions & 4 deletions libcxx/include/__memory/compressed_pair.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,16 @@ _LIBCPP_BEGIN_NAMESPACE_STD

#ifndef _LIBCPP_ABI_NO_COMPRESSED_PAIR_PADDING

template <class _ToPad>
template <class _ToPad,
bool _Empty = ((is_empty<_ToPad>::value && !__libcpp_is_final<_ToPad>::value) ||
is_reference<_ToPad>::value || sizeof(_ToPad) == __datasizeof_v<_ToPad>)>
class __compressed_pair_padding {
char __padding_[((is_empty<_ToPad>::value && !__libcpp_is_final<_ToPad>::value) || is_reference<_ToPad>::value)
? 0
: sizeof(_ToPad) - __datasizeof_v<_ToPad>];
char __padding_[sizeof(_ToPad) - __datasizeof_v<_ToPad>];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we reuse the same __padding struct we now have in <string>?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed

};

template <class _ToPad>
class __compressed_pair_padding<_ToPad, true> {};

# define _LIBCPP_COMPRESSED_PAIR(T1, Initializer1, T2, Initializer2) \
_LIBCPP_NO_UNIQUE_ADDRESS __attribute__((__aligned__(_LIBCPP_ALIGNOF(T2)))) T1 Initializer1; \
_LIBCPP_NO_UNIQUE_ADDRESS ::std::__compressed_pair_padding<T1> _LIBCPP_CONCAT3(__padding1_, __LINE__, _); \
Expand Down
Loading