[PATCH] D155610: [Clang][Sema] Fix display of characters on static assertion failure

Hubert Tong via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 11 16:49:03 PDT 2023


hubert.reinterpretcast added inline comments.


================
Comment at: clang/lib/Sema/SemaDeclCXX.cpp:16930-16936
+        case BuiltinType::Char_S:
+        case BuiltinType::Char_U:
+        case BuiltinType::Char8:
+        case BuiltinType::Char16:
+        case BuiltinType::Char32:
+        case BuiltinType::WChar_S:
+        case BuiltinType::WChar_U: {
----------------
Add FIXME for `char` and `wchar_t` cases that this assumes Unicode literal encodings.


================
Comment at: clang/lib/Sema/SemaDeclCXX.cpp:16942-16945
+          OS << "' (0x"
+             << llvm::format_hex_no_prefix(CodePoint, /*Width=*/2,
+                                           /*Upper=*/true)
+             << ')';
----------------
@aaron.ballman, hex output hides signedness. I think we want hex //and// decimal.


================
Comment at: clang/test/SemaCXX/static-assert.cpp:287
+  static_assert((char16_t)L'ゆ' == L"C̵̭̯̠̎͌ͅť̺"[1], ""); // expected-error {{failed}} \
+                                                  // expected-note {{evaluates to ''ゆ' (0x3086) == '̵' (0x335)'}}
+  static_assert(L"\/"[1] == u'\xFFFD', ""); // expected-error {{failed}} \
----------------
The C++23 escaped string formatting facility would not generate a trailing combining character like this. I recommend following suit.

Info on U+0335: https://util.unicode.org/UnicodeJsps/character.jsp?a=0335



CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155610/new/

https://reviews.llvm.org/D155610



More information about the cfe-commits mailing list