[Bug libstdc++/95048] New: wstring-constructor of std::filesystem::path throws for non-ASCII characters
kontakt at neonfoto dot de
gcc-bugzilla@gcc.gnu.org
Mon May 11 07:59:09 GMT 2020
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95048
Bug ID: 95048
Summary: wstring-constructor of std::filesystem::path throws
for non-ASCII characters
Product: gcc
Version: 10.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: kontakt at neonfoto dot de
Target Milestone: ---
When trying to port our Windows application to Linux, I encountered a problem
constructing an instance of std::filesystem::path with a wide-character literal
containing a non-ASCII wchar:
#include <filesystem>
int main()
{
std::filesystem::path p = L"ä";
}
This builds fine with g++-10 -Wall -Wextra -pedantic -std=c++17 minimal.cpp on
my Ubuntu 18.04 in WSL (using g++ from this ppa:
https://launchpad.net/~ubuntu-toolchain-r/+archive/ubuntu/test) but throws an
exception on execution:
terminate called after throwing an instance of
'std::filesystem::__cxx11::filesystem_error'
what(): filesystem error: Cannot convert character sequence: Invalid or
incomplete multibyte or wide character
Reading the C++ standard, I believe this should not happen and libstdc++ should
be able to convert the wchar literal to a path. Using clang with libc++ instead
of libstdc++ performs a conversion as I expected. Trying different versions of
g++ in the Compiler Explorer (https://godbolt.org/z/KQD1I6) shows that this
also used to work with g++9.1 and stopped working in g++9.2.
The problem was already described by someone else in this StackOverflow post:
https://stackoverflow.com/questions/58521857/cross-platform-way-to-handle-stdstring-stdwstring-with-stdfilesystempath
More information about the Gcc-bugs
mailing list