This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch, fortran] PR32545 Give compile error not warning for wrong edit format statements


The attached patch generates an error on bad formats and propagates that information up the call chain to check_io_constraints to give a MATCH_ERROR. Otherwise the error was getting buffered out and would not be seen.

Regression tested on latest trunk with x86-64-Gnu/Linux.

OK for trunk?

Regards,

Jerry

2007-07-03 Jerry DeLisle <jvdelisle@gcc.gnu.org>

	PR fortran/32545
	* io.c (check_format): Always call gfc_error for errors.
	(check_format_string): Change type of this function to try and
	return the result of check_format.
	(check_io_constraints): Return MATCH_ERROR if check_format_string
	returns FAILURE.
Index: io.c
===================================================================
*** io.c	(revision 126283)
--- io.c	(working copy)
*************** extension_optional_comma:
*** 842,861 ****
    goto format_item;
  
  syntax:
!   /* Something went wrong.  If the format we're checking is a string,
!      generate a warning, since the program is correct.  If the format
!      is in a FORMAT statement, this messes up parsing, which is an
!      error.  */
!   if (mode != MODE_STRING)
!     gfc_error ("%s in format string at %C", error);
!   else
!     {
!       gfc_warning ("%s in format string at %C", error);
! 
!       /* TODO: More elaborate measures are needed to show where a problem
! 	 is within a format string that has been calculated.  */
!     }
  
    rv = FAILURE;
  
  finished:
--- 842,851 ----
    goto format_item;
  
  syntax:
!   gfc_error ("%s in format string at %C", error);
  
+   /* TODO: More elaborate measures are needed to show where a problem
+      is within a format string that has been calculated.  */
    rv = FAILURE;
  
  finished:
*************** finished:
*** 866,877 ****
  /* Given an expression node that is a constant string, see if it looks
     like a format string.  */
  
! static void
  check_format_string (gfc_expr *e, bool is_input)
  {
    mode = MODE_STRING;
    format_string = e->value.character.string;
!   check_format (is_input);
  }
  
  
--- 856,867 ----
  /* Given an expression node that is a constant string, see if it looks
     like a format string.  */
  
! static try
  check_format_string (gfc_expr *e, bool is_input)
  {
    mode = MODE_STRING;
    format_string = e->value.character.string;
!   return check_format (is_input);
  }
  
  
*************** if (condition) \
*** 2752,2759 ****
      }
  
    expr = dt->format_expr;
!   if (expr != NULL && expr->expr_type == EXPR_CONSTANT)
!     check_format_string (expr, k == M_READ);
  
    return m;
  }
--- 2742,2750 ----
      }
  
    expr = dt->format_expr;
!   if (expr != NULL && expr->expr_type == EXPR_CONSTANT
!       && check_format_string (expr, k == M_READ) == FAILURE)
!     return MATCH_ERROR;
  
    return m;
  }
! { dg-do compile }
! PR32545 Give compile error not warning for wrong edit format statements.
read (5,'(i0)') i ! { dg-error "Error: Positive width required in format" }
end

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]