public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "kristian.spangsege at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/115524] New: Cygwin: Space character categorized as non-printable by std::ctype<wchar_t>
Date: Mon, 17 Jun 2024 14:06:46 +0000	[thread overview]
Message-ID: <bug-115524-4@http.gcc.gnu.org/bugzilla/> (raw)

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115524

            Bug ID: 115524
           Summary: Cygwin: Space character categorized as non-printable
                    by std::ctype<wchar_t>
           Product: gcc
           Version: 13.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kristian.spangsege at gmail dot com
  Target Milestone: ---

Created attachment 58451
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=58451&action=edit
test.cpp Demonstrate the bug

On Cygwin, a space character is reported as non-printable by
`std::ctype<wchar_t>` in the "C" locale (the only locale supported by
libstdc+++ on Cygwin). 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 (the defining distinction
between a printable and a graphical character is that space is printable but
not graphical).

Also, the space character is reported as printable by `std::iswprint(int ch)`.
So it seems like the problem is specific to `libstdc++`.

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 (attached as `test.cpp`) 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";
}

                 reply	other threads:[~2024-06-17 14:06 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-115524-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).