Skip to content

Commit f4c1258

Browse files
committed
[libc++] Add an option to disable wide character support in libc++
Some embedded platforms do not wish to support the C library functionality for handling wchar_t because they have no use for it. It makes sense for libc++ to work properly on those platforms, so this commit adds a carve-out of functionality for wchar_t. Unfortunately, unlike some other carve-outs (e.g. random device), this patch touches several parts of the library. However, despite the wide impact of this patch, I still think it is important to support this configuration since it makes it much simpler to port libc++ to some embedded platforms. Differential Revision: https://reviews.llvm.org/D111265
1 parent c6828e0 commit f4c1258

File tree

612 files changed

+3891
-1691
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

612 files changed

+3891
-1691
lines changed

libcxx/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,12 @@ option(LIBCXX_ENABLE_UNICODE
120120
"Whether to include support for Unicode in the library. Disabling Unicode can
121121
be useful when porting to platforms that don't support UTF-8 encoding (e.g.
122122
embedded)." ON)
123+
option(LIBCXX_ENABLE_WIDE_CHARACTERS
124+
"Whether to include support for wide characters in the library. Disabling
125+
wide character support can be useful when porting to platforms that don't
126+
support the C functionality for wide characters. When wide characters are
127+
not supported, several parts of the library will be disabled, notably the
128+
wide character specializations of std::basic_string." ON)
123129
option(LIBCXX_ENABLE_VENDOR_AVAILABILITY_ANNOTATIONS
124130
"Whether to turn on vendor availability annotations on declarations that depend
125131
on definitions in a shared library. By default, we assume that we're not building
@@ -893,6 +899,7 @@ config_define_if_not(LIBCXX_ENABLE_FILESYSTEM _LIBCPP_HAS_NO_FILESYSTEM_LIBRARY)
893899
config_define_if_not(LIBCXX_ENABLE_RANDOM_DEVICE _LIBCPP_HAS_NO_RANDOM_DEVICE)
894900
config_define_if_not(LIBCXX_ENABLE_LOCALIZATION _LIBCPP_HAS_NO_LOCALIZATION)
895901
config_define_if_not(LIBCXX_ENABLE_UNICODE _LIBCPP_HAS_NO_UNICODE)
902+
config_define_if_not(LIBCXX_ENABLE_WIDE_CHARACTERS _LIBCPP_HAS_NO_WIDE_CHARACTERS)
896903
config_define_if_not(LIBCXX_ENABLE_VENDOR_AVAILABILITY_ANNOTATIONS _LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS)
897904
# Incomplete features get their own specific disabling flags. This makes it
898905
# easier to grep for target specific flags once the feature is complete.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
set(LIBCXX_ENABLE_WIDE_CHARACTERS OFF CACHE BOOL "")

libcxx/docs/BuildingLibcxx.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,15 @@ libc++ specific options
251251
This option can be used to enable or disable the filesystem components on
252252
platforms that may not support them. For example on Windows when using MSVC.
253253

254+
.. option:: LIBCXX_ENABLE_WIDE_CHARACTERS:BOOL
255+
256+
**Default**: ``ON``
257+
258+
This option can be used to disable support for ``wchar_t`` in the library. It also
259+
allows the library to work on top of a C Standard Library that does not provide
260+
support for ``wchar_t``. This is especially useful in embedded settings where
261+
C Standard Libraries don't always provide all the usual bells and whistles.
262+
254263
.. option:: LIBCXX_ENABLE_INCOMPLETE_FEATURES:BOOL
255264

256265
**Default**: ``ON``

libcxx/docs/ReleaseNotes.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ New Features
4949
API Changes
5050
-----------
5151

52-
- ...
52+
- Support for building libc++ on top of a C Standard Library that does not support ``wchar_t`` was
53+
added. This is useful for building libc++ in an embedded setting, and it adds itself to the various
54+
freestanding-friendly options provided by libc++.
5355

5456
Build System Changes
5557
--------------------

libcxx/include/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ set(files
211211
__iterator/wrap_iter.h
212212
__libcpp_version
213213
__locale
214+
__mbstate_t.h
214215
__memory/addressof.h
215216
__memory/allocation_guard.h
216217
__memory/allocator_arg_t.h

libcxx/include/__algorithm/sort.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,9 @@ __sort(_Tp** __first, _Tp** __last, __less<_Tp*>&)
463463
}
464464

465465
_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less<char>&, char*>(char*, char*, __less<char>&))
466+
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
466467
_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less<wchar_t>&, wchar_t*>(wchar_t*, wchar_t*, __less<wchar_t>&))
468+
#endif
467469
_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less<signed char>&, signed char*>(signed char*, signed char*, __less<signed char>&))
468470
_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less<unsigned char>&, unsigned char*>(unsigned char*, unsigned char*, __less<unsigned char>&))
469471
_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less<short>&, short*>(short*, short*, __less<short>&))
@@ -479,7 +481,9 @@ _LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less<double>&, double*>(d
479481
_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less<long double>&, long double*>(long double*, long double*, __less<long double>&))
480482

