https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67429
--- Comment #9 from Manuel López-Ibáñez <manu at gcc dot gnu.org> --- Even with the original patch applied to r227391, I cannot reproduce the error that you get. On x86_64-linux-gnu, I get: Starting program: /home/manuel/test1/226953M/build/gcc/f951 ~/test1/src/gcc/testsuite/gfortran.dg/pr65045.f90 /home/manuel/test1/src/gcc/testsuite/gfortran.dg/pr65045.f90:7:6: Error: Symbol ‘i’ at (1) is not appropriate for an expression /home/manuel/test1/src/gcc/testsuite/gfortran.dg/pr65045.f90:9:59: else ! { dg-error "Unexpected ELSE statement" } 1 Error: Unexpected ELSE statement at (1) /home/manuel/test1/src/gcc/testsuite/gfortran.dg/pr65045.f90:10:6: Error: ‘i’ at (1) is not a variable /home/manuel/test1/src/gcc/testsuite/gfortran.dg/pr65045.f90:11:6: end if ! { dg-error "Expecting END BLOCK statement" } 1 Error: Expecting END BLOCK statement at (1) /home/manuel/test1/src/gcc/testsuite/gfortran.dg/pr65045.f90:13:8: print*,i ! { dg-error "not appropriate for an expression" } 1 Error: Symbol ‘i’ at (1) is not appropriate for an expression However, there is a bug indeed. The first caret line is not printed because there was a previous buffered error at the same location that later got cleared. However, clearing it does not reset context->last_location, which is checked in gfc_diagnostic_starter. This patch seems to fix it: Index: error.c =================================================================== --- error.c (revision 227391) +++ error.c (working copy) @@ -755,10 +755,13 @@ gfc_clear_pp_buffer (output_buffer *this pretty_printer *pp = global_dc->printer; output_buffer *tmp_buffer = pp->buffer; pp->buffer = this_buffer; pp_clear_output_area (pp); pp->buffer = tmp_buffer; + /* We need to reset last_location, otherwise we may skip caret lines + when we actually give a diagnostic. */ + global_dc->last_location = UNKNOWN_LOCATION; } However, it is not a very nice solution. It may happen that we give an error at location X, then we buffer some errors, then we clear them, so we reset last location to UNKNOWN, then we give an error at location X and we will get a duplicated caret line. Thus, it would be better if last_location was only updated when we actually flush the output text. However, that would require some deeper changes, probably in diagnostic.c and in fortran/error.c to handle both buffered and not buffered output_buffers. On the other hand, I'm not sure the previous Fortran diagnostic machinery cared about duplicated caret lines, thus perhaps the above is enough. BTW, you should use %qs instead of '%s' in order to get quoting localized to the user's language and color highlighting.