Skip to content

Commit 005ac72

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 005ac72

File tree

2 files changed

+27
-21
lines changed

2 files changed

+27
-21
lines changed

libcxx/include/__filesystem/path.h

Lines changed: 4 additions & 2 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,7 +375,8 @@ 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_HAS_CHAR8_T
379+
# endif // _LIBCPP_HAS_LOCALIZATION
378380
# endif /* _LIBCPP_WIN32API */
379381

380382
class _LIBCPP_EXPORTED_FROM_ABI path {

libcxx/include/__filesystem/u8path.h

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313
#include <__algorithm/unwrap_iter.h>
1414
#include <__config>
1515
#include <__filesystem/path.h>
16+
17+
#if _LIBCPP_HAS_LOCALIZATION
1618
#include <__locale>
19+
#endif
1720
#include <string>
1821

1922
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -24,28 +27,30 @@
2427

2528
_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
2629

30+
# if !defined(_LIBCPP_WIN32API) || _LIBCPP_HAS_LOCALIZATION
2731
template <class _InputIt, __enable_if_t<__is_pathable<_InputIt>::value, int> = 0>
2832
_LIBCPP_HIDE_FROM_ABI _LIBCPP_DEPRECATED_WITH_CHAR8_T path u8path(_InputIt __f, _InputIt __l) {
2933
static_assert(
30-
# if _LIBCPP_HAS_CHAR8_T
31-
is_same<typename __is_pathable<_InputIt>::__char_type, char8_t>::value ||
32-
# endif
33-
is_same<typename __is_pathable<_InputIt>::__char_type, char>::value,
34-
"u8path(Iter, Iter) requires Iter have a value_type of type 'char'"
35-
" or 'char8_t'");
36-
# if defined(_LIBCPP_WIN32API)
37-
string __tmp(__f, __l);
38-
using _CVT = __widen_from_utf8<sizeof(wchar_t) * __CHAR_BIT__>;
39-
std::wstring __w;
40-
__w.reserve(__tmp.size());
41-
_CVT()(back_inserter(__w), __tmp.data(), __tmp.data() + __tmp.size());
42-
return path(__w);
43-
# else
44-
return path(__f, __l);
45-
# endif /* !_LIBCPP_WIN32API */
34+
# if _LIBCPP_HAS_CHAR8_T
35+
is_same<typename __is_pathable<_InputIt>::__char_type, char8_t>::value ||
36+
# endif
37+
is_same<typename __is_pathable<_InputIt>::__char_type, char>::value,
38+
"u8path(Iter, Iter) requires Iter have a value_type of type 'char'"
39+
" or 'char8_t'");
40+
# if defined(_LIBCPP_WIN32API)
41+
string __tmp(__f, __l);
42+
using _CVT = __widen_from_utf8<sizeof(wchar_t) * __CHAR_BIT__>;
43+
std::wstring __w;
44+
__w.reserve(__tmp.size());
45+
_CVT()(back_inserter(__w), __tmp.data(), __tmp.data() + __tmp.size());
46+
return path(__w);
47+
# else
48+
return path(__f, __l);
49+
# endif /* !_LIBCPP_WIN32API */
4650
}
51+
# endif /* !_LIBCPP_WIN32API || _LIBCPP_HAS_LOCALIZATION */
4752

48-
# if defined(_LIBCPP_WIN32API)
53+
# if defined(_LIBCPP_WIN32API) && _LIBCPP_HAS_LOCALIZATION
4954
template <class _InputIt, __enable_if_t<__is_pathable<_InputIt>::value, int> = 0>
5055
_LIBCPP_HIDE_FROM_ABI _LIBCPP_DEPRECATED_WITH_CHAR8_T path u8path(_InputIt __f, _NullSentinel) {
5156
static_assert(
@@ -65,7 +70,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_DEPRECATED_WITH_CHAR8_T path u8path(_InputIt __f,
6570
_CVT()(back_inserter(__w), __tmp.data(), __tmp.data() + __tmp.size());
6671
return path(__w);
6772
}
68-
# endif /* _LIBCPP_WIN32API */
73+
# endif /* _LIBCPP_WIN32API && _LIBCPP_HAS_LOCALIZATION */
6974

7075
template <class _Source, __enable_if_t<__is_pathable<_Source>::value, int> = 0>
7176
_LIBCPP_HIDE_FROM_ABI _LIBCPP_DEPRECATED_WITH_CHAR8_T path u8path(const _Source& __s) {
@@ -85,7 +90,6 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_DEPRECATED_WITH_CHAR8_T path u8path(const _Source&
8590
}
8691

8792
_LIBCPP_END_NAMESPACE_FILESYSTEM
88-
8993
#endif // _LIBCPP_STD_VER >= 17
9094

9195
#endif // _LIBCPP___FILESYSTEM_U8PATH_H

0 commit comments

Comments
 (0)