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

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 3 09:41:00 PDT 2023


aaron.ballman added inline comments.


================
Comment at: clang/docs/ReleaseNotes.rst:103-137
+- When describing the failure of static assertion of `==` expression, clang prints the integer
+  representation of the value as well as its character representation when
+  the user-provided expression is of character type. If the character is
+  non-printable, clang now shows the escpaed character.
+  Clang also prints multi-byte characters if the user-provided expression
+  is of multi-byte character type.
+
----------------
cor3ntin wrote:
> aaron.ballman wrote:
> > cor3ntin wrote:
> > > @aaron.ballman One one hand this is nice, on the other hand maybe too detailed. What do you think?
> > I'm happy with it -- better too much detail than too little, but this really helps users see what's been improved and why it matters.
> > 
> > That said, I think `0x0A` and `0x1F30D` would arguably be better than printing the values in decimal. For `\n`, perhaps folks remember that it's decimal value 10, but nobody is going to know what `127757` means compared to the hex representation (esp because the value is specified in hex with the prefix printed in the error message). WDYT?
> For `wchar_t`, `charN_t` I think that makes sense.
> for `char`... hard to know, I think this is mostly useful for people who treat char as some kind of integer. I could go either way. using hex consistently seems reasonable
I don't insist on using hex, but I have a slight preference for using it consistently everywhere. CC @cjdb for more opinions since this relates to user experience of diagnostics.


================
Comment at: clang/test/SemaCXX/static-assert.cpp:280-287
+static_assert((char16_t)L'ゆ' == L"C̵̭̯̠̎͌ͅť̺"[1], ""); // expected-error {{failed}} \
+                                                // expected-note {{evaluates to ''ゆ' (12422) == '̵' (821)'}}
+static_assert(L"\/"[1] == u'\xFFFD', ""); // expected-error {{failed}} \
+                                           // expected-note {{evaluates to ''/' (65295) == '�' (65533)'}}
+static_assert(L"⚾"[0] == U'🌍', ""); // expected-error {{failed}} \
+                                       // expected-note {{evaluates to ''⚾' (9918) == '🌍' (127757)'}}
+static_assert(U"\a"[0] == (wchar_t)9, ""); // expected-error {{failed}} \
----------------



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

https://reviews.llvm.org/D155610



More information about the cfe-commits mailing list