Hi,

This is to bump this for review. PR 99333 also affects OpenSCAD where a workaround has been done (https://github.com/openscad/openscad/pull/7222). So it would be great if this could be fixed.

I've tested the fix and it solves the issue. I have some comments though:
- The gnu.ver hunk no longer applies (GCC 16 already uses
  GLIBCXX_3.4.35).  The rest applies cleanly to master.

- operator+= now strips two characters from any root-name in the
  appended path, including "C:": path("dir\\") += path("C:file") gives
  components {dir} {} {file}.  Checking is_dir_sep(s[0]) first would
  avoid that.

- "\/server" isn't recognized as a root-name, because root_path()
  requires input[1] == input[0].  MSVC accepts mixed separators.

- Jonathan: is the new exported _M_is_unc_path() wanted?  Without it, a
  bare "\\server" is relative, but "\\server\share\..." is still
  absolute.

My testing was done on a GitHub runner (windows-latest, MSYS2 GCC 16.2.0, UCRT64 and MINGW64, https://github.com/kalj/congenial-tribble/actions/runs/44894793307). No regressions, and the new tests pass. On a real SMB share, is_absolute() is now true and absolute() leaves the path unchanged (it used to give "D:\localhost\..."). canonical() still fails on MINGW64, but that looks like PR 99311 rather than this patch. It's
not a full bootstrap.

I include a patch for some additional tests (implemented with help from Claude Code as indicated in the patch). These test +=, lexically_normal and lexically_relative, the \\?\ and \\.\ prefixes, and absolute(). They pass with your fix and fail without it. Feel free to include them.

Claude was also used during the investigation.

I'd be happy to test an updated version too.

Regards,
Karl
From 5a168df5ed02b9d1301d282174f8b08660bd6f12 Mon Sep 17 00:00:00 2001
From: Karl Ljungkvist <[email protected]>
Date: Sat, 21 Nov 2026 10:26:28 +0000
Subject: [PATCH] libstdc++: Add more tests for UNC paths on Windows [PR99333]

Add tests for UNC paths that cover concatenation, lexically_normal,
lexically_relative, the \\?\ and \\.\ prefixes, paths with three
leading separators, and filesystem::absolute.

Assisted-by: Claude Opus 5.5
Signed-off-by: Karl Ljungkvist <[email protected]>

libstdc++-v3/ChangeLog:

	PR libstdc++/99333
	* testsuite/27_io/filesystem/path/decompose/99333.cc: New test.
---
 .../27_io/filesystem/path/decompose/99333.cc  | 161 ++++++++++++++++++
 1 file changed, 161 insertions(+)
 create mode 100644 libstdc++-v3/testsuite/27_io/filesystem/path/decompose/99333.cc

diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/99333.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/99333.cc
new file mode 100644
index 000000000..4165d515e
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/99333.cc
@@ -0,0 +1,161 @@
+// { dg-do run { target { *-*-*mingw* } } }
+// { dg-require-effective-target c++17 }
+
+// PR libstdc++/99333 std::filesystem::path does not handle UNC paths
+
+#include <filesystem>
+#include <vector>
+#include <testsuite_hooks.h>
+#include <testsuite_fs.h>
+
+using std::filesystem::path;
+using __gnu_test::compare_paths;
+
+void
+test_decompose()
+{
+  path p = L"\\\\server\\share\\dir\\file.txt";
+  VERIFY( p.has_root_name() );
+  VERIFY( p.root_name() == L"\\\\server" );
+  VERIFY( p.root_directory() == L"\\" );
+  VERIFY( p.root_path() == L"\\\\server\\" );
+  VERIFY( p.relative_path() == L"share\\dir\\file.txt" );
+  VERIFY( p.parent_path() == L"\\\\server\\share\\dir" );
+  VERIFY( p.filename() == L"file.txt" );
+  VERIFY( p.is_absolute() );
+
+  std::vector<path> v(p.begin(), p.end());
+  std::vector<path> v2
+    = { L"\\\\server", L"\\", L"share", L"dir", L"file.txt" };
+  VERIFY( v == v2 );
+
+  p = L"//server/share";
+  VERIFY( p.root_name() == L"//server" );
+  VERIFY( p.root_directory() == L"/" );
+  VERIFY( p.relative_path() == L"share" );
+  VERIFY( p.is_absolute() );
+
+  // A root-name with no root-directory.
+  p = L"\\\\server";
+  VERIFY( p.has_root_name() );
+  VERIFY( p.root_name() == p );
+  VERIFY( ! p.has_root_directory() );
+  VERIFY( ! p.has_relative_path() );
+  VERIFY( ! p.has_filename() );
+
+  // Three or more separators is just a root-directory.
+  p = L"\\\\\\server\\share";
+  VERIFY( ! p.has_root_name() );
+  VERIFY( p.root_directory() == L"\\" );
+  VERIFY( p.relative_path() == L"server\\share" );
+
+  // Win32 file namespace and device namespace prefixes.
+  p = L"\\\\?\\C:\\dir";
+  VERIFY( p.root_name() == L"\\\\?" );
+  VERIFY( p.root_directory() == L"\\" );
+  VERIFY( p.relative_path() == L"C:\\dir" );
+  p = L"\\\\.\\COM1";
+  VERIFY( p.root_name() == L"\\\\." );
+  VERIFY( p.relative_path() == L"COM1" );
+}
+
+void
+test_append()
+{
+  path p = L"\\\\server";
+  p /= L"share";
+  VERIFY( p.native() == L"\\\\server\\share" );
+  VERIFY( p.root_name() == L"\\\\server" );
+  VERIFY( p.relative_path() == L"share" );
+
+  p = L"\\\\server";
+  p /= path(L"share");
+  VERIFY( p.native() == L"\\\\server\\share" );
+
+  p = L"\\\\server\\share";
+  p /= L"\\dir";
+  VERIFY( p.native() == L"\\\\server\\dir" );
+  p = L"\\\\server\\share";
+  p /= path(L"\\dir");
+  VERIFY( p.native() == L"\\\\server\\dir" );
+
+  p = L"C:\\dir";
+  p /= L"\\\\server\\share";
+  VERIFY( p.native() == L"\\\\server\\share" );
+  p = L"\\\\server\\share";
+  p /= L"\\\\other\\dir";
+  VERIFY( p.native() == L"\\\\other\\dir" );
+  p = L"\\\\server\\share";
+  p /= path(L"\\\\other\\dir");
+  VERIFY( p.native() == L"\\\\other\\dir" );
+
+  p = L"\\\\server\\share";
+  p /= L"dir";
+  compare_paths( p, L"\\\\server\\share\\dir" );
+}
+
+void
+test_concat()
+{
+  path p = L"\\";
+  p += L"\\server";
+  VERIFY( p.root_name() == L"\\\\server" );
+  p = L"\\";
+  p += path(L"\\server");
+  VERIFY( p.root_name() == L"\\\\server" );
+
+  p = L"\\\\server";
+  p += L"\\share";
+  compare_paths( p, L"\\\\server\\share" );
+  p = L"\\\\server";
+  p += path(L"\\share");
+  compare_paths( p, L"\\\\server\\share" );
+
+  p = L"dir";
+  p += path(L"\\\\server\\share");
+  compare_paths( p, L"dir\\\\server\\share" );
+}
+
+void
+test_generic()
+{
+  VERIFY( path(L"\\\\server").generic_wstring() == L"//server" );
+  VERIFY( path(L"\\\\server\\share\\dir").generic_wstring()
+	    == L"//server/share/dir" );
+  VERIFY( path(L"\\\\server\\share\\dir").generic_string()
+	    == "//server/share/dir" );
+}
+
+void
+test_generation()
+{
+  path p = L"\\\\server\\share\\..\\dir\\.\\file";
+  compare_paths( p.lexically_normal(), L"\\\\server\\dir\\file" );
+  p = L"//server/share/../..";
+  compare_paths( p.lexically_normal(), L"\\\\server\\" );
+
+  p = L"\\\\server\\share\\a\\b";
+  compare_paths( p.lexically_relative(L"\\\\server\\share\\c"),
+		 L"..\\a\\b" );
+  compare_paths( p.lexically_relative(L"\\\\other\\share\\c"), L"" );
+  compare_paths( p.lexically_relative(L"C:\\share\\c"), L"" );
+  compare_paths( p.lexically_relative(L"\\share\\c"), L"" );
+}
+
+void
+test_absolute()
+{
+  path p = L"\\\\server\\share\\dir";
+  VERIFY( std::filesystem::absolute(p) == p );
+}
+
+int
+main()
+{
+  test_decompose();
+  test_append();
+  test_concat();
+  test_generic();
+  test_generation();
+  test_absolute();
+}
-- 
2.43.0

Reply via email to