Skip to content

Commit 5afac07

Browse files
committed
[libcxx] proper guarding for locale usage in filesystem on Windows
- Resolves build issues when localization support is disabled on Windows. - Resolves dependencies on localization in filesystem header implementations. Related PR llvm#164602 Fixes llvm#164074
1 parent d0e0d7f commit 5afac07

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

libcxx/include/__filesystem/path.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ struct _PathCVT<char> {
324324
}
325325
};
326326

327+
# if _LIBCPP_HAS_LOCALIZATION
327328
template <class _ECharT>
328329
struct _PathExport {
329330
typedef __narrow_to_utf8<sizeof(wchar_t) * __CHAR_BIT__> _Narrower;
@@ -364,7 +365,7 @@ struct _PathExport<char16_t> {
364365
}
365366
};
366367

367-
# if _LIBCPP_HAS_CHAR8_T
368+
# if _LIBCPP_HAS_CHAR8_T
368369
template <>
369370
struct _PathExport<char8_t> {
370371
typedef __narrow_to_utf8<sizeof(wchar_t) * __CHAR_BIT__> _Narrower;
@@ -374,8 +375,9 @@ struct _PathExport<char8_t> {
374375
_Narrower()(back_inserter(__dest), __src.data(), __src.data() + __src.size());
375376
}
376377
};
377-
# endif // _LIBCPP_HAS_CHAR8_T
378-
# endif /* _LIBCPP_WIN32API */
378+
# endif // _LIBCPP_HAS_CHAR8_T
379+
# endif // _LIBCPP_HAS_LOCALIZATION
380+
# endif // _LIBCPP_WIN32API
379381

380382
class _LIBCPP_EXPORTED_FROM_ABI path {
381383
template <class _SourceOrIter, class _Tp = path&>

libcxx/include/__filesystem/u8path.h

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,30 @@
2424

2525
_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
2626

27+
# if !defined(_LIBCPP_WIN32API) || _LIBCPP_HAS_LOCALIZATION
2728
template <class _InputIt, __enable_if_t<__is_pathable<_InputIt>::value, int> = 0>
2829
_LIBCPP_HIDE_FROM_ABI _LIBCPP_DEPRECATED_WITH_CHAR8_T path u8path(_InputIt __f, _InputIt __l) {
2930
static_assert(
30-
# if _LIBCPP_HAS_CHAR8_T
31+
# if _LIBCPP_HAS_CHAR8_T
3132
is_same<typename __is_pathable<_InputIt>::__char_type, char8_t>::value ||
32-
# endif
33+
# endif
3334
is_same<typename __is_pathable<_InputIt>::__char_type, char>::value,
3435
"u8path(Iter, Iter) requires Iter have a value_type of type 'char'"
3536
" or 'char8_t'");
36-
# if defined(_LIBCPP_WIN32API)
37+
# if defined(_LIBCPP_WIN32API)
3738
string __tmp(__f, __l);
3839
using _CVT = __widen_from_utf8<sizeof(wchar_t) * __CHAR_BIT__>;
3940
std::wstring __w;
4041
__w.reserve(__tmp.size());
4142
_CVT()(back_inserter(__w), __tmp.data(), __tmp.data() + __tmp.size());
4243
return path(__w);
43-
# else
44+
# else
4445
return path(__f, __l);
45-
# endif /* !_LIBCPP_WIN32API */
46+
# endif // defined(_LIBCPP_WIN32API)
4647
}
48+
# endif // !defined(_LIBCPP_WIN32API) || _LIBCPP_HAS_LOCALIZATION
4749

48-
# if defined(_LIBCPP_WIN32API)
50+
# if defined(_LIBCPP_WIN32API) && _LIBCPP_HAS_LOCALIZATION
4951
template <class _InputIt, __enable_if_t<__is_pathable<_InputIt>::value, int> = 0>
5052
_LIBCPP_HIDE_FROM_ABI _LIBCPP_DEPRECATED_WITH_CHAR8_T path u8path(_InputIt __f, _NullSentinel) {
5153
static_assert(
@@ -65,7 +67,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_DEPRECATED_WITH_CHAR8_T path u8path(_InputIt __f,
6567
_CVT()(back_inserter(__w), __tmp.data(), __tmp.data() + __tmp.size());
6668
return path(__w);
6769
}
68-
# endif /* _LIBCPP_WIN32API */
70+
# endif // defined(_LIBCPP_WIN32API) && _LIBCPP_HAS_LOCALIZATION
6971

7072
template <class _Source, __enable_if_t<__is_pathable<_Source>::value, int> = 0>
7173
_LIBCPP_HIDE_FROM_ABI _LIBCPP_DEPRECATED_WITH_CHAR8_T path u8path(const _Source& __s) {
@@ -81,7 +83,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_DEPRECATED_WITH_CHAR8_T path u8path(const _Source&
8183
return u8path(std::__unwrap_iter(_Traits::__range_begin(__s)), std::__unwrap_iter(_Traits::__range_end(__s)));
8284
# else
8385
return path(__s);
84-
# endif
86+
# endif // defined(_LIBCPP_WIN32API)
8587
}
8688

8789
_LIBCPP_END_NAMESPACE_FILESYSTEM

0 commit comments

Comments
 (0)