C++11 newline eof

Please review this patch:

diff --git a/lib/Lex/Lexer.cpp b/lib/Lex/Lexer.cpp
index e5d26ff..f27e238 100644
--- a/lib/Lex/Lexer.cpp
+++ b/lib/Lex/Lexer.cpp
@@ -2382,7 +2382,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");

Also, can anyone tell me why when I run clang with -verify and -std=c++11 I get a warning "clang: warning: argument unused during compilation: '-verify'"? I've verified that my patch changes the warnings output from clang based on the -std=c++11 flag, but since -verify doesn't seen work I can't add a working test. Here's a test that should fail but doesn't for me:

newline-eof-c++11.cpp (183 Bytes)

Please review this patch:

diff --git a/lib/Lex/Lexer.cpp b/lib/Lex/Lexer.cpp
index e5d26ff..f27e238 100644
--- a/lib/Lex/Lexer.cpp
+++ b/lib/Lex/Lexer.cpp
@@ -2382,7 +2382,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");

Also, can anyone tell me why when I run clang with -verify and -std=c++11 I get a warning "clang: warning: argument unused during compilation: '-verify'"? I've verified that my patch changes the warnings output from clang based on the -std=c++11 flag, but since -verify doesn't seen work I can't add a working test. Here's a test that should fail but doesn't for me:

-verify is a cc1 (the underlying clang binary, not the gcc-compatible
driver) option - use %clang_cc1 instead of %clang & you should be fine

Thanks, turns out the test I copied from (test/Lexer/newline-eof.c) wasn't working either. I'll fix it when I check this in.

Also, after reviewing the llvm developer policy I've decided that this change is minor enough that I'm just going to commit it here in a little while.

Thanks, turns out the test I copied from (test/Lexer/newline-eof.c) wasn't working either. I'll fix it when I check this in.

That's really kind of disturbing. I'm seeing the same behavior - it's
as though that test isn't being run at all.

Strangely, putting "// RUN: foo" after the existing RUN line in
newline-eof.c causes both run lines to be executed & print relevant
failures from each...

Perhaps we should see what's broken in lit.

- David