[gfortran] PATCH Fix PR 19936

Steve Kargl sgk@troutmask.apl.washington.edu
Sun Feb 13 17:57:00 GMT 2005


Gfortran issues an interest error message for the
following:

program main
  integer, parameter :: i=4
  print *,(/(i,i=1,4)/)
end program main
$ gfortran implied_parameter.f90
 In file implied_parameter.f90:3

  print *,(/(i,i=1,4)/)
               1
Error: Syntax error in COMPLEX constant at (1)

The problem is that the matcher match_complex_constant() is
run before the matcher for implied do-loops.  The matcher
essentially sees (/ (4,4=1,4) /) after the parameter statement
is used.  The sequence "(4,4" is matched to a complex constant
and the matcher is expecting a closing ")", which of course
is not found and hence the error message.

The attached patch gives the implied do-loop matcher a 
chance to run, and hence issue a much saner error message.

kargl[237] gfc -o ba ba.f90
 In file ba.f90:3

  print *,(/(i,i=1,4)/)
               1
Error: Expected VARIABLE at (1)

The case of a mangled complex constant is still caught.
kargl[237] cat bc.f90
program bc
  complex z
  z = (1,4z)
  print *, z
end program bc
kargl[240] gfc -o z bc.f90
 In file bc.f90:3

  z = (1,4z)
         1
Error: Syntax error in COMPLEX constant at (1)

There is minor exception, but a sensible error message is still
emitted.

kargl[238] cat bc.f90
program bc
  complex z
  z = (1,4=)
  print *, z
end program bc
kargl[239] gfc -o z bc.f90
 In file bc.f90:3

  z = (1,4=)
 1
Error: Unclassifiable statement at (1)


2005-02-13  Steven G. Kargl  <kargls@comcast.net>

      PR 19936
      * primary.c (match_complex_constant): Mangled complex constant may
      be an implied do-loop.  Give implied do-loop matcher a chance.
-- 
Steve
-------------- next part --------------
Index: primary.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/primary.c,v
retrieving revision 1.19
diff -u -b -u -r1.19 primary.c
--- primary.c	7 Feb 2005 22:16:13 -0000	1.19
+++ primary.c	13 Feb 2005 17:32:33 -0000
@@ -1076,7 +1076,17 @@
 
   m = gfc_match_char (')');
   if (m == MATCH_NO)
+    {
+      /* Give the matcher for implied do-loops a chance to run.  This
+	 yield a much saner error message for (/ (i, 4=i, 6) /).  */
+      if (gfc_peek_char () == '=')
+	{
+	  m = MATCH_ERROR;
+	  goto cleanup;
+	}
+      else
     goto syntax;
+    }
 
   if (m == MATCH_ERROR)
     goto cleanup;


More information about the Fortran mailing list