public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "cvs-commit at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libstdc++/95048] [11 Regression] wstring-constructor of std::filesystem::path throws for non-ASCII characters
Date: Mon, 10 Jul 2023 15:47:22 +0000	[thread overview]
Message-ID: <bug-95048-4-Eahp2BVTSO@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-95048-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #26 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Jonathan Wakely
<redi@gcc.gnu.org>:

https://gcc.gnu.org/g:d308b11fa94728507984b4ccc949219511273ab6

commit r11-10903-gd308b11fa94728507984b4ccc949219511273ab6
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Fri Nov 11 15:22:02 2022 +0000

    libstdc++: Fix wstring conversions in filesystem::path [PR95048]

    In commit r9-7381-g91756c4abc1757 I changed filesystem::path to use
    std::codecvt<CharT, char, mbstate_t> for conversions from all wide
    strings to UTF-8, instead of using std::codecvt_utf8<CharT>. This was
    done because for 16-bit wchar_t, std::codecvt_utf8<wchar_t> only
    supports UCS-2 and not UTF-16. The rationale for the change was sound,
    but the actual fix was not. It's OK to use std::codecvt for char16_t or
    char32_t, because the specializations for those types always use UTF-8 ,
    but std::codecvt<wchar_t, char, mbstate_t> uses the current locale's
    encodings, and the narrow encoding is probably ASCII and can't support
    non-ASCII characters.

    The correct fix is to use std::codecvt only for char16_t and char32_t.
    For 32-bit wchar_t we could have continued using std::codecvt_utf8
    because that uses UTF-32 which is fine, switching to std::codecvt broke
    non-Windows targets with 32-bit wchar_t. For 16-bit wchar_t we did need
    to change, but should have changed to std::codecvt_utf8_utf16<wchar_t>
    instead, as that always uses UTF-16 not UCS-2. I actually noted that in
    the commit message for r9-7381-g91756c4abc1757 but didn't use that
    option. Oops.

    This replaces the unconditional std::codecvt<CharT, char, mbstate_t>
    with a type defined via template specialization, so it can vary
    depending on the wide character type. The code is also simplified to
    remove some of the mess of #ifdef and if-constexpr conditions.

    libstdc++-v3/ChangeLog:

            PR libstdc++/95048
            * include/bits/fs_path.h (path::_Codecvt): New class template
            that selects the kind of code conversion done.
            (path::_Codecvt<wchar_t>): Select based on sizeof(wchar_t).
            (_GLIBCXX_CONV_FROM_UTF8): New macro to allow the same code to
            be used for Windows and POSIX.
            (path::_S_convert(const EcharT*, const EcharT*)): Simplify by
            using _Codecvt and _GLIBCXX_CONV_FROM_UTF8 abstractions.
            (path::_S_str_convert(basic_string_view<value_type>, const A&)):
            Simplify nested conditions.
            * include/experimental/bits/fs_path.h (path::_Cvt): Define
            nested typedef controlling type of code conversion done.
            (path::_Cvt::_S_wconvert): Use new typedef.
            (path::string(const A&)): Likewise.
            * testsuite/27_io/filesystem/path/construct/95048.cc: New test.
            * testsuite/experimental/filesystem/path/construct/95048.cc: New
            test.

    (cherry picked from commit b331bf303bdc1edead41e2b3d11d1a7804b433cf)

  parent reply	other threads:[~2023-07-10 15:47 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-11  7:59 [Bug libstdc++/95048] New: " kontakt at neonfoto dot de
2020-05-11 20:49 ` [Bug libstdc++/95048] " redi at gcc dot gnu.org
2020-05-11 20:59 ` carlos at redhat dot com
2020-05-11 21:14 ` [Bug libstdc++/95048] [9/10/11 Regression] " redi at gcc dot gnu.org
2020-05-11 21:19 ` redi at gcc dot gnu.org
2020-05-11 21:25 ` redi at gcc dot gnu.org
2020-06-26 12:05 ` rguenth at gcc dot gnu.org
2020-11-12 13:48 ` gcc-bugzilla at m dot chronial.de
2020-11-12 13:58 ` redi at gcc dot gnu.org
2020-11-12 14:02 ` redi at gcc dot gnu.org
2020-11-12 23:49 ` gcc-bugzilla at m dot chronial.de
2021-01-14  8:44 ` rguenth at gcc dot gnu.org
2021-04-19 10:40 ` redi at gcc dot gnu.org
2021-06-01  8:17 ` [Bug libstdc++/95048] [9/10/11/12 " rguenth at gcc dot gnu.org
2021-07-23 12:40 ` gcc-bugzilla at m dot chronial.de
2021-10-19 13:25 ` redi at gcc dot gnu.org
2022-05-27  9:42 ` [Bug libstdc++/95048] [10/11/12/13 " rguenth at gcc dot gnu.org
2022-06-28 10:40 ` jakub at gcc dot gnu.org
2022-10-24 15:09 ` ulf.lorenz at ptvgroup dot com
2022-10-25 11:54 ` redi at gcc dot gnu.org
2022-10-25 12:47 ` ulf.lorenz at ptvgroup dot com
2022-11-11 17:43 ` cvs-commit at gcc dot gnu.org
2022-11-11 17:46 ` [Bug libstdc++/95048] [10/11/12 " redi at gcc dot gnu.org
2022-11-11 17:51 ` redi at gcc dot gnu.org
2022-11-11 22:29 ` cvs-commit at gcc dot gnu.org
2022-11-14 18:34 ` cvs-commit at gcc dot gnu.org
2022-11-22 11:51 ` [Bug libstdc++/95048] [10/11 " ulf.lorenz at ptvgroup dot com
2022-11-22 12:30 ` redi at gcc dot gnu.org
2023-07-07 10:37 ` [Bug libstdc++/95048] [11 " rguenth at gcc dot gnu.org
2023-07-10 15:47 ` cvs-commit at gcc dot gnu.org [this message]
2023-07-12 20:04 ` cvs-commit at gcc dot gnu.org
2023-07-12 20:16 ` cvs-commit at gcc dot gnu.org
2023-07-12 20:19 ` cvs-commit at gcc dot gnu.org
2023-07-12 20:23 ` cvs-commit at gcc dot gnu.org
2023-07-12 20:24 ` redi at gcc dot gnu.org

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-95048-4-Eahp2BVTSO@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).