This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: duplicate warnings about missing EOF newline
- To: gcc-patches at gcc dot gnu dot org
- Subject: Re: duplicate warnings about missing EOF newline
- From: Neil Booth <neil at daikokuya dot demon dot co dot uk>
- Date: Sat, 12 May 2001 08:55:03 +0100
Matt Kraai wrote:-
> With the latest CVS GCC, I see duplicate warnings about a missing
> newline at the end of file.
>
> $ echo -n '#define foo bar' > foo.c
> $ gcc -E foo.c
> foo.c:1:15: warning no newline at end of file
> foo.c:1:15: warning no newline at end of file
Fixed thus. Since this is a regression, albeit a most minor one, I'll
put this on branch too.
Neil.
* cpplex.c (_cpp_lex_token): Ensure we warn at most once
about files not ending in newlines.
Index: cpplex.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cpplex.c,v
retrieving revision 1.138
diff -u -p -r1.138 cpplex.c
--- cpplex.c 2001/05/11 23:48:20 1.138
+++ cpplex.c 2001/05/12 07:30:21
@@ -890,9 +890,11 @@ _cpp_lex_token (pfile, result)
switch (c)
{
case EOF:
- /* Non-empty files should end in a newline. Ignore for command
- line and _Pragma buffers. */
- if (pfile->lexer_pos.col != 0 && !buffer->from_stage3)
+ /* Non-empty files should end in a newline. Checking "bol" is
+ enough to get this right, and also prevents multiple warnings
+ when hitting the EOF more than once, like in a directive.
+ Don't warn for command line and _Pragma buffers. */
+ if (!bol && !buffer->from_stage3)
cpp_pedwarn (pfile, "no newline at end of file");
pfile->state.next_bol = 1;
pfile->skipping = 0; /* In case missing #endif. */