summaryrefslogtreecommitdiffstats
path: root/clang/lib/Lex/Lexer.cpp
diff options
context:
space:
mode:
authorJordan Rose <jordan_rose@apple.com>2013-08-23 15:42:01 +0000
committerJordan Rose <jordan_rose@apple.com>2013-08-23 15:42:01 +0000
commit4c55d45b13e9a09b48c4dffefae04ea21e2e5822 (patch)
tree589c4c6d39b9e53923c2975700ef2b6a61a47744 /clang/lib/Lex/Lexer.cpp
parentc7cda1c59ef9559331160cd6d48d8f7e6177a180 (diff)
downloadbcm5719-llvm-4c55d45b13e9a09b48c4dffefae04ea21e2e5822.tar.gz
bcm5719-llvm-4c55d45b13e9a09b48c4dffefae04ea21e2e5822.zip
Respect -Wnewline-eof even in C++11 mode.
If the user has requested this warning, we should emit it, even if it's not an extension in the current language mode. However, being an extension is more important, so prefer the pedantic warning or the pedantic-compatibility warning if those are enabled. <rdar://problem/12922063> llvm-svn: 189110
Diffstat (limited to 'clang/lib/Lex/Lexer.cpp')
-rw-r--r--clang/lib/Lex/Lexer.cpp26
1 files changed, 22 insertions, 4 deletions
diff --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp
index c28781dc5f2..e3e01da8416 100644
--- a/clang/lib/Lex/Lexer.cpp
+++ b/clang/lib/Lex/Lexer.cpp
@@ -2410,10 +2410,28 @@ 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, LangOpts.CPlusPlus11 ? // C++11 [lex.phases] 2.2 p2
- diag::warn_cxx98_compat_no_newline_eof : diag::ext_no_newline_eof)
- << FixItHint::CreateInsertion(getSourceLocation(BufferEnd), "\n");
+ if (CurPtr != BufferStart && (CurPtr[-1] != '\n' && CurPtr[-1] != '\r')) {
+ DiagnosticsEngine &Diags = PP->getDiagnostics();
+ SourceLocation EndLoc = getSourceLocation(BufferEnd);
+ unsigned DiagID;
+
+ if (LangOpts.CPlusPlus11) {
+ // C++11 [lex.phases] 2.2 p2
+ // Prefer the C++98 pedantic compatibility warning over the generic,
+ // non-extension, user-requested "missing newline at EOF" warning.
+ if (Diags.getDiagnosticLevel(diag::warn_cxx98_compat_no_newline_eof,
+ EndLoc) != DiagnosticsEngine::Ignored) {
+ DiagID = diag::warn_cxx98_compat_no_newline_eof;
+ } else {
+ DiagID = diag::warn_no_newline_eof;
+ }
+ } else {
+ DiagID = diag::ext_no_newline_eof;
+ }
+
+ Diag(BufferEnd, DiagID)
+ << FixItHint::CreateInsertion(EndLoc, "\n");
+ }
BufferPtr = CurPtr;
OpenPOWER on IntegriCloud