- /* Non-empty files should end in a newline. Checking "bol" too
- prevents multiple warnings when hitting the EOF more than
- once, like in a directive. Don't warn for command line and
- _Pragma buffers. */
- if (pfile->lexer_pos.col != 0 && !bol && !buffer->from_stage3)
- cpp_pedwarn (pfile, "no newline at end of file");
- pfile->state.next_bol = 1;
- pfile->state.skipping = 0; /* In case missing #endif. */
+ /* Non-empty files should end in a newline. Don't warn for
+ command line and _Pragma buffers. */
+ if (pfile->lexer_pos.col != 0)
+ {
+ /* Account for the missing \n, prevent multiple warnings. */
+ pfile->line++;
+ pfile->lexer_pos.col = 0;
+ if (!buffer->from_stage3)
+ cpp_pedwarn (pfile, "no newline at end of file");
+ }
+
+ /* To prevent bogus diagnostics, only pop the buffer when
+ in-progress directives and arguments have been taken care of.
+ Decrement the line to terminate an in-progress directive. */
+ if (pfile->state.in_directive)
+ pfile->lexer_pos.output_line = pfile->line--;
+ else if (! pfile->state.parsing_args)
+ {
+ /* Don't pop the last buffer. */
+ if (buffer->prev)
+ {
+ unsigned char stop = buffer->return_at_eof;
+
+ _cpp_pop_buffer (pfile);
+ if (!stop)
+ goto next_token;
+ }
+ }