Skip to content

Commit 34300c3

Browse files
committed
[libc++] Fix incorrect bypassing of <wctype.h>
Differential Revision: https://reviews.llvm.org/D108709 (cherry picked from commit a4357bc)
1 parent 198edf0 commit 34300c3

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

libcxx/include/cwctype

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ wctrans_t wctrans(const char* property);
5959

6060
_LIBCPP_BEGIN_NAMESPACE_STD
6161

62+
#if defined(_LIBCPP_INCLUDED_C_LIBRARY_WCTYPE_H)
6263
using ::wint_t _LIBCPP_USING_IF_EXISTS;
6364
using ::wctrans_t _LIBCPP_USING_IF_EXISTS;
6465
using ::wctype_t _LIBCPP_USING_IF_EXISTS;
@@ -80,6 +81,7 @@ using ::towlower _LIBCPP_USING_IF_EXISTS;
8081
using ::towupper _LIBCPP_USING_IF_EXISTS;
8182
using ::towctrans _LIBCPP_USING_IF_EXISTS;
8283
using ::wctrans _LIBCPP_USING_IF_EXISTS;
84+
#endif // _LIBCPP_INCLUDED_C_LIBRARY_WCTYPE_H
8385

8486
_LIBCPP_END_NAMESPACE_STD
8587

libcxx/include/wctype.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,18 @@ wctrans_t wctrans(const char* property);
5050
#pragma GCC system_header
5151
#endif
5252

53+
// TODO:
54+
// In the future, we should unconditionally include_next <wctype.h> here and instead
55+
// have a mode under which the library does not need libc++'s <wctype.h> or <cwctype>
56+
// at all (i.e. a mode without wchar_t). As it stands, we need to do that to completely
57+
// bypass the using declarations in <cwctype> when we did not include <wctype.h>.
58+
// Otherwise, a using declaration like `using ::wint_t` in <cwctype> will refer to
59+
// nothing (with using_if_exists), and if we include another header that defines one
60+
// of these declarations (e.g. <wchar.h>), the second `using ::wint_t` with using_if_exists
61+
// will fail because it does not refer to the same declaration.
5362
#if __has_include_next(<wctype.h>)
5463
# include_next <wctype.h>
64+
# define _LIBCPP_INCLUDED_C_LIBRARY_WCTYPE_H
5565
#endif
5666

5767
#ifdef __cplusplus

0 commit comments

Comments
 (0)