]> granicus.if.org Git - clang/commitdiff
A code modification hint for files that don't end in a newline.
authorMike Stump <mrs@apple.com>
Thu, 2 Apr 2009 02:29:42 +0000 (02:29 +0000)
committerMike Stump <mrs@apple.com>
Thu, 2 Apr 2009 02:29:42 +0000 (02:29 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@68272 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Lex/Lexer.cpp
test/Lexer/fixit-errors.c [new file with mode: 0644]

index a8a22ebc3517f1aca4a2e0f20bc286077ea09c8b..3a3e86a3cf1daf03985b47f90ffaf567118df2f1 100644 (file)
@@ -1224,7 +1224,9 @@ bool Lexer::LexEndOfFile(Token &Result, const char *CurPtr) {
   // 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;
 
diff --git a/test/Lexer/fixit-errors.c b/test/Lexer/fixit-errors.c
new file mode 100644 (file)
index 0000000..13b4243
--- /dev/null
@@ -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}}