[Bug libstdc++/106028] New: std::filesystem::path lacks conversion to native mbs

goughostt at gmail dot com gcc-bugzilla@gcc.gnu.org
Sun Jun 19 06:26:11 GMT 2022


            Bug ID: 106028
           Summary: std::filesystem::path lacks conversion to native mbs
           Product: gcc
           Version: 12.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: goughostt at gmail dot com
  Target Milestone: ---

The following assumes c++17 std.

With Windows (mingw): a path can be build with UTF-8 (`u8path`) or native mbs
(`path(const char*)`) and converted to UTF-8 string (`path.string()` and
It seems impossible to get a native mbs string back (easily).

I suggest `path.string()` to return the native mbs string instead.
That allows one to `printf` the path in Windows.
Otherwise, I cannot find an easy way (without explicit encoding conversion) for
a mingw cross-compiled binary to print paths to the Cmd console.

As I understand, the suggested change conforms to the standard.
And developers also noted this in the code (XXX):

      if (__str_codecvt_out_all(__wfirst, __wlast, __u8str, __cvt)) {
      if constexpr (is_same_v<_CharT, char>)
        return __u8str; // XXX assumes native ordinary encoding is UTF-8.
      else {

More information about the Gcc-bugs mailing list