[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:48:46 PDT 2025


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

Okay, but the general idea still holds; we can guard it with `#if !_LIBCPP_WIN32 || _LIBCPP_HAS_LOCALIZATION` instead, and adjust the body as well.

```cpp
#if !_LIBCPP_WIN32 || _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_HAS_LOCALIZATION
 _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_HAS_LOCALIZATION
   return path(__f, __l);
#else
    string __tmp(__f, __l);
    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
}
#endif
```

Sorry, doing this during the LLVM conference, so there might be more tweaks required.

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


More information about the libcxx-commits mailing list