You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If one passes a fixed size char - array containing a 0-terminated string to std::format, the entire array minus one character is added to the result, instead of just the part until the null terminator. This not only seemingly violates [format.formatter.spec]/2.2, but also doesn't match the behavior of MS-STL or libstdc++. (And only formatting 49 characters out of a 50 character array seems buggy anyway.)
The issue is reproducible with all versions of libc++ that shipped with clang since <format> was added, including current trunk on godbolt.
The text was updated successfully, but these errors were encountered:
…arrays in formatting (#116571)
Currently, built-in `char`/`wchar_t` arrays are assumed to be
null-terminated sequence with the terminator being the last element in
formatting. This doesn't conform to [format.arg]/6.9.
> otherwise, if `decay_t<TD>` is `char_type*` or `const char_type*`,
> initializes value with `static_cast<const char_type*>(v)`;
The standard wording specifies that character arrays are decayed to
pointers. When the null terminator is not the last element or there's no
null terminator (the latter case is UB), libc++ currently produces
different results.
Also fixes and hardens `formatter<CharT[N], CharT>::format` in
`<__format/formatter_string.h>`. These specializations are rarely used.
Fixes#115935. Also checks the preconditions in this case, which fixes#116570.
Reproducer
If one passes a fixed size
char
- array containing a 0-terminated string tostd::format
, the entire array minus one character is added to the result, instead of just the part until the null terminator. This not only seemingly violates [format.formatter.spec]/2.2, but also doesn't match the behavior of MS-STL or libstdc++. (And only formatting 49 characters out of a 50 character array seems buggy anyway.)The issue is reproducible with all versions of libc++ that shipped with clang since
<format>
was added, including current trunk on godbolt.The text was updated successfully, but these errors were encountered: