[libc-commits] [libc] [libc] Fix character converter in C++20 (PR #177421)
Michael Jones via libc-commits
libc-commits at lists.llvm.org
Thu Jan 22 10:10:55 PST 2026
https://github.com/michaelrj-google created https://github.com/llvm/llvm-project/pull/177421
Internally character converter uses char8_t to represent a character.
Before C++20 we provide a typedef for it, but since C++20 it's a
keyword. The keyword version isn't listed in our is_integral, causing
countl to reject it as an invalid type. This patch just casts from
char8_t to int8_t to sidestep the issue, but in future we may want to
add char8_t, char16_t, and char32_t to our is_integral.
>From dac550b82d8d04c680f5f5029fb55709983c5527 Mon Sep 17 00:00:00 2001
From: Michael Jones <michaelrj at google.com>
Date: Thu, 22 Jan 2026 18:05:30 +0000
Subject: [PATCH] [libc] Fix character converter in C++20
Internally character converter uses char8_t to represent a character.
Before C++20 we provide a typedef for it, but since C++20 it's a
keyword. The keyword version isn't listed in our is_integral, causing
countl to reject it as an invalid type. This patch just casts from
char8_t to int8_t to sidestep the issue, but in future we may want to
add char8_t, char16_t, and char32_t to our is_integral.
---
libc/src/__support/wchar/character_converter.h | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/libc/src/__support/wchar/character_converter.h b/libc/src/__support/wchar/character_converter.h
index e7300166556ac..d0a942ecb3bb1 100644
--- a/libc/src/__support/wchar/character_converter.h
+++ b/libc/src/__support/wchar/character_converter.h
@@ -77,7 +77,8 @@ LIBC_INLINE bool CharacterConverter::isValidState() {
}
LIBC_INLINE int CharacterConverter::push(char8_t utf8_byte) {
- uint8_t num_ones = static_cast<uint8_t>(cpp::countl_one(utf8_byte));
+ uint8_t num_ones =
+ static_cast<uint8_t>(cpp::countl_one(static_cast<uint8_t>(utf8_byte)));
// Checking the first byte if first push
if (isEmpty()) {
// UTF-8 char has 1 byte total
More information about the libc-commits
mailing list