481483
_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<char>&, char*>(char*, char*, __less<char>&))
484+
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
482485
_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<wchar_t>&, wchar_t*>(wchar_t*, wchar_t*, __less<wchar_t>&))
486+
#endif
483487
_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<signed char>&, signed char*>(signed char*, signed char*, __less<signed char>&))
484488
_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<unsigned char>&, unsigned char*>(unsigned char*, unsigned char*, __less<unsigned char>&))
485489
_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<short>&, short*>(short*, short*, __less<short>&))

libcxx/include/__bsd_locale_fallbacks.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ decltype(MB_CUR_MAX) __libcpp_mb_cur_max_l(locale_t __l)
3030
return MB_CUR_MAX;
3131
}
3232

33+
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
3334
inline _LIBCPP_INLINE_VISIBILITY
3435
wint_t __libcpp_btowc_l(int __c, locale_t __l)
3536
{
@@ -88,6 +89,7 @@ size_t __libcpp_mbrlen_l(const char *__s, size_t __n, mbstate_t *__ps, locale_t
8889
__libcpp_locale_guard __current(__l);
8990
return mbrlen(__s, __n, __ps);
9091
}
92+
#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
9193

9294
inline _LIBCPP_INLINE_VISIBILITY
9395
lconv *__libcpp_localeconv_l(locale_t __l)
@@ -96,13 +98,15 @@ lconv *__libcpp_localeconv_l(locale_t __l)
9698
return localeconv();
9799
}
98100

101+
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
99102
inline _LIBCPP_INLINE_VISIBILITY
100103
size_t __libcpp_mbsrtowcs_l(wchar_t *__dest, const char **__src, size_t __len,
101104
mbstate_t *__ps, locale_t __l)
102105
{
103106
__libcpp_locale_guard __current(__l);
104107
return mbsrtowcs(__dest, __src, __len, __ps);
105108
}
109+
#endif
106110

