From e83c731cad3009ba20d0d0d990789ab5de38d192 Mon Sep 17 00:00:00 2001 From: Seth Cantrell Date: Fri, 13 Apr 2012 03:43:23 +0000 Subject: [PATCH] Support -Wc++98-compat-pedantic as requested: http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20120409/056126.html llvm-svn: 154655 --- clang/include/clang/Basic/DiagnosticLexKinds.td | 5 +++++ clang/lib/Lex/Lexer.cpp | 8 ++++---- clang/test/Lexer/newline-eof-c++98-compat.cpp | 4 ++++ 3 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 clang/test/Lexer/newline-eof-c++98-compat.cpp diff --git a/clang/include/clang/Basic/DiagnosticLexKinds.td b/clang/include/clang/Basic/DiagnosticLexKinds.td index eb2cf10d505f..670283ef1a5c 100644 --- a/clang/include/clang/Basic/DiagnosticLexKinds.td +++ b/clang/include/clang/Basic/DiagnosticLexKinds.td @@ -48,6 +48,11 @@ def ext_bcpl_comment : Extension< InGroup; def ext_no_newline_eof : Extension<"no newline at end of file">, InGroup>; + +def warn_cxx98_compat_no_newline_eof : Warning< + "C++98 requires newline at end of file">, + InGroup, DefaultIgnore; + def ext_dollar_in_identifier : Extension<"'$' in identifier">, InGroup>; def ext_charize_microsoft : Extension<"@# is a microsoft extension">, diff --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp index f0c2c8e4f681..535a852429b5 100644 --- a/clang/lib/Lex/Lexer.cpp +++ b/clang/lib/Lex/Lexer.cpp @@ -2375,10 +2375,10 @@ 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') - && !LangOpts.CPlusPlus0x) // C++11 [lex.phases] 2.2 p2 - Diag(BufferEnd, diag::ext_no_newline_eof) - << FixItHint::CreateInsertion(getSourceLocation(BufferEnd), "\n"); + if (CurPtr != BufferStart && (CurPtr[-1] != '\n' && CurPtr[-1] != '\r')) + Diag(BufferEnd, LangOpts.CPlusPlus0x ? // C++11 [lex.phases] 2.2 p2 + diag::warn_cxx98_compat_no_newline_eof : diag::ext_no_newline_eof) + << FixItHint::CreateInsertion(getSourceLocation(BufferEnd), "\n"); BufferPtr = CurPtr; diff --git a/clang/test/Lexer/newline-eof-c++98-compat.cpp b/clang/test/Lexer/newline-eof-c++98-compat.cpp new file mode 100644 index 000000000000..7f7eebbad7d3 --- /dev/null +++ b/clang/test/Lexer/newline-eof-c++98-compat.cpp @@ -0,0 +1,4 @@ +// RUN: %clang -cc1 -fsyntax-only -Wc++98-compat-pedantic -std=c++11 -verify %s + +// The following line isn't terminated, don't fix it. +void foo() {} // expected-warning{{C++98 requires newline at end of file}} \ No newline at end of file