"A source file that is not empty and that does not end with a newline, or that ends with a newline, which is preceded by a backslash before any such merging occurs, is processed as if an additional character had been added to the file new line.
The second part of translation phase 2 (section 2.2.2 in N3485) basically says that if the source file does not end with a newline, the compiler should treat it as if it were doing it.
No - it says that if the file is "not empty" and does not end in a new line, a new line is added
However, if I read it correctly, it makes an explicit exception for empty source files that remain empty.
I agree.
I was not able to figure out any situations in which it would matter if the source file was empty or consisted only of a newline. I hope that someone can shed light on the reasoning behind this requirement.
Consider a header file called "header.h" with the last line, as shown below, without a trailing new line:
#endif
Let's say another.cc includes the following:
#include "header.h" #include "another.h"
When analyzing another.cc, the text from header.h is replaced with a line indicating its inclusion. Done naively, which will lead to:
#endif
Obviously, the compiler will then be unable to act on #include "another.h" , considering it to be part of the comment started in header.h.
Thus, the rule for incomplete rules avoids these problems (which can be very difficult to detect).
If the file is still empty, this problem does not occur: nothing looks like #endif for the next line in the included file ....
Tony delroy
source share