[clang] [clang] Improve diagnostics for invalid named-universal-characters (PR #206326)

Corentin Jabot via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 30 04:50:21 PDT 2026


================
@@ -550,6 +555,27 @@ static void DiagnoseInvalidUnicodeCharacterName(
 
   namespace u = llvm::sys::unicode;
 
+  bool HasIllegalCharacter = false;
+  for (const char *P = Name.begin(), *E = Name.end(); P != E;) {
+    if (allowedInCharacterName(*P)) {
+      ++P;
+      continue;
+    }
+    const auto *Src = reinterpret_cast<const llvm::UTF8 *>(P);
+    const auto *SrcEnd = reinterpret_cast<const llvm::UTF8 *>(E);
+    llvm::UTF32 CodePoint = 0;
+    if (llvm::convertUTF8Sequence(&Src, SrcEnd, &CodePoint,
+                                  llvm::strictConversion) != llvm::conversionOK)
+      break;
----------------
cor3ntin wrote:

Lexing is done in a single phase - so invalid code units can appear anywhere.
There aren't a lot of great ways to test that beside crafting a file that contains invalid utf-8

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


More information about the cfe-commits mailing list