[clang] [C2y] Implement WG14 N3411 (PR #130180)
A. Jiang via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 6 18:19:40 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;
----------------
frederick-vs-ja wrote:
I found that the corresponding change in C++ was introduced by a CWG issue ([CWG787](https://cplusplus.github.io/CWG/issues/787.html)). Would it be preferred to treat N3411 as a DR?
https://github.com/llvm/llvm-project/pull/130180
More information about the cfe-commits
mailing list