]> granicus.if.org Git - clang/commitdiff
C++11 no longer requires files to end with a newline
authorSeth Cantrell <seth.cantrell@gmail.com>
Fri, 13 Apr 2012 01:00:34 +0000 (01:00 +0000)
committerSeth Cantrell <seth.cantrell@gmail.com>
Fri, 13 Apr 2012 01:00:34 +0000 (01:00 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@154643 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Lex/Lexer.cpp
test/Lexer/newline-eof-c++11.cpp [new file with mode: 0644]
test/Lexer/newline-eof.c

index c817e3f10564c3e9daa906cd6b8fc8ef019bff67..f0c2c8e4f68105de143247cae46fb1b6992ba113 100644 (file)
@@ -2375,7 +2375,8 @@ 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'))
+  if (CurPtr != BufferStart && (CurPtr[-1] != '\n' && CurPtr[-1] != '\r')
+      && !LangOpts.CPlusPlus0x) // C++11 [lex.phases] 2.2 p2
     Diag(BufferEnd, diag::ext_no_newline_eof)
       << FixItHint::CreateInsertion(getSourceLocation(BufferEnd), "\n");
 
diff --git a/test/Lexer/newline-eof-c++11.cpp b/test/Lexer/newline-eof-c++11.cpp
new file mode 100644 (file)
index 0000000..3c45f28
--- /dev/null
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 -Wnewline-eof -verify %s
+
+// The following line isn't terminated, don't fix it.
+void foo() {}
\ No newline at end of file
index 2f95dc7593c7ad64b7986b217e116c31eb875fb4..12087b2370808abd5c853b6a3023b3047e4e7476 100644 (file)
@@ -1,5 +1,5 @@
-// RUN: %clang -fsyntax-only -Wnewline-eof -verify %s 
+// RUN: %clang -cc1 -fsyntax-only -Wnewline-eof -verify %s
 // rdar://9133072
 
 // The following line isn't terminated, don't fix it.
-void foo() {} // expected-warning{{No newline at end of file}}
\ No newline at end of file
+void foo() {} // expected-warning{{no newline at end of file}}
\ No newline at end of file