]> granicus.if.org Git - clang/commitdiff
Support -Wc++98-compat-pedantic as requested:
authorSeth Cantrell <seth.cantrell@gmail.com>
Fri, 13 Apr 2012 03:43:23 +0000 (03:43 +0000)
committerSeth Cantrell <seth.cantrell@gmail.com>
Fri, 13 Apr 2012 03:43:23 +0000 (03:43 +0000)
http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20120409/056126.html

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@154655 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticLexKinds.td
lib/Lex/Lexer.cpp
test/Lexer/newline-eof-c++98-compat.cpp [new file with mode: 0644]

index eb2cf10d505fb686dbb766d0e6e75a57d8da443e..670283ef1a5c9dce12dcffcd16feff9401ed7b7a 100644 (file)
@@ -48,6 +48,11 @@ def ext_bcpl_comment : Extension<
   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">,
index f0c2c8e4f68105de143247cae46fb1b6992ba113..535a852429b567b82f385827c5ae4ef05477958c 100644 (file)
@@ -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/test/Lexer/newline-eof-c++98-compat.cpp b/test/Lexer/newline-eof-c++98-compat.cpp
new file mode 100644 (file)
index 0000000..7f7eebb
--- /dev/null
@@ -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