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]

[gfortran] Optional comma after string literal in format


The following patch adds support for an extension to make the
comma separator after a string literal optional in fortran formats,
if the user hasn't specified -pedantic.

Whilst trying to compile some dusty deck FORTRAN (the semi-empirical
quantum mechanics program MOPAC), I discovered that the source code
contained examples of the following:

       PRINT 10, 4
10     FORMAT ('2+2='I1)
       END

The missing comma generates a hard error with both g77 and gfortran.
However, testing on various other fortran compilers reveals that both
the native Tru64 and IRIX fortran compilers compile the above code
without comment, and the AIX fortran compiler issues a warning but
succeeds in generating a binary executable.

The patch below allows gfortran to also compile this code.

The following patch has been tested on i686-pc-linux-gnu with a full
bootstrap, including gfortran, and regression tested with a top-level
"make -k check" with no new failures.

Ok for mainline?


2004-05-20  Roger Sayle  <roger@eyesopen.com>

	* io.c (format_item): If we're not being pedantic, allow the
	comma after a string literal to be optional in a format.

	* io/format.c (parse_format_list): Allow the comma after a string
	literal to be optional.

	* compile/format-1.f: New testcase.


Index: gcc/fortran/io.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/io.c,v
retrieving revision 1.3
diff -c -3 -p -r1.3 io.c
*** gcc/fortran/io.c	14 May 2004 13:00:04 -0000	1.3
--- gcc/fortran/io.c	20 May 2004 17:17:32 -0000
*************** format_item:
*** 477,484 ****

      case FMT_SIGN:
      case FMT_BLANK:
-     case FMT_CHAR:
        goto between_desc;

      case FMT_COLON:
      case FMT_SLASH:
--- 477,489 ----

      case FMT_SIGN:
      case FMT_BLANK:
        goto between_desc;
+
+     case FMT_CHAR:
+       /* Require a comma after a string if we're being pedantic.  */
+       if (pedantic)
+ 	goto between_desc;
+       goto optional_comma;

      case FMT_COLON:
      case FMT_SLASH:
Index: libgfortran/io/format.c
===================================================================
RCS file: /cvs/gcc/gcc/libgfortran/io/format.c,v
retrieving revision 1.3
diff -c -3 -p -r1.3 format.c
*** libgfortran/io/format.c	13 May 2004 23:36:16 -0000	1.3
--- libgfortran/io/format.c	20 May 2004 17:17:32 -0000
*************** format_item:
*** 542,548 ****
        tail->u.string.p = string;
        tail->u.string.length = value;
        tail->repeat = 1;
!       goto between_desc;

      case FMT_S:
      case FMT_SS:
--- 542,548 ----
        tail->u.string.p = string;
        tail->u.string.length = value;
        tail->repeat = 1;
!       goto optional_comma;

      case FMT_S:
      case FMT_SS:



       PRINT 10, 4
10     FORMAT ('2+2='I1)
       END


Roger
--
Roger Sayle,                         E-mail: roger@eyesopen.com
OpenEye Scientific Software,         WWW: http://www.eyesopen.com/
Suite 1107, 3600 Cerrillos Road,     Tel: (+1) 505-473-7385
Santa Fe, New Mexico, 87507.         Fax: (+1) 505-473-0833


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