-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
<format>
: Fix STL internal check when formatting empty strings
#4243
<format>
: Fix STL internal check when formatting empty strings
#4243
Conversation
… internal check `_First < _Last` When `_First == _Last`, the iterator will compare equal to `default_sentinel_t` and the callsite `_Measure_string_prefix()` will do the right thing, we just need to avoid calling `_Decode_utf()` for an empty range. This will leave `_Next` as null, which is fine - we only need it when we increment the iterator. `_Measure_string_prefix_iterator_legacy` already appears to handle empty ranges correctly.
_Next = _Decode_utf(_First, _Last, _Val)._Next_ptr; | ||
if (_First != _Last) { | ||
_Next = _Decode_utf(_First, _Last, _Val)._Next_ptr; | ||
} | ||
} | ||
|
||
constexpr _Unicode_codepoint_iterator() = default; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Drive-by WTF: Why does line 364 check _Last == _Other._Last
when line 363 say it's a precondition? Should we fix that in another PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. I assume I wrote the INTERNAL_CHECK on a different side of a coffee break than the return statement :D
I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed. |
Fixes #4241. Test coverage will be provided by the upcoming libcxx update.
When
_First == _Last
, the iterator will compare equal todefault_sentinel_t
and the callsite_Measure_string_prefix()
will do the right thing, we just need to avoid calling_Decode_utf()
for an empty range. This will leave_Next
as null, which is fine - we only need it when we increment the iterator._Measure_string_prefix_iterator_legacy
already appears to handle empty ranges correctly.