[libcxx-commits] [libcxx] [libcxx] proper guarding for locale usage in filesystem on Windows (PR #165470)

Saleem Abdulrasool via libcxx-commits libcxx-commits at lists.llvm.org
Tue Oct 28 14:06:07 PDT 2025


================
@@ -24,28 +27,30 @@
 
 _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
 
+#  if !defined(_LIBCPP_WIN32API) || _LIBCPP_HAS_LOCALIZATION
----------------
compnerd wrote:

I wonder if this is better as a more complex change.

```cpp
#if _LIBCPP_HAS_LOCALIZATION
template <class _InputIt, __enable_if_t<__is_pathable<_InputIt>::value, int> = 0>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_DEPRECATED_WITH_CHAR8_T path u8path(_InputIt __f,
#if _LIBCPP_WIN32API
 _InputIt __l
#else
  _NullSentinel
#endif
) {
  static_assert(
#    if _LIBCPP_HAS_CHAR8_T
        is_same<typename __is_pathable<_InputIt>::__char_type, char8_t>::value ||
#    endif
            is_same<typename __is_pathable<_InputIt>::__char_type, char>::value,
        "u8path(Iter, Iter) requires Iter have a value_type of type 'char'"
        " or 'char8_t'");
#if _LIBCPP_WIN32API
  string __tmp(__f, __l);
#else
  string __tmp;
#endif
  const char __sentinel = char{};
  for (; *__f != __sentinel; ++__f)
    __tmp.push_back(*__f);
  using _CVT = __widen_from_utf8<sizeof(wchar_t) * __CHAR_BIT__>;
  std::wstring __w;
  __w.reserve(__tmp.size());
  _CVT()(back_inserter(__w), __tmp.data(), __tmp.data() + __tmp.size());
  return path(__w);
}
#endif
```

Of course this needs to be clang-formatted, but that is the general idea.

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


More information about the libcxx-commits mailing list