Bug in GCC / libstdc++: Space character categorized as non-printable by std::ctype<wchar_t>
Kristian Spangsege
kristian.spangsege@gmail.com
Fri Jun 14 15:37:13 GMT 2024
In C++, a space character is reported as non-printable by
`std::ctype<wchar_t>` in the "C" locale (the only locale supported by
`std::ctype`). In other words, the following expression evaluates to
`false`:
ctype.is(std::ctype_base::print, ctype.widen(' '))
where `ctype` is obtained by `std::use_facet<std::ctype<wchar_t>>(loc)` and
`loc` is the "C" locale.
It should have been evaluated to `true` because a space character is
required by the C++ standard to be categorized as printable.
Also, it is reported as printable by `std::iswprint(int ch)`.
Also, the non-wide space character is reported as printable, i.e,
`std::use_facet<std::ctype<char>>(loc)::is(std::ctype_base::print, ' ')` is
`true`.
Also, `ctype.is(std::ctype_base::print, ctype.widen(' '))` is `true` with
MinGW, with GCC on Linux, and with Visual Studio.
The problem can be demonstrated with the code below in regular Cygwin (
https://cygwin.com/install.html) using GCC 12.3.1 and in the Cygwin
environment of MSYS2 (https://www.msys2.org/) using GCC 13.2.0:
#include <cwctype>
#include <string>
#include <locale>
#include <iostream>
int main()
{
using facet_type = std::ctype<wchar_t>;
std::locale loc;
const auto& ctype = std::use_facet<facet_type>(loc);
wchar_t ch = ctype.widen(' ');
std::cout << ctype.is(ctype.print, ch) << "\n";
std::cout << (std::iswprint(std::char_traits<wchar_t>::to_int_type(ch))
!= 0) << "\n";
}
Regards
Kristian Spangsege
More information about the Cygwin
mailing list