Skip to content

Commit d95597d

Browse files
[libc++][string] Remove potential non-trailing 0-length array (#108867)
It is a violation of the standard to use 0 length arrays, especially when not at the end of a structure (not a FAM GNU extension). Compiler generally accept it, but it's probably better to have a conforming implementation. This is a re-application of #105865 which was reverted in 72cfc74 because it broke the data formatters. A LLDB patch has since been landed that should make this a non-issue. Co-authored-by: serge-sans-paille <[email protected]>
1 parent 0a7a1ef commit d95597d

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

Diff for: libcxx/include/string

+10-2
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,14 @@ struct __can_be_converted_to_string_view
749749
struct __uninitialized_size_tag {};
750750
struct __init_with_sentinel_tag {};
751751

752+
template <size_t _PaddingSize>
753+
struct __padding {
754+
char __padding_[_PaddingSize];
755+
};
756+
757+
template <>
758+
struct __padding<0> {};
759+
752760
template <class _CharT, class _Traits, class _Allocator>
753761
class basic_string {
754762
private:
@@ -853,7 +861,7 @@ private:
853861

854862
struct __short {
855863
value_type __data_[__min_cap];
856-
unsigned char __padding_[sizeof(value_type) - 1];
864+
_LIBCPP_NO_UNIQUE_ADDRESS __padding<sizeof(value_type) - 1> __padding_;
857865
unsigned char __size_ : 7;
858866
unsigned char __is_long_ : 1;
859867
};
@@ -905,7 +913,7 @@ private:
905913
unsigned char __is_long_ : 1;
906914
unsigned char __size_ : 7;
907915
};
908-
char __padding_[sizeof(value_type) - 1];
916+
_LIBCPP_NO_UNIQUE_ADDRESS __padding<sizeof(value_type) - 1> __padding_;
909917
value_type __data_[__min_cap];
910918
};
911919

0 commit comments

Comments
 (0)