[clang] [C2y] Implement WG14 N3411 (PR #130180)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 7 04:50:25 PST 2025


================
@@ -3192,23 +3192,22 @@ bool Lexer::LexEndOfFile(Token &Result, const char *CurPtr) {
   if (CurPtr != BufferStart && (CurPtr[-1] != '\n' && CurPtr[-1] != '\r')) {
     DiagnosticsEngine &Diags = PP->getDiagnostics();
     SourceLocation EndLoc = getSourceLocation(BufferEnd);
-    unsigned DiagID;
+    unsigned DiagID = diag::warn_no_newline_eof;
 
     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.isIgnored(diag::warn_cxx98_compat_no_newline_eof, EndLoc)) {
+      if (!Diags.isIgnored(diag::warn_cxx98_compat_no_newline_eof, EndLoc))
         DiagID = diag::warn_cxx98_compat_no_newline_eof;
-      } else {
-        DiagID = diag::warn_no_newline_eof;
-      }
     } else {
-      DiagID = diag::ext_no_newline_eof;
+      // This is conforming in C2y, but is an extension in earlier language
+      // modes.
+      if (!LangOpts.C2y)
+        DiagID = diag::ext_no_newline_eof;
----------------
AaronBallman wrote:

`-pedantic` exists to diagnose extensions and this is definitively an extension. So that's a GCC bug IMO. :-)

https://github.com/llvm/llvm-project/pull/130180


More information about the cfe-commits mailing list