[libc++] Fix initialization of __fill_

`basic_ios` delays initialization of `__fill_` to `widen(' ')` until `fill()` is called. But, `fill(char_type)` is missing this logic, so the fill character does not get initialized to whitespace if `fill(char_type)` is called first. This patch adds this logic to `fill(char_type)`.

Reviewed By: #libc, ldionne, Quuxplusone

Differential Revision: https://reviews.llvm.org/D120751
This commit is contained in:
Jake Egan 2022-03-03 09:28:23 -05:00
parent e9302bf7ef
commit 3e87719177
2 changed files with 2 additions and 1 deletions

View File

@ -781,6 +781,8 @@ inline _LIBCPP_INLINE_VISIBILITY
_CharT
basic_ios<_CharT, _Traits>::fill(char_type __ch)
{
if (traits_type::eq_int_type(traits_type::eof(), __fill_))
__fill_ = widen(' ');
char_type __r = __fill_;
__fill_ = __ch;
return __r;

View File

@ -20,7 +20,6 @@
int main(int, char**)
{
std::ios ios(0);
assert(ios.fill() == ' ');
char c = ios.fill('*');
assert(c == ' ');
assert(ios.fill() == '*');