Skip to content

Commit 3e87719

Browse files
committed
[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
1 parent e9302bf commit 3e87719

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

libcxx/include/ios

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,8 @@ inline _LIBCPP_INLINE_VISIBILITY
781781
_CharT
782782
basic_ios<_CharT, _Traits>::fill(char_type __ch)
783783
{
784+
if (traits_type::eq_int_type(traits_type::eof(), __fill_))
785+
__fill_ = widen(' ');
784786
char_type __r = __fill_;
785787
__fill_ = __ch;
786788
return __r;

libcxx/test/std/input.output/iostreams.base/ios/basic.ios.members/fill_char_type.pass.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
int main(int, char**)
2121
{
2222
std::ios ios(0);
23-
assert(ios.fill() == ' ');
2423
char c = ios.fill('*');
2524
assert(c == ' ');
2625
assert(ios.fill() == '*');

0 commit comments

Comments
 (0)