[PATCH] D124996: [clang][preprocessor] Fix unsigned-ness of utf8 char literals

Tom Honermann via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed May 11 07:25:42 PDT 2022


tahonermann added inline comments.


================
Comment at: clang/test/Lexer/utf8-char-literal.cpp:54-56
+#  if !(u8'\xff' == 0xff)
+#    error u8 char literal is not unsigned
+#  endif
----------------
tbaeder wrote:
> tahonermann wrote:
> > The C++ case looks good now, but the condition doesn't look right for the C case. The expectation is that `u8'\xff'` should not match `'\xff'` in C23 mode, but the test treats this as an error. If the test is passing, that indicates something is not being validated correctly. Shouldn't unexpected error diagnostics cause the test to fail?
> I used `u8'\xff' != 0xff` here because that's the condition you mentioned in the phab review adding the `u8` prefix. Using `u8'\xff' != '\xff'` indeed fails with:
> 
> ```
> clang/test/Lexer/utf8-char-literal.cpp Line 55: u8 char literal is not unsigned
> clang/test/Lexer/utf8-char-literal.cpp Line 54: right side of operator converted from negative value to unsigned: -1 to 18446744073709551615
> ```
Oh! I missed the use of `0xff` vs `'\xff'`. Sorry if I mislead you. In order to avoid such subtle differences in the test, can we use the same check as for C++?
  // UTF-8 character literals are enabled in C23 and later and are always unsigned.
  #if __STDC_VERSION__ >= 202000L
  #  if u8'\xff' == '\xff' // expected-warning {{right side of operator converted from negative value to unsigned}}
  #    error UTF-8 character value matched ordinary character literal; this is unexpected
  #  endif
  #endif


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

https://reviews.llvm.org/D124996



More information about the cfe-commits mailing list