From aa89cf1a6611ce1a35b85418b0434620b4064c83 Mon Sep 17 00:00:00 2001 From: Jordan Rose Date: Thu, 24 Jan 2013 20:50:13 +0000 Subject: [PATCH] Unify diagnostics for \x, \u, and \U without any following hex digits. llvm-svn: 173368 --- clang/include/clang/Basic/DiagnosticLexKinds.td | 3 +-- clang/lib/Lex/LiteralSupport.cpp | 4 ++-- clang/test/Sema/ucn-cstring.c | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticLexKinds.td b/clang/include/clang/Basic/DiagnosticLexKinds.td index 90012fa..c8b4423 100644 --- a/clang/include/clang/Basic/DiagnosticLexKinds.td +++ b/clang/include/clang/Basic/DiagnosticLexKinds.td @@ -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< diff --git a/clang/lib/Lex/LiteralSupport.cpp b/clang/lib/Lex/LiteralSupport.cpp index 362453e..1647aa5 100644 --- a/clang/lib/Lex/LiteralSupport.cpp +++ b/clang/lib/Lex/LiteralSupport.cpp @@ -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); diff --git a/clang/test/Sema/ucn-cstring.c b/clang/test/Sema/ucn-cstring.c index 5d3e85d..382e555 100644 --- a/clang/test/Sema/ucn-cstring.c +++ b/clang/test/Sema/ucn-cstring.c @@ -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}} -- 2.7.4