http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49791

--- Comment #19 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-02-05 
23:00:16 UTC ---
I think the patch suggested in
http://gcc.gnu.org/ml/fortran/2011-07/msg00252.html is actually correct - which
then fixes the issue of comment 18. 

--- ../../libgfortran/io/list_read.c    (Revision 183913)
+++ ../../libgfortran/io/list_read.c    (Arbeitskopie)
@@ -2206,3 +2211,4 @@ nml_parse_qualifier (st_parameter_dt *dt
                      || !(compile_options.allow_std & GFC_STD_GNU)
-                     || dtp->u.p.ionml->type == BT_DERIVED)
+                     || (dtp->u.p.ionml->type == BT_DERIVED
+                         && !dtp->u.p.ionml->touched))
                    ls[dim].end = ls[dim].start;


However, one then runs into a failure for fortran.dg/namelist_66.f90, but it
fails in the same way for the program below. Contrary to comment 18 (which is
about a vendor extension), I believe the following program *is* valid. At least
one combines an incomplete read of the whole array "(:)" with some explicit
reads.


One should recall that in namelist, all character constants have to start with
a quotation mark. Thus, if one reads [a-z], one is always matching a namelist
object name! Thus, before reading the next array element, one should check
whether one has as next item something starting with "a-zA-z"; if so, one does
an early return from nml_read_obj



Expected (as with NAG):
 &NAML1 TRACER = aa T bb T XX F/

Result with gfortran:
 Fortran runtime error: Cannot match namelist object name 'bb'


Example:

type ptracer
   character(len = 2)  :: sname
   logical              :: lini
end type ptracer
type(ptracer) , dimension(3) :: tracer
namelist/naml1/  tracer

tracer(:) = ptracer('XXX', .false.)
open (99, file='nml.dat', status="replace")
write(99,*) "&naml1"
write(99,*) "   tracer(:)   = 'aa' , .true."
write(99,*) "   tracer(2)   = 'bb' , .true. /"
rewind(99)
read (99, nml=naml1)
write (*, nml=naml1)
close (99, status="delete")
end



Using the following early draft patch, the example above works. However, if one
changes one tracer(2) line to:
  write(99,*) "   tracer(2)   = 'bb' , .true. "
(i.e. removes the "/") one gets:
  Fortran runtime error: End of file
which looks reasonable.

However, if one adds after that line:
  write(99,*) "   tracer(3)   = 'cc' , .true. "
one now gets:
  Fortran runtime error: Internal namelist read error

It works correctly if a "/" is added in the last write above.


Hence, I think the patch is in the correct direction, but not yet ready.

--- ../../libgfortran/io/list_read.c    (Revision 183913)
+++ ../../libgfortran/io/list_read.c    (Arbeitskopie)
@@ -2517,2 +2518,19 @@ nml_read_obj (st_parameter_dt *dtp, name

+/*       if (dtp->u.p.expanded_read)*/
+           {
+             char c;
+
+             /* Skip whitespace.  */
+             do
+               c = next_char (dtp);
+             while (c != EOF && (c == ' ' || c == '\t' || c == '\r' || c ==
'\n'));
+             unget_char (dtp, c);
+
+             /* Stop early - next namelist object found. */
+             if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'))
+             {
+               return SUCCESS;
+             }
+           }
+
           switch (nl->type)

Reply via email to