-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[libc++] basic_ios<wchar_t> cannot store fill character WCHAR_MAX (#8…
…9305) `libcxx std::basic_ios` uses `WEOF` to indicate the `fill` value is uninitialized. On some platforms (e.g AIX and zOS in 64-bit mode) `wchar_t` is 4 bytes `unsigned` and `wint_t` is also 4 bytes which means `WEOF` cannot be distinguished from `WCHAR_MAX` by `std::char_traits<wchar_t>::eq_int_type()`, meaning this valid character value cannot be stored on affected platforms (as the implementation triggers reinitialization to `widen(’ ’)`). This patch introduces a new helper class `_FillHelper` uses a boolean variable to indicate whether the fill character has been initialized, which is used by default in libcxx ABI version 2. The patch does not affect ABI version 1 except for targets AIX in 32- and 64-bit and z/OS in 64-bit (so that the layout of the implementation is compatible with the current IBM system provided libc++) This is a continuation of Phabricator patch [D124555](https://reviews.llvm.org/D124555). This patch uses a modified version of the [approach](https://reviews.llvm.org/D124555#3566746) suggested by @ldionne . --------- Co-authored-by: Louis Dionne <[email protected]> Co-authored-by: David Tenty <[email protected]>
- Loading branch information
1 parent
130ef73
commit 194f98c
Showing
6 changed files
with
92 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
libcxx/test/std/input.output/iostream.format/std.manip/setfill_wchar_max.pass.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// Test that WCHAR_MAX as a wchar_t value can be set as the fill character. | ||
|
||
// UNSUPPORTED: no-wide-characters | ||
|
||
// Expect the test case to fail on targets where WEOF is the same as | ||
// WCHAR_MAX with the libcpp ABI version 1 implementation. The libcpp ABI | ||
// version 2 implementation fixes the problem. | ||
|
||
// XFAIL: target={{.*}}-windows{{.*}} && libcpp-abi-version=1 | ||
// XFAIL: target=armv{{7|8}}l-linux-gnueabihf && libcpp-abi-version=1 | ||
// XFAIL: target=aarch64-linux-gnu && libcpp-abi-version=1 | ||
|
||
#include <iomanip> | ||
#include <ostream> | ||
#include <cassert> | ||
#include <string> | ||
|
||
template <class CharT> | ||
struct testbuf : public std::basic_streambuf<CharT> { | ||
testbuf() {} | ||
}; | ||
|
||
int main(int, char**) { | ||
testbuf<wchar_t> sb; | ||
std::wostream os(&sb); | ||
os << std::setfill((wchar_t)WCHAR_MAX); | ||
assert(os.fill() == (wchar_t)WCHAR_MAX); | ||
|
||
return 0; | ||
} |