From ad4481fa00369f8ce043d326daf80bb349b0c99a Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Sat, 2 Dec 2023 20:24:17 -0500 Subject: Source: Enhance check for C++17 filesystem support * Add `lexically_normal` test for all platforms. * On Windows, MinGW does not currently handle `lexically_normal()` correctly on UNC path, but MSVC and IntelLLVM do--add a comment on this to avoid future confusion. * Add test with `\\?\` notation and `weakly_canonical` that also triggers the MinGW bug, but is fine with MSVC and oneAPI, for a more robust and comprehensive test. --- Source/Checks/cm_cxx_filesystem.cxx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Source/Checks/cm_cxx_filesystem.cxx b/Source/Checks/cm_cxx_filesystem.cxx index c8df589..bdc7c6d 100644 --- a/Source/Checks/cm_cxx_filesystem.cxx +++ b/Source/Checks/cm_cxx_filesystem.cxx @@ -9,12 +9,13 @@ int main() std::filesystem::path p0(L"/a/b/c"); std::filesystem::path p1("/a/b/c"); - std::filesystem::path p2("/a/b/c"); - if (p1 != p2) { + std::filesystem::path p2("/a/b//c"); + if (p1 != p2.lexically_normal()) { return 1; } #if defined(_WIN32) + // "//host/" is not preserved in some environments like GNU under MinGW. std::filesystem::path p3("//host/a/b/../c"); if (p3.lexically_normal().generic_string() != "//host/a/c") { return 1; @@ -24,6 +25,12 @@ int main() if (p4.lexically_normal().generic_string() != "c:/a/") { return 1; } + + std::filesystem::path b1("C:\\path\\y\\..\\"); + if (std::filesystem::weakly_canonical("\\\\?\\C:\\path\\x\\..") != + b1.lexically_normal()) { + return 1; + } #endif // If std::string is copy-on-write, the std::filesystem::path -- cgit v0.12