preprocessing directive with no new-line character

Martin Sebor msebor@gmail.com
Mon Aug 7 15:29:00 GMT 2017


On 08/06/2017 06:47 PM, Vincent Lefevre wrote:
> On 2017-07-18 17:43:50 -0600, Martin Sebor wrote:
>> Yes, C requires every non-empty source file to have at least
>> one line.  The C11 standard says in 5.1.1.2 Translation phases,
>> p2:
>>
>>   A source file that is not empty shall end in a new-line character,
>>   which shall not be immediately preceded by a backslash character
>>   before any such splicing takes place.
>
> I've reported a bug for the missing warning:
>
>   https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81745
>
> It was closed because
>
>   https://gcc.gnu.org/ml/gcc-patches/2007-04/msg00504.html
>
> "It's really not undefined at all.  gcc would be still be standard
> conformant if we defined all input to end with a newline, whether or
> not the actual physical Unix input file did so."

The C standard requires implementations to issue diagnostics only
for constraint violations.  Violations of requirements that aren't
explicitly called out as constraints don't require a diagnostic.
Implementations that do issue diagnostics for either kinds of
violations aren't required to reject programs with those
diagnostics.  As a result, the behavior or programs that contain
such violations is undefined.  Implementations are free to provide
meaningful semantics for constructs that are left undefined by the
standard.

The requirement quoted from the standard above (5.1.1.2, p2)
is not a constraint so conforming compilers aren't required to
diagnose it, although quality implementations do.

> However, this is not documented in the GCC manual and the preprocessor
> behaves differently whether the input file ends with a backslash or
> ends with a backslash-newline:
>
>   https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81745#c7

That sounds like a reason to diagnose it in and of itself.

Martin



More information about the Gcc-help mailing list