[cfe-commits] r68272 - in /cfe/trunk: lib/Lex/Lexer.cpp test/Lexer/fixit-errors.c

Mike Stump mrs at apple.com
Wed Apr 1 19:29:44 PDT 2009


Author: mrs
Date: Wed Apr  1 21:29:42 2009
New Revision: 68272

URL: http://llvm.org/viewvc/llvm-project?rev=68272&view=rev
Log:
A code modification hint for files that don't end in a newline.
Eventually, would be nice to be able to run these modifications even
when we don't want the warning or errors for the actual diagnostic.

Added:
    cfe/trunk/test/Lexer/fixit-errors.c
Modified:
    cfe/trunk/lib/Lex/Lexer.cpp

Modified: cfe/trunk/lib/Lex/Lexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Lexer.cpp?rev=68272&r1=68271&r2=68272&view=diff

==============================================================================
--- cfe/trunk/lib/Lex/Lexer.cpp (original)
+++ cfe/trunk/lib/Lex/Lexer.cpp Wed Apr  1 21:29:42 2009
@@ -1224,7 +1224,9 @@
   // C99 5.1.1.2p2: If the file is non-empty and didn't end in a newline, issue
   // a pedwarn.
   if (CurPtr != BufferStart && (CurPtr[-1] != '\n' && CurPtr[-1] != '\r'))
-    Diag(BufferEnd, diag::ext_no_newline_eof);
+    Diag(BufferEnd, diag::ext_no_newline_eof)
+      << CodeModificationHint::CreateInsertion(getSourceLocation(BufferEnd),
+                                               "\n");
   
   BufferPtr = CurPtr;
 

Added: cfe/trunk/test/Lexer/fixit-errors.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Lexer/fixit-errors.c?rev=68272&view=auto

==============================================================================
--- cfe/trunk/test/Lexer/fixit-errors.c (added)
+++ cfe/trunk/test/Lexer/fixit-errors.c Wed Apr  1 21:29:42 2009
@@ -0,0 +1,13 @@
+// RUN: clang-cc -fsyntax-only -pedantic -fixit %s -o - | clang-cc -pedantic -Werror -x c -
+
+/* This is a test of the various code modification hints that are
+   provided as part of warning or extension diagnostics. Eventually,
+   we would like to actually try to perform the suggested
+   modifications and compile the result to test that no warnings
+   remain. */
+// FIXME: If you put a space at the end of the line, it doesn't work yet!
+char *s = "hi\
+there";
+
+// The following line isn't terminated, don't fix it.
+int i; // expected-error{{no newline at end of file}}





More information about the cfe-commits mailing list