[cfe-commits] r173371 - in /cfe/trunk: include/clang/Basic/DiagnosticLexKinds.td lib/Lex/Lexer.cpp test/Preprocessor/ucn-pp-identifier.c
Jordan Rose
jordan_rose at apple.com
Thu Jan 24 12:50:52 PST 2013
Author: jrose
Date: Thu Jan 24 14:50:52 2013
New Revision: 173371
URL: http://llvm.org/viewvc/llvm-project?rev=173371&view=rev
Log:
Add a fixit for \U1234 -> \u1234.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
cfe/trunk/lib/Lex/Lexer.cpp
cfe/trunk/test/Preprocessor/ucn-pp-identifier.c
Modified: cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td?rev=173371&r1=173370&r2=173371&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td Thu Jan 24 14:50:52 2013
@@ -114,12 +114,13 @@
def warn_ucn_escape_incomplete : Warning<
"incomplete universal character name; "
"treating as '\\' followed by identifier">, InGroup<Unicode>;
-def err_ucn_escape_invalid : Error<"invalid universal character">;
+def note_ucn_four_not_eight : Note<"did you mean to use '\\u'?">;
def err_ucn_escape_basic_scs : Error<
"character '%0' cannot be specified by a universal character name">;
def err_ucn_control_character : Error<
"universal character name refers to a control character">;
+def err_ucn_escape_invalid : Error<"invalid universal character">;
def warn_cxx98_compat_literal_ucn_escape_basic_scs : Warning<
"specifying character '%0' with a universal character name "
"is incompatible with C++98">, InGroup<CXX98Compat>, DefaultIgnore;
Modified: cfe/trunk/lib/Lex/Lexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Lexer.cpp?rev=173371&r1=173370&r2=173371&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Lexer.cpp (original)
+++ cfe/trunk/lib/Lex/Lexer.cpp Thu Jan 24 14:50:52 2013
@@ -2725,8 +2725,16 @@
Diag(BufferPtr, diag::warn_ucn_escape_no_digits)
<< StringRef(KindLoc, 1);
} else {
- // FIXME: if i == 4 and NumHexDigits == 8, suggest a fixit to \u.
Diag(BufferPtr, diag::warn_ucn_escape_incomplete);
+
+ // If the user wrote \U1234, suggest a fixit to \u.
+ if (i == 4 && NumHexDigits == 8) {
+ CharSourceRange URange =
+ CharSourceRange::getCharRange(getSourceLocation(KindLoc),
+ getSourceLocation(KindLoc + 1));
+ Diag(KindLoc, diag::note_ucn_four_not_eight)
+ << FixItHint::CreateReplacement(URange, "u");
+ }
}
}
Modified: cfe/trunk/test/Preprocessor/ucn-pp-identifier.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/ucn-pp-identifier.c?rev=173371&r1=173370&r2=173371&view=diff
==============================================================================
--- cfe/trunk/test/Preprocessor/ucn-pp-identifier.c (original)
+++ cfe/trunk/test/Preprocessor/ucn-pp-identifier.c Thu Jan 24 14:50:52 2013
@@ -1,5 +1,6 @@
// RUN: %clang_cc1 %s -fsyntax-only -std=c99 -pedantic -verify -Wundef
// RUN: %clang_cc1 %s -fsyntax-only -x c++ -pedantic -verify -Wundef
+// RUN: %clang_cc1 %s -fsyntax-only -std=c99 -pedantic -fdiagnostics-parseable-fixits -Wundef 2>&1 | FileCheck -strict-whitespace %s
#define \u00FC
#define a\u00FD() 0
@@ -95,3 +96,11 @@
#else
#error "Line splicing failed to produce UCNs"
#endif
+
+
+#define capital_u_\U00FC
+// expected-warning at -1 {{incomplete universal character name}} expected-note at -1 {{did you mean to use '\u'?}} expected-warning at -1 {{whitespace}}
+// CHECK: note: did you mean to use '\u'?
+// CHECK-NEXT: #define capital_u_\U00FC
+// CHECK-NEXT: {{^ \^}}
+// CHECK-NEXT: {{^ u}}
More information about the cfe-commits
mailing list