Skip to content

Commit d55527c

Browse files
committed
Define char16_t and char32_t in uchar.h conditionally
This patch adds a macro guard around the typedefs for `char16_t` and `char32_t`. These two types have become built-in in C++ starting from C++11. Because of that, the presence of the typedefs leads to an error as the types are already defined. For C++11 or later, there's a difference in how libstdc++ and LLVM's libcxx use the C library's `uchar.h`. The former only includes the C library's `uchar.h` under certain conditions, whereas libcxx always does. In the case of libcxx, this introduces a problem since picolibc's `uchar.h` has the typedefs unconditionally. Glibc, on the other hand, has them under a macro guard called`__USE_ISOCXX11`, defined as `defined __cplusplus && __cplusplus >= 201103L` ([link](https://sourceware.org/git/?p=glibc.git;a=blob;f=wcsmbs/uchar.h;h=7123f46500ef2162f214208007a9af50f5cd6d5d;hb=HEAD#l49)). Thus even in the case where libstdc++ performs the inclusion of C library's `uchar.h`, glibc defensively disables the typedefs.
1 parent 1c73900 commit d55527c

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

newlib/libc/include/uchar.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,10 @@ typedef _mbstate_t mbstate_t;
5252
#endif
5353

5454
typedef unsigned char char8_t;
55+
#if !defined __cplusplus || __cplusplus < 201103L
5556
typedef __uint_least16_t char16_t;
5657
typedef __uint_least32_t char32_t;
58+
#endif
5759

5860
size_t mbrtoc8(char8_t * __restrict pc8, const char * __restrict s, size_t n,
5961
_mbstate_t * __restrict ps);

0 commit comments

Comments
 (0)