Reputation: 733
I have clang 15.0.7 installed with brew in MacOS and the same version installed with MSYS2 in Windows 10.
When I compile the following program:
#include <filesystem>
int main()
{
std::filesystem::path p("/some/path");
std::string s(p);
}
using clang++ -std=c++20 test.cpp
I get no compilation errors on MacOS, but in windows it gives:
test.cpp:6:15 error: no matching constructor for initialization of 'std::string' (aka 'basic_string<char>')
std::string s(p);
^ ~
[more errors]
What is going on?
Upvotes: 2
Views: 80
Reputation: 96719
std::filesystem::path::value_type
is wchar_t
on Windows and char
elsewhere.
Hence, std::filesystem::path
has a conversion operator to std::wstring
on Windows and to std::string
elsewhere (who even thought this was a good idea?!).
Call .string()
to get std::string
in a "portable" manner.
On Windows, make sure to test UTF-8 support on all standard library flavors you're interested in (MSVC STL, GCC's libstdc++, Clang's libc++). I remember that at least on MSVC you had to enable UTF-8 support with a locale, or use std::u8string
.
Upvotes: 5