Issue 1098: Source files not ending with newline

Authors: Joseph Myers
Date: 2026-09-01
Submitted against: C2Y (N3886 draft)
Status: Open

As noted in reflector message 33995, when we accepted N3411, allowing source files without a final newline, we did not make any corresponding change to the syntax for many preprocessing directives, which includes new-line, as does that for text-line, so leaving syntax violations for source files without the final newline character, when the intent was to allow such file as if the final newline were added. It was also said when we accepted N3478, making partial comments at the end of a file into a constraint violation, that we should allow a // comment on the final line of a file without needing trailing newline.

In reflector message 34017, Corentin Jabot suggested following the wording used by C++. This would allow a source file with no final newline without allowing the case where the source file ends with a backslash (and no following newline) to act as if line splicing occurs. It would both resolve the issues introduced by the integration of N3411, and allow a // comment on the final line of a file without a trailing newline to be handled as such rather than being a constraint violation.

Suggested correction

At the end of translation phase 2 in 5.2.1.2 (Translation phases), add:

  1. Each instance of a backslash character (\) immediately followed by a new-line character is deleted, splicing physical source lines to form logical source lines. Only the last backslash on any physical source line shall be eligible for being part of such a splice. A source file that is not empty and that (after splicing) does not end in a new-line character is processed as if an additional new-line character were appended to the file.