Open manxorist opened 2 years ago
Improved readability with a raw string literal:
C:\Temp>type meow.cpp
#include <filesystem>
#include <iostream>
using namespace std;
int main() {
try {
cout << filesystem::weakly_canonical(R"(\\?\UNC\server\share\dir\name.ext)").string() << endl;
} catch (const filesystem::filesystem_error& e) {
cout << e.what() << endl;
}
}
C:\Temp>cl /EHsc /nologo /W4 /MTd /std:c++17 meow.cpp && meow
meow.cpp
weakly_canonical: Incorrect function.: "\\?\UNC\server\share\dir\name.ext"
The error is happening here:
https://github.com/microsoft/STL/blob/ad80eb79ba4953e7529d15b1bc8d0b540150bf7d/stl/inc/filesystem#L4075-L4089
We've called _Canonical()
with LR"(\\?\UNC)"
and it has failed with _Invalid_function
.
Potentially related / involving similar issues: #2256 and LWG-3699 "lexically_relative
on UNC drive paths (\\?\C:\...
) results in a default-constructed value".
Describe the bug
std::filesystem::weakly_canonical
fails for UNC path with\\?\UNC
prefix.Command-line test case
(https://godbolt.org/z/v83fbPfrW)
Expected behavior
weakly_canonical
does work for plain UNC paths without\\?\UNC
prefix, so I think it should also work for prefixed ones:(https://godbolt.org/z/rEdMvWs7h)
https://github.com/microsoft/STL/blob/7f04137880e1c3df5125c1baf808f16f399dee2e/stl/inc/filesystem#L420 talks about this prefix, so I would assume
std::filesystem
to be aware of it.