Unify diagnostics for \x, \u, and \U without any following hex digits.
authorJordan Rose <jordan_rose@apple.com>
Thu, 24 Jan 2013 20:50:13 +0000 (20:50 +0000)
committerJordan Rose <jordan_rose@apple.com>
Thu, 24 Jan 2013 20:50:13 +0000 (20:50 +0000)
llvm-svn: 173368

clang/include/clang/Basic/DiagnosticLexKinds.td
clang/lib/Lex/LiteralSupport.cpp
clang/test/Sema/ucn-cstring.c

index 90012fa..c8b4423 100644 (file)
@@ -99,8 +99,7 @@ def ext_four_char_character_literal : Extension<
 def ext_nonstandard_escape : Extension<
   "use of non-standard escape character '\\%0'">;
 def ext_unknown_escape : ExtWarn<"unknown escape sequence '\\%0'">;
-def err_hex_escape_no_digits : Error<"\\x used with no following hex digits">;
-def err_ucn_escape_no_digits : Error<"\\u used with no following hex digits">;
+def err_hex_escape_no_digits : Error<"\\%0 used with no following hex digits">;
 def err_ucn_escape_invalid : Error<"invalid universal character">;
 def err_ucn_escape_incomplete : Error<"incomplete universal character name">;
 def err_ucn_escape_basic_scs : Error<
index 362453e..1647aa5 100644 (file)
@@ -130,7 +130,7 @@ static unsigned ProcessCharEscape(const char *ThisTokBegin,
     if (ThisTokBuf == ThisTokEnd || !isxdigit(*ThisTokBuf)) {
       if (Diags)
         Diag(Diags, Features, Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
-             diag::err_hex_escape_no_digits);
+             diag::err_hex_escape_no_digits) << "x";
       HadError = 1;
       break;
     }
@@ -226,7 +226,7 @@ static bool ProcessUCNEscape(const char *ThisTokBegin, const char *&ThisTokBuf,
   if (ThisTokBuf == ThisTokEnd || !isxdigit(*ThisTokBuf)) {
     if (Diags)
       Diag(Diags, Features, Loc, ThisTokBegin, UcnBegin, ThisTokBuf,
-           diag::err_ucn_escape_no_digits);
+           diag::err_hex_escape_no_digits) << StringRef(&ThisTokBuf[-1], 1);
     return false;
   }
   UcnLen = (ThisTokBuf[-1] == 'u' ? 4 : 8);
index 5d3e85d..382e555 100644 (file)
@@ -8,7 +8,7 @@ int main(void) {
   printf("%s (%zd)\n", "hello \u2192 \u2603 \u2190 world", sizeof("hello \u2192 \u2603 \u2190 world"));
   printf("%s (%zd)\n", "\U00010400\U0001D12B", sizeof("\U00010400\U0001D12B"));
   // Some error conditions...
-  printf("%s\n", "\U"); // expected-error{{\u used with no following hex digits}}
+  printf("%s\n", "\U"); // expected-error{{\U used with no following hex digits}}
   printf("%s\n", "\U00"); // expected-error{{incomplete universal character name}}
   printf("%s\n", "\U0001"); // expected-error{{incomplete universal character name}}
   printf("%s\n", "\u0001"); // expected-error{{universal character name refers to a control character}}