[clang] [Clang] [C23] Implement N2653: u8 strings are char8_t[] (PR #97208)

Mital Ashok via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 3 09:17:16 PDT 2024


================
@@ -1165,6 +1165,8 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
   DefineType("__WCHAR_TYPE__", TI.getWCharType(), Builder);
   DefineType("__WINT_TYPE__", TI.getWIntType(), Builder);
   DefineTypeSizeAndWidth("__SIG_ATOMIC", TI.getSigAtomicType(), TI, Builder);
+  if (LangOpts.Char8 || LangOpts.C23)
+    DefineType("__CHAR8_TYPE__", TI.UnsignedChar, Builder);
----------------
MitalAshok wrote:

According to https://gcc.gnu.org/legacy-ml/gcc-patches/2018-11/msg00295.html `__CHAR8_TYPE__` is "the underlying type of `char8_t`" in C++. `char8_t` in C++ was added in GCC9 which explains the difference between GCC8 and 9

And this made me realise `-std=c++11 -fchar8_t` sets `LangOpts.Char8` in C++11, which I think this patch handles fine (See also: #97601).
Also `-std=c23 -fchar8_t` is a mode that exists. It makes `typeof(u8'x')` `char8_t` and `typeof(u8"")` `char8_t[1]`, even with this patch, which I guess is fine. Pending #55373 if `-std=c23 -fchar8_t` even makes sense.

https://github.com/llvm/llvm-project/pull/97208


More information about the cfe-commits mailing list