107111
inline
108112
int __libcpp_snprintf_l(char *__s, size_t __n, locale_t __l, const char *__format, ...) {

libcxx/include/__config

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,6 +1241,16 @@ extern "C" _LIBCPP_FUNC_VIS void __sanitizer_annotate_contiguous_container(
12411241
#define _LIBCPP_PREFERRED_NAME(x)
12421242
#endif
12431243

1244+
// We often repeat things just for handling wide characters in the library.
1245+
// When wide characters are disabled, it can be useful to have a quick way of
1246+
// disabling it without having to resort to #if-#endif, which has a larger
1247+
// impact on readability.
1248+
#if defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)
1249+
# define _LIBCPP_IF_WIDE_CHARACTERS(...)
1250+
#else
1251+
# define _LIBCPP_IF_WIDE_CHARACTERS(...) __VA_ARGS__
1252+
#endif
1253+
12441254
#if defined(_LIBCPP_ABI_MICROSOFT) && \
12451255
(defined(_LIBCPP_COMPILER_MSVC) || __has_declspec_attribute(empty_bases))
12461256
# define _LIBCPP_DECLSPEC_EMPTY_BASES __declspec(empty_bases)

libcxx/include/__config_site.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#cmakedefine _LIBCPP_HAS_PARALLEL_ALGORITHMS
3131
#cmakedefine _LIBCPP_HAS_NO_RANDOM_DEVICE
3232
#cmakedefine _LIBCPP_HAS_NO_LOCALIZATION
33+
#cmakedefine _LIBCPP_HAS_NO_WIDE_CHARACTERS
3334
#cmakedefine _LIBCPP_HAS_NO_INCOMPLETE_FORMAT
3435
#cmakedefine _LIBCPP_HAS_NO_INCOMPLETE_RANGES
3536

libcxx/include/__format/format_context.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,9 @@ class _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT basic_format_context {
146146
// (such as a span<charT>) and polymorphic reallocation. - end note]
147147

148148
using format_context = basic_format_context<back_insert_iterator<string>, char>;
149-
using wformat_context =
150-
basic_format_context<back_insert_iterator<wstring>, wchar_t>;
149+
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
150+
using wformat_context = basic_format_context<back_insert_iterator<wstring>, wchar_t>;
151+
#endif
151152

152153
#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
153154

libcxx/include/__format/format_parse_context.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@ class _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT basic_format_parse_contex
9696
};
9797

9898
using format_parse_context = basic_format_parse_context<char>;
99+
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
99100
using wformat_parse_context = basic_format_parse_context<wchar_t>;
101+
#endif
100102

101103
#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
102104

libcxx/include/__format/formatter_bool.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,13 @@ struct _LIBCPP_TEMPLATE_VIS __bool_strings<char> {
8585
static constexpr string_view __false{"false"};
8686
};
8787

88+
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
8889
template <>
8990
struct _LIBCPP_TEMPLATE_VIS __bool_strings<wchar_t> {
9091
static constexpr wstring_view __true{L"true"};
9192
static constexpr wstring_view __false{L"false"};
9293
};
94+
#endif
9395

9496
template <class _CharT>
9597
using __formatter_bool = __formatter_integral<__parser_bool<_CharT>>;

libcxx/include/__format/formatter_char.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ template <>
7878
struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<char, char>
7979
: public __format_spec::__formatter_char<char> {};
8080

81+
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
8182
template <>
8283
struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<char, wchar_t>
8384
: public __format_spec::__formatter_char<wchar_t> {
@@ -93,7 +94,7 @@ template <>
9394
struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT
9495
formatter<wchar_t, wchar_t>
9596
: public __format_spec::__formatter_char<wchar_t> {};
96-
97+
#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
9798
#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
9899

99100
#endif //_LIBCPP_STD_VER > 17

libcxx/include/__functional/hash.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,7 @@ _LIBCPP_SUPPRESS_DEPRECATED_POP
561561

562562
#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
563563

564+
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
564565
_LIBCPP_SUPPRESS_DEPRECATED_PUSH
565566
template <>
566567
struct _LIBCPP_TEMPLATE_VIS hash<wchar_t>
@@ -576,6 +577,7 @@ _LIBCPP_SUPPRESS_DEPRECATED_POP
576577
_LIBCPP_INLINE_VISIBILITY
577578
size_t operator()(wchar_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
578579
};
580+
#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
579581

580582
_LIBCPP_SUPPRESS_DEPRECATED_PUSH
581583
template <>

libcxx/include/__locale

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,9 @@ collate<_CharT>::do_hash(const char_type* __lo, const char_type* __hi) const
338338
}
339339

340340
_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS collate<char>)
341+
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
341342
_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS collate<wchar_t>)
343+
#endif
342344

343345
// template <class CharT> class collate_byname;
344346

@@ -363,6 +365,7 @@ protected:
363365
virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const;
364366
};
365367

368+
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
366369
template <>
367370
class _LIBCPP_TYPE_VIS collate_byname<wchar_t>
368371
: public collate<wchar_t>
@@ -382,6 +385,7 @@ protected:
382385
const char_type* __lo2, const char_type* __hi2) const;
383386
virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const;
384387
};
388+
#endif
385389

386390
template <class _CharT, class _Traits, class _Allocator>
387391
bool
@@ -516,6 +520,7 @@ public:
516520

517521
template <class _CharT> class _LIBCPP_TEMPLATE_VIS ctype;
518522

523+
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
519524
template <>
520525
class _LIBCPP_TYPE_VIS ctype<wchar_t>
521526
: public locale::facet,
@@ -617,6 +622,7 @@ protected:
617622
virtual char do_narrow(char_type, char __dfault) const;
618623
virtual const char_type* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const;
619624
};
625+
#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
620626

621627
template <>
622628
class _LIBCPP_TYPE_VIS ctype<char>
@@ -761,6 +767,7 @@ protected:
761767
virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
762768
};
763769

770+
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
764771
template <>
765772
class _LIBCPP_TYPE_VIS ctype_byname<wchar_t>
766773
: public ctype<wchar_t>
@@ -786,6 +793,7 @@ protected:
786793
virtual char do_narrow(char_type, char __dfault) const;
787794
virtual const char_type* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const;
788795
};
796+
#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
789797

790798
template <class _CharT>
791799
inline _LIBCPP_INLINE_VISIBILITY
@@ -992,6 +1000,7 @@ protected:
9921000

9931001
// template <> class codecvt<wchar_t, char, mbstate_t>
9941002

1003+
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
9951004
template <>
9961005
class _LIBCPP_TYPE_VIS codecvt<wchar_t, char, mbstate_t>
9971006
: public locale::facet,
@@ -1072,6 +1081,7 @@ protected:
10721081
virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
10731082
virtual int do_max_length() const _NOEXCEPT;
10741083
};
1084+
#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
10751085

