[cfe-commits] r154655 - in /cfe/trunk: include/clang/Basic/DiagnosticLexKinds.td lib/Lex/Lexer.cpp test/Lexer/newline-eof-c++98-compat.cpp

Seth Cantrell seth.cantrell at gmail.com
Thu Apr 12 20:43:23 PDT 2012


Author: socantre
Date: Thu Apr 12 22:43:23 2012
New Revision: 154655

URL: http://llvm.org/viewvc/llvm-project?rev=154655&view=rev
Log:
Support -Wc++98-compat-pedantic as requested:

http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20120409/056126.html

Added:
    cfe/trunk/test/Lexer/newline-eof-c++98-compat.cpp
Modified:
    cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
    cfe/trunk/lib/Lex/Lexer.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td?rev=154655&r1=154654&r2=154655&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td Thu Apr 12 22:43:23 2012
@@ -48,6 +48,11 @@
   InGroup<Comment>;
 def ext_no_newline_eof : Extension<"no newline at end of file">, 
   InGroup<DiagGroup<"newline-eof">>;
+
+def warn_cxx98_compat_no_newline_eof : Warning<
+  "C++98 requires newline at end of file">,
+  InGroup<CXX98CompatPedantic>, DefaultIgnore;
+
 def ext_dollar_in_identifier : Extension<"'$' in identifier">,
   InGroup<DiagGroup<"dollar-in-identifier-extension">>;
 def ext_charize_microsoft : Extension<"@# is a microsoft extension">,

Modified: cfe/trunk/lib/Lex/Lexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Lexer.cpp?rev=154655&r1=154654&r2=154655&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Lexer.cpp (original)
+++ cfe/trunk/lib/Lex/Lexer.cpp Thu Apr 12 22:43:23 2012
@@ -2375,10 +2375,10 @@
 
   // 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;
 

Added: cfe/trunk/test/Lexer/newline-eof-c++98-compat.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Lexer/newline-eof-c%2B%2B98-compat.cpp?rev=154655&view=auto
==============================================================================
--- cfe/trunk/test/Lexer/newline-eof-c++98-compat.cpp (added)
+++ cfe/trunk/test/Lexer/newline-eof-c++98-compat.cpp Thu Apr 12 22:43:23 2012
@@ -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





More information about the cfe-commits mailing list