[libc-commits] [libc] [libc] Always provide char8/16/32_t (PR #143803)
Michael Jones via libc-commits
libc-commits at lists.llvm.org
Thu Jun 12 09:25:18 PDT 2025
https://github.com/michaelrj-google updated https://github.com/llvm/llvm-project/pull/143803
>From 6adb80d86101268ea7791b6a43e96b5605d66612 Mon Sep 17 00:00:00 2001
From: Michael Jones <michaelrj at google.com>
Date: Wed, 11 Jun 2025 16:01:51 -0700
Subject: [PATCH 1/2] [libc] Always provide char8/16/32_t
The current definitions only provide these types if the stdc version is
2023 for char8_t or 2011 for char16/32_t. None of our other types are
currently handled this way. If we want to provide these headers only
under certain circumstances we should add guards to the types in the
public header, since internal code should always have access to these
types.
---
libc/include/llvm-libc-types/char16_t.h | 2 --
libc/include/llvm-libc-types/char32_t.h | 2 --
libc/include/llvm-libc-types/char8_t.h | 3 +--
3 files changed, 1 insertion(+), 6 deletions(-)
diff --git a/libc/include/llvm-libc-types/char16_t.h b/libc/include/llvm-libc-types/char16_t.h
index 1f5847ae771b4..1d6e9f98cf886 100644
--- a/libc/include/llvm-libc-types/char16_t.h
+++ b/libc/include/llvm-libc-types/char16_t.h
@@ -9,9 +9,7 @@
#ifndef LLVM_LIBC_TYPES_CHAR16_T_H
#define LLVM_LIBC_TYPES_CHAR16_T_H
-#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
#include "../llvm-libc-macros/stdint-macros.h"
typedef uint_least16_t char16_t;
-#endif
#endif // LLVM_LIBC_TYPES_CHAR16_T_H
diff --git a/libc/include/llvm-libc-types/char32_t.h b/libc/include/llvm-libc-types/char32_t.h
index 20b72dc5d67e3..24b5ef52badfd 100644
--- a/libc/include/llvm-libc-types/char32_t.h
+++ b/libc/include/llvm-libc-types/char32_t.h
@@ -9,9 +9,7 @@
#ifndef LLVM_LIBC_TYPES_CHAR32_T_H
#define LLVM_LIBC_TYPES_CHAR32_T_H
-#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
#include "../llvm-libc-macros/stdint-macros.h"
typedef uint_least32_t char32_t;
-#endif
#endif // LLVM_LIBC_TYPES_CHAR32_T_H
diff --git a/libc/include/llvm-libc-types/char8_t.h b/libc/include/llvm-libc-types/char8_t.h
index ddadab1afa219..a343be77d810b 100644
--- a/libc/include/llvm-libc-types/char8_t.h
+++ b/libc/include/llvm-libc-types/char8_t.h
@@ -9,8 +9,7 @@
#ifndef LLVM_LIBC_TYPES_CHAR8_T_H
#define LLVM_LIBC_TYPES_CHAR8_T_H
-#if !defined(__cplusplus) && defined(__STDC_VERSION__) && \
- __STDC_VERSION__ >= 202311L
+#if !(defined(__cplusplus) && defined(__cpp_char8_t))
typedef unsigned char char8_t;
#endif
>From 039a1de28c88f058d0d3f16fcbd473846bd641d3 Mon Sep 17 00:00:00 2001
From: Michael Jones <michaelrj at google.com>
Date: Thu, 12 Jun 2025 09:24:44 -0700
Subject: [PATCH 2/2] change header guards to work properly for c++
---
libc/include/llvm-libc-types/char16_t.h | 2 ++
libc/include/llvm-libc-types/char32_t.h | 2 ++
libc/include/llvm-libc-types/char8_t.h | 3 +++
3 files changed, 7 insertions(+)
diff --git a/libc/include/llvm-libc-types/char16_t.h b/libc/include/llvm-libc-types/char16_t.h
index 1d6e9f98cf886..91f2d7a17ce44 100644
--- a/libc/include/llvm-libc-types/char16_t.h
+++ b/libc/include/llvm-libc-types/char16_t.h
@@ -9,7 +9,9 @@
#ifndef LLVM_LIBC_TYPES_CHAR16_T_H
#define LLVM_LIBC_TYPES_CHAR16_T_H
+#if !(defined(__cplusplus) && defined(__cpp_unicode_characters))
#include "../llvm-libc-macros/stdint-macros.h"
typedef uint_least16_t char16_t;
+#endif
#endif // LLVM_LIBC_TYPES_CHAR16_T_H
diff --git a/libc/include/llvm-libc-types/char32_t.h b/libc/include/llvm-libc-types/char32_t.h
index 24b5ef52badfd..44624c60bb335 100644
--- a/libc/include/llvm-libc-types/char32_t.h
+++ b/libc/include/llvm-libc-types/char32_t.h
@@ -9,7 +9,9 @@
#ifndef LLVM_LIBC_TYPES_CHAR32_T_H
#define LLVM_LIBC_TYPES_CHAR32_T_H
+#if !(defined(__cplusplus) && defined(__cpp_unicode_characters))
#include "../llvm-libc-macros/stdint-macros.h"
typedef uint_least32_t char32_t;
+#endif
#endif // LLVM_LIBC_TYPES_CHAR32_T_H
diff --git a/libc/include/llvm-libc-types/char8_t.h b/libc/include/llvm-libc-types/char8_t.h
index a343be77d810b..06cd123e5de28 100644
--- a/libc/include/llvm-libc-types/char8_t.h
+++ b/libc/include/llvm-libc-types/char8_t.h
@@ -9,6 +9,9 @@
#ifndef LLVM_LIBC_TYPES_CHAR8_T_H
#define LLVM_LIBC_TYPES_CHAR8_T_H
+// char8_t is only defined as a keyword in C++20, but char16_t and char32_t are
+// defined in C++11. Need to guard all of them so our definitions don't conflict
+// with the compiler's.
#if !(defined(__cplusplus) && defined(__cpp_char8_t))
typedef unsigned char char8_t;
#endif
More information about the libc-commits
mailing list