[libcxx-commits] [libcxx] Properly implement std::fs::is_socket() on Windows (PR #213233)

via libcxx-commits libcxx-commits at lists.llvm.org
Fri Jul 31 02:30:08 PDT 2026


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff origin/main HEAD --extensions cpp,h -- libcxx/src/filesystem/posix_compat.h libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.is_socket/is_socket.pass.cpp libcxx/test/support/filesystem_test_helper.h --diff_from_common_commit
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.is_socket/is_socket.pass.cpp b/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.is_socket/is_socket.pass.cpp
index 18e5a1967..15b39954a 100644
--- a/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.is_socket/is_socket.pass.cpp
+++ b/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.is_socket/is_socket.pass.cpp
@@ -67,26 +67,25 @@ static void test_exist_not_found()
     assert(is_socket(p) == false);
 }
 
-static void test_is_socket_for_real_socket()
-{
-    // Some platforms don't support creating socket files.
+static void test_is_socket_for_real_socket() {
+  // Some platforms don't support creating socket files.
 #if !defined(__FreeBSD__) && !defined(__APPLE__)
-    scoped_test_env env;
-    const path sock = env.create_socket("socket");
-
-    // A bound AF_UNIX socket file must be reported as a socket, without error.
-    // On Windows this is a regression test: the socket file is a reparse point
-    // that cannot be opened by following it, which previously made status()
-    // throw filesystem_error instead of reporting file_type::socket.
-    std::error_code ec = GetTestEC();
-    assert(is_socket(sock, ec) == true);
-    assert(!ec);
-
-    assert(is_socket(sock) == true);
-
-    assert(is_regular_file(sock) == false);
-    assert(is_directory(sock) == false);
-    assert(exists(sock) == true);
+  scoped_test_env env;
+  const path sock = env.create_socket("socket");
+
+  // A bound AF_UNIX socket file must be reported as a socket, without error.
+  // On Windows this is a regression test: the socket file is a reparse point
+  // that cannot be opened by following it, which previously made status()
+  // throw filesystem_error instead of reporting file_type::socket.
+  std::error_code ec = GetTestEC();
+  assert(is_socket(sock, ec) == true);
+  assert(!ec);
+
+  assert(is_socket(sock) == true);
+
+  assert(is_regular_file(sock) == false);
+  assert(is_directory(sock) == false);
+  assert(exists(sock) == true);
 #endif
 }
 
diff --git a/libcxx/test/support/filesystem_test_helper.h b/libcxx/test/support/filesystem_test_helper.h
index 45fdafeaf..bd7182b03 100644
--- a/libcxx/test/support/filesystem_test_helper.h
+++ b/libcxx/test/support/filesystem_test_helper.h
@@ -12,12 +12,12 @@
 #include <direct.h>
 // winsock2.h must be included before windows.h to avoid clashing with the
 // older winsock.h that windows.h would otherwise pull in.
-#include <winsock2.h> // for AF_UNIX sockets
-#include <afunix.h>
-#include <windows.h> // for CreateSymbolicLink, CreateHardLink
-#if defined(_MSC_VER)
-#pragma comment(lib, "ws2_32")
-#endif
+#  include <winsock2.h> // for AF_UNIX sockets
+#  include <afunix.h>
+#  include <windows.h> // for CreateSymbolicLink, CreateHardLink
+#  if defined(_MSC_VER)
+#    pragma comment(lib, "ws2_32")
+#  endif
 #endif
 
 #include <cassert>
@@ -373,13 +373,13 @@ struct scoped_test_env
       return file;
     }
 
-private:
+  private:
     static int WinsockInit() {
       WSADATA wsaData;
       return ::WSAStartup(MAKEWORD(2, 2), &wsaData);
     }
 
-public:
+  public:
 #endif
 
     fs::path test_root;

``````````

</details>


https://github.com/llvm/llvm-project/pull/213233


More information about the libcxx-commits mailing list