[clang] [clang] Improve diagnostics for invalid named-universal-characters (PR #206326)
Corentin Jabot via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 29 01:33:34 PDT 2026
================
@@ -550,6 +556,44 @@ static void DiagnoseInvalidUnicodeCharacterName(
namespace u = llvm::sys::unicode;
+ auto StringifyCodePoint = [](llvm::UTF32 CodePoint) -> llvm::SmallString<16> {
+ llvm::SmallString<16> Result;
+ if (u::isPrintable(CodePoint)) {
+ std::string CharUTF8;
+ llvm::convertUTF32ToUTF8String(llvm::ArrayRef<llvm::UTF32>(&CodePoint, 1),
+ CharUTF8);
+ Result.append("'");
+ Result.append(CharUTF8);
+ Result.append("' U+");
+ } else {
+ Result.append("U+");
+ }
+ llvm::raw_svector_ostream OS(Result);
+ llvm::write_hex(OS, CodePoint, llvm::HexPrintStyle::Upper, 4);
+ return Result;
+ };
----------------
cor3ntin wrote:
You should be able to use `FormatUTFCodeUnitAsCodepoint` (for a single char32) - or `EscapeStringForDiagnostic` (taking a utf-8 string so you'd first need to find the length of the codepoint with `getUTF8SequenceSize`
https://github.com/llvm/llvm-project/pull/206326
More information about the cfe-commits
mailing list