[Bug libstdc++/95048] wstring-constructor of std::filesystem::path throws for non-ASCII characters

2020-05-11 Thread carlos at redhat dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95048

Carlos O'Donell  changed:

   What|Removed |Added

 CC||carlos at redhat dot com

--- Comment #2 from Carlos O'Donell  ---
(In reply to Jonathan Wakely from comment #1)
> This happens because glibc won't convert the wide string to UTF-8:
> 
> #include 
> #include 
> 
> int main()
> {
>   const wchar_t wstr[] = L"ä";
>   const wchar_t* from = wstr;
>   char to[10];
>   mbstate_t s;
>   size_t res = wcsnrtombs(to, , 1, sizeof(to), );
>   assert(res != (size_t)-1);
> }
> 
> I'm not yet sure why glibc refuses to convert that.

ISO C says:

"At program startup, the equivalent of
setlocale(LC_ALL, "C");
is executed."

Which means you are trying to convert UTF-8 to ASCII.

You should call setlocale with a non-ASCII character set to make this work.

[Bug libstdc++/95048] wstring-constructor of std::filesystem::path throws for non-ASCII characters

2020-05-11 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95048

Jonathan Wakely  changed:

   What|Removed |Added

 Ever confirmed|0   |1
 Status|UNCONFIRMED |NEW
   Last reconfirmed||2020-05-11

--- Comment #1 from Jonathan Wakely  ---
This happens because glibc won't convert the wide string to UTF-8:

#include 
#include 

int main()
{
  const wchar_t wstr[] = L"ä";
  const wchar_t* from = wstr;
  char to[10];
  mbstate_t s;
  size_t res = wcsnrtombs(to, , 1, sizeof(to), );
  assert(res != (size_t)-1);
}

I'm not yet sure why glibc refuses to convert that.