This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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, libgfortran,fortran] Fix PR27634 Handling missing period in format specifier


:ADDPATCH fortran:

The attached patch allows a missing period in a real format specifier, interpreting it as 0 decimal places. At compile time a warning is given in all cases (unless -w is given) except -std=f95. -std=f95 gives a compile time error, regardless.

At runtime, no warnings or errors are given by default. If -pedantic, a run time warning is given. No executable is produced for -std=f95 so this is a do nothing for run time.

Simple test case:

      real      aval
      character str*6
      character(12) :: input = "1234abcdef"
      read(input,'(f4,a6)') aval, str
      end

I am working up a proper test case now.
Comments welcome as far as approach to this one. In particular, do we even want to do this?


OK for trunk and then 4.1 branch after freeze?

Regards,

Jerry

2006-05-21 Jerry DeLisle <jvdelisle@gcc.gnu.org>

	PR libgfortran/27634
	* io/format.c (parse_format_list): Allow missing period in format and
	warn if -pedantic.

2006-05-21 Jerry DeLisle <jvdelisle@gcc.gnu.org>

	PR fortran/27634
	* io.c (check_format): Add error for missing period in format
	specifier for -std=f95.  Give warning otherwise.

Index: gcc/fortran/io.c
===================================================================
*** gcc/fortran/io.c	(revision 113949)
--- gcc/fortran/io.c	(working copy)
*************** static try
*** 413,419 ****
  check_format (void)
  {
    const char *posint_required	  = _("Positive width required");
-   const char *period_required	  = _("Period required");
    const char *nonneg_required	  = _("Nonnegative width required");
    const char *unexpected_element  = _("Unexpected element");
    const char *unexpected_end	  = _("Unexpected end of format string");
--- 413,418 ----
*************** data_desc:
*** 610,617 ****
        u = format_lex ();
        if (u != FMT_PERIOD)
  	{
! 	  error = period_required;
! 	  goto syntax;
  	}
  
        u = format_lex ();
--- 609,620 ----
        u = format_lex ();
        if (u != FMT_PERIOD)
  	{
! 	  if (gfc_option.allow_std < GFC_STD_GNU)
! 	    gfc_error_now ("Period required in format specifier at %C");
! 	  else
! 	    gfc_warning ("Period required in format specifier at %C");
! 	  saved_token = t;
! 	  break;
  	}
  
        u = format_lex ();
*************** data_desc:
*** 653,660 ****
        t = format_lex ();
        if (t != FMT_PERIOD)
  	{
! 	  error = period_required;
! 	  goto syntax;
  	}
  
        t = format_lex ();
--- 656,667 ----
        t = format_lex ();
        if (t != FMT_PERIOD)
  	{
! 	  if (gfc_option.allow_std < GFC_STD_GNU)
! 	    gfc_error_now ("Period required in format specifier at %C");
! 	  else
! 	    gfc_warning ("Period required in format specifier at %C");
! 	  saved_token = t;
! 	  break;
  	}
  
        t = format_lex ();
Index: libgfortran/io/format.c
===================================================================
*** libgfortran/io/format.c	(revision 113949)
--- libgfortran/io/format.c	(working copy)
*************** parse_format_list (st_parameter_dt *dtp)
*** 725,732 ****
        t = format_lex (fmt);
        if (t != FMT_PERIOD)
  	{
! 	  fmt->error = period_required;
! 	  goto finished;
  	}
  
        t = format_lex (fmt);
--- 725,736 ----
        t = format_lex (fmt);
        if (t != FMT_PERIOD)
  	{
! 	  /* We treat missing decimal descriptor as 0.  
! 	     Warn on -pedantic.  */
! 	  fmt->saved_token = t;
! 	  tail->u.real.d = 0;
! 	  notify_std (GFC_STD_GNU, period_required);
! 	  break;
  	}
  
        t = format_lex (fmt);

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