[clang] [C2y] Implement WG14 N3411 (PR #130180)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Mar 7 04:45:19 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;
----------------
cor3ntin wrote:
Interestingly, GCC does not warn https://compiler-explorer.com/z/vWMf6W551 , so I question the value of bundling that warning in `-fpedantic`.
https://github.com/llvm/llvm-project/pull/130180
More information about the cfe-commits
mailing list