diff --git a/gcc/cpplex.c b/gcc/cpplex.c
index b4893bd5fccfe935bc8c90aceb5ba41afc0f0196..4f0767e42c8eaa916340d2433ebb999fdba2018d 100644
--- a/gcc/cpplex.c
+++ b/gcc/cpplex.c
@@ -776,6 +776,12 @@ _cpp_lex_direct (pfile)
       if (!_cpp_get_fresh_line (pfile))
 	{
 	  result->type = CPP_EOF;
+	  if (!pfile->state.in_directive)
+	    {
+	      /* Tell the compiler the line number of the EOF token.  */
+	      result->line = pfile->line;
+	      result->flags = BOL;
+	    }
 	  return result;
 	}
       if (!pfile->keep_tokens)