summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorMike Stump <mrs@apple.com>2009-04-02 02:29:42 +0000
committerMike Stump <mrs@apple.com>2009-04-02 02:29:42 +0000
commit0be8875ea446eb4da76c474e643c2b2c8c249b8a (patch)
treeb75cdae836f2c25099a220a38f9e4c2d3ddfcfbf /clang
parent43533c7f40a31340c0c4e0171ac3675975f47c98 (diff)
downloadbcm5719-llvm-0be8875ea446eb4da76c474e643c2b2c8c249b8a.tar.gz
bcm5719-llvm-0be8875ea446eb4da76c474e643c2b2c8c249b8a.zip
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. llvm-svn: 68272
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/Lex/Lexer.cpp4
-rw-r--r--clang/test/Lexer/fixit-errors.c13
2 files changed, 16 insertions, 1 deletions
diff --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp
index a8a22ebc351..3a3e86a3cf1 100644
--- a/clang/lib/Lex/Lexer.cpp
+++ b/clang/lib/Lex/Lexer.cpp
@@ -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/clang/test/Lexer/fixit-errors.c b/clang/test/Lexer/fixit-errors.c
new file mode 100644
index 00000000000..13b42431951
--- /dev/null
+++ b/clang/test/Lexer/fixit-errors.c
@@ -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}}
OpenPOWER on IntegriCloud