Skip to content

Commit e3a7084

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 #164602 Fixes #164074
1 parent d0e0d7f commit e3a7084

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
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 & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <__algorithm/unwrap_iter.h>
1414
#include <__config>
1515
#include <__filesystem/path.h>
16+
1617
#include <__locale>
1718
#include <string>
1819

@@ -24,28 +25,30 @@
2425

2526
_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
2627

28+
# if !defined(_LIBCPP_WIN32API) || _LIBCPP_HAS_LOCALIZATION
2729
template <class _InputIt, __enable_if_t<__is_pathable<_InputIt>::value, int> = 0>
2830
_LIBCPP_HIDE_FROM_ABI _LIBCPP_DEPRECATED_WITH_CHAR8_T path u8path(_InputIt __f, _InputIt __l) {
2931
static_assert(
30-
# if _LIBCPP_HAS_CHAR8_T
32+
# if _LIBCPP_HAS_CHAR8_T
3133
is_same<typename __is_pathable<_InputIt>::__char_type, char8_t>::value ||
32-
# endif
34+
# endif
3335
is_same<typename __is_pathable<_InputIt>::__char_type, char>::value,
3436
"u8path(Iter, Iter) requires Iter have a value_type of type 'char'"
3537
" or 'char8_t'");
36-
# if defined(_LIBCPP_WIN32API)
38+
# if defined(_LIBCPP_WIN32API)
3739
string __tmp(__f, __l);
3840
using _CVT = __widen_from_utf8<sizeof(wchar_t) * __CHAR_BIT__>;
3941
std::wstring __w;
4042
__w.reserve(__tmp.size());
4143
_CVT()(back_inserter(__w), __tmp.data(), __tmp.data() + __tmp.size());
4244
return path(__w);
43-
# else
45+
# else
4446
return path(__f, __l);
45-
# endif /* !_LIBCPP_WIN32API */
47+
# endif /* !_LIBCPP_WIN32API */
4648
}
49+
# endif /* !_LIBCPP_WIN32API || _LIBCPP_HAS_LOCALIZATION */
4750

48-
# if defined(_LIBCPP_WIN32API)
51+
# if defined(_LIBCPP_WIN32API) && _LIBCPP_HAS_LOCALIZATION
4952
template <class _InputIt, __enable_if_t<__is_pathable<_InputIt>::value, int> = 0>
5053
_LIBCPP_HIDE_FROM_ABI _LIBCPP_DEPRECATED_WITH_CHAR8_T path u8path(_InputIt __f, _NullSentinel) {
5154
static_assert(
@@ -65,7 +68,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_DEPRECATED_WITH_CHAR8_T path u8path(_InputIt __f,
6568
_CVT()(back_inserter(__w), __tmp.data(), __tmp.data() + __tmp.size());
6669
return path(__w);
6770
}
68-
# endif /* _LIBCPP_WIN32API */
71+
# endif /* _LIBCPP_WIN32API && _LIBCPP_HAS_LOCALIZATION */
6972

7073
template <class _Source, __enable_if_t<__is_pathable<_Source>::value, int> = 0>
7174
_LIBCPP_HIDE_FROM_ABI _LIBCPP_DEPRECATED_WITH_CHAR8_T path u8path(const _Source& __s) {

0 commit comments

Comments
 (0)