10761086
// template <> class codecvt<char16_t, char, mbstate_t> // deprecated in C++20
10771087

@@ -1450,7 +1460,9 @@ codecvt_byname<_InternT, _ExternT, _StateT>::~codecvt_byname()
14501460
_LIBCPP_SUPPRESS_DEPRECATED_POP
14511461

14521462
_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char, char, mbstate_t>)
1463+
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
14531464
_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<wchar_t, char, mbstate_t>)
1465+
#endif
14541466
_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char16_t, char, mbstate_t>) // deprecated in C++20
14551467
_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char32_t, char, mbstate_t>) // deprecated in C++20
14561468
#ifndef _LIBCPP_HAS_NO_CHAR8_T
@@ -1681,6 +1693,7 @@ protected:
16811693
string __grouping_;
16821694
};
16831695

1696+
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
16841697
template <>
16851698
class _LIBCPP_TYPE_VIS numpunct<wchar_t>
16861699
: public locale::facet
@@ -1711,6 +1724,7 @@ protected:
17111724
char_type __thousands_sep_;
17121725
string __grouping_;
17131726
};
1727+
#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
17141728

17151729
// template <class charT> class numpunct_byname
17161730

@@ -1734,6 +1748,7 @@ private:
17341748
void __init(const char*);
17351749
};
17361750

1751+
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
17371752
template <>
17381753
class _LIBCPP_TYPE_VIS numpunct_byname<wchar_t>
17391754
: public numpunct<wchar_t>
@@ -1751,6 +1766,7 @@ protected:
17511766
private:
17521767
void __init(const char*);
17531768
};
1769+
#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
17541770

17551771
_LIBCPP_END_NAMESPACE_STD
17561772

libcxx/include/__mbstate_t.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// -*- C++ -*-
2+
//===----------------------------------------------------------------------===//
3+
//
4+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5+
// See https://llvm.org/LICENSE.txt for license information.
6+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
#ifndef _LIBCPP___MBSTATE_T_H
11+
#define _LIBCPP___MBSTATE_T_H
12+
13+
#include <__config>
14+
15+
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16+
#pragma GCC system_header
17+
#endif
18+
19+
// TODO(ldionne):
20+
// The goal of this header is to provide mbstate_t without having to pull in
21+
// <wchar.h> or <uchar.h>. This is necessary because we need that type even
22+
// when we don't have (or try to provide) support for wchar_t, because several
23+
// types like std::fpos are defined in terms of mbstate_t.
24+
//
25+
// This is a gruesome hack, but I don't know how to make it cleaner for
26+
// the time being.
27+
28+
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
29+
# include <wchar.h> // for mbstate_t
30+
#elif __has_include(<bits/types/mbstate_t.h>)
31+
# include <bits/types/mbstate_t.h> // works on most Unixes
32+
#elif __has_include(<sys/_types/_mbstate_t.h>)
33+
# include <sys/_types/_mbstate_t.h> // works on Darwin
34+
#else
35+
# error "The library was configured without support for wide-characters, but we don't know how to get the definition of mbstate_t without <wchar.h> on your platform."
36+
#endif
37+
38+
_LIBCPP_BEGIN_NAMESPACE_STD
39+
40+
using ::mbstate_t _LIBCPP_USING_IF_EXISTS;
41+
42+
_LIBCPP_END_NAMESPACE_STD
43+
44+
#endif // _LIBCPP___MBSTATE_T_H

libcxx/include/__string

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,12 @@
2323
#include <cstdio> // for EOF
2424
#include <cstdint> // for uint_least16_t
2525
#include <cstring> // for memcpy
26-
#include <cwchar> // for wmemcpy
2726
#include <type_traits> // for __libcpp_is_constant_evaluated
27+
#include <iosfwd> // for streampos & friends
28+
29+
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
30+
# include <cwchar> // for wmemcpy
31+
#endif
2832

2933
#include <__debug>
3034

@@ -423,6 +427,7 @@ char_traits<char>::find(const char_type* __s, size_t __n, const char_type& __a)
423427

424428
// char_traits<wchar_t>
425429

430+
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
426431
template <>
427432
struct _LIBCPP_TEMPLATE_VIS char_traits<wchar_t>
428433
{
@@ -539,6 +544,7 @@ char_traits<wchar_t>::find(const char_type* __s, size_t __n, const char_type& __
539544
return nullptr;
540545
#endif
541546
}
547+
#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
542548

543549
template <class _Traits>
544550
_LIBCPP_INLINE_VISIBILITY

0 commit comments

Comments
 (0)