<div dir="ltr">Actually, the C++11 standard says:<div>"A source file that is not empty and that does not end in a new-line character, or that ends in a new-line character immediately preceded by a backslash character before any such splicing takes place, shall be processed as if an additional new-line character were appended to the file."</div>
<div><br></div><div>I think this pretty much implies that source files are allowed to not end in a newline. Also, I think it is fine for clang-format to not alter its input file in this regard. If your VCS requires this, configure your editor appropriately ..</div>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Sun, Oct 6, 2013 at 2:10 PM, Alp Toker <span dir="ltr"><<a href="mailto:alp@nuanti.com" target="_blank">alp@nuanti.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi,<br>
<br>
I'm just putting this patch out there for now as it's been useful to us<br>
in its current state. Some tweaks are needed before this can land:<br>
<br>
1) It needs a lot of existing unit tests to be fixed. The tests could be<br>
fixed before this patch goes in if anyone has the time to volunteer(!)<br>
<br>
2) I'm not convinced it's worth even having a 'AllowNoEOL' format flag<br>
for this. The spec is clear that it's mandatory and many VCS also expect<br>
EOL at EOF to work properly.<br>
<br>
3) That means we might do better to add a command line flag to identify<br>
that the code is being formatted for snippets, which uses the<br>
forSnippets() internally, in which case AllowNoEOL would be made true.<br>
<br>
4) There are other rules such as trailing slash in 5.5.1.2 that I'm not<br>
sure are handled yet, though these could be worked on subequent to this<br>
patch landing.<br>
<br>
Note also that this fixes a bug in clang-format where it was reporting<br>
an error code for an empty (zero-sized) file. There's no benefit to the<br>
special case so we can just remove that check now.<br>
<br>
Here's the change:<br>
<br>
    clang-format: Enforce EOL at EOF as required by C standard<br>
<br>
    This enables end-of-line correction as specified for C-family languages.<br>
<br>
    C11 5.5.1.2p2 "A source file that is not empty shall end in a new-line<br>
    character"<br>
<br>
    The new setting 'AllowNoEOL' and the fluent<br>
FormatStyle::forSnippets() helper<br>
    are provided for consumers that prefer the old behaviour, which is<br>
preferable<br>
    for inline code snippets in documentation.<br>
<span class="HOEnZb"><font color="#888888"><br>
Alp.<br>
<br>
--<br>
<a href="http://www.nuanti.com" target="_blank">http://www.nuanti.com</a><br>
the browser experts<br>
<br>
</font></span></blockquote></div><br></div>