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

Jan Schultke via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 30 01:17:11 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;
----------------
eisenwave wrote:

I do now for `DisplayCodePointForDiagnosticTest`, but not for this.

Can you even test this? I would have expected that some earlier stage would kill lexing if your text file isn't valid UTF-8, or that lexing wouldn't happen in the first place.

I could also add an `assert` that this part always succeeds, since it's not really intended to fail.

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


More information about the cfe-commits mailing list