Hi: It seems that gfortran can get confused about namelists that include 2 ! on the same line. The following code fails to execute properly with gfortran 4.3.0: cat > t.nml <<EOF &nbdrive_naml !nstep_stop = 2 ! uncomment to save restart data and halt after 1st step !nstep_start = 2 ! uncomment to restart on 2nd step using saved restart data mhdpath = 'EFIT:efit_d3d_99411_195.dat' EOF cat > t.f90 <<EOF program test character(len=128) :: mhdpath namelist /nbdrive_naml/ mhdpath open(10, file='t.nml') read(10, nbdrive_naml) close(10) write(*, nbdrive_naml) end program test EOF gfortran t.f90 ./a.out At line 5 of file t.f90 (unit = 10, file = 't.nml') Fortran runtime error: End of file
(In reply to comment #0) Oops, the failing namelist was: &nbdrive_naml !nstep_stop = 2 ! uncomment to save restart data and halt after 1st step !nstep_start = 2 ! uncomment to restart on 2nd step using saved restart data mhdpath = 'EFIT:efit_d3d_99411_195.dat' / and the erro message is Fortran runtime error: Cannot match namelist object name !nstep_start Note: the initial blank line is essential in order to reproduce the problem. Thanks for your help. --Alex > Hi: It seems that gfortran can get confused about namelists that include 2 ! on > the same line. The following code fails to execute properly with gfortran > 4.3.0: > > cat > t.nml <<EOF > &nbdrive_naml > !nstep_stop = 2 ! uncomment to save restart data and halt after 1st step > !nstep_start = 2 ! uncomment to restart on 2nd step using saved restart data > mhdpath = 'EFIT:efit_d3d_99411_195.dat' > EOF > cat > t.f90 <<EOF > program test > character(len=128) :: mhdpath > namelist /nbdrive_naml/ mhdpath > open(10, file='t.nml') > read(10, nbdrive_naml) > close(10) > write(*, nbdrive_naml) > end program test > EOF > gfortran t.f90 > ./a.out > At line 5 of file t.f90 (unit = 10, file = 't.nml') > Fortran runtime error: End of file >
Confirmed. This is a regression. Personal candidate for this is PR 34530. I think the following patch is correct. Jerry what do you think? (I currently have no time to submit the patch.) Index: libgfortran/io/list_read.c =================================================================== --- libgfortran/io/list_read.c (Revision 133293) +++ libgfortran/io/list_read.c (Arbeitskopie) @@ -353,10 +353,7 @@ eat_separator (st_parameter_dt *dtp) { c = next_char (dtp); if (c == '!') - { - eat_line (dtp); - c = next_char (dtp); - } + eat_line (dtp); } while (c == '\n' || c == '\r' || c == ' '); unget_char (dtp, c);
I will test and fix.
Naturally, the patch in comment #2 breaks namelist_44.f90 (I say that because, after all, we are up to 44 namelist test cases, and about to go to 45 :) ) Nevertheless, this fixes it and passes regression. Index: list_read.c =================================================================== --- list_read.c (revision 133275) +++ list_read.c (working copy) @@ -356,6 +356,11 @@ eat_separator (st_parameter_dt *dtp) { eat_line (dtp); c = next_char (dtp); + if (c == '!') + { + eat_line (dtp); + c = next_char (dtp); + } } } while (c == '\n' || c == '\r' || c == ' '); eatline leaves us pointing to the first character of the next line, which we then get, which causes the while loop to exit, followed by an unget. So the next get char will get a '!' which is nonsense and can not be matched. The patch circumvents this special case. I will commit as obvious to trunk and then to 4.3 in a few days.
Subject: Bug 35617 Author: jvdelisle Date: Tue Mar 18 04:27:56 2008 New Revision: 133302 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=133302 Log: 2008-03-17 Jerry DeLisle <jvdelisle@gcc.gnu.org> PR libfortran/35617 * io/list_read.c (eat_separator): If next character after eatline is '!' then eatline again. Modified: trunk/libgfortran/ChangeLog trunk/libgfortran/io/list_read.c
Subject: Bug 35617 Author: jvdelisle Date: Tue Mar 18 04:30:37 2008 New Revision: 133303 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=133303 Log: 2008-03-17 Jerry DeLisle <jvdelisle@gcc.gnu.org> PR libfortran/35617 * gfortran.dg/namelist_45.f90: New test. Added: trunk/gcc/testsuite/gfortran.dg/namelist_45.f90 Modified: trunk/gcc/testsuite/ChangeLog
Fixed in trunk, will back port to 4.3
Subject: Bug 35617 Author: jvdelisle Date: Fri Mar 21 01:29:30 2008 New Revision: 133411 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=133411 Log: 2008-03-20 Jerry DeLisle <jvdelisle@gcc.gnu.org> PR libfortran/35627 Backport from trunk. * io/list_read.c (free_line): Clear the line buffer enable flag and reset the index into line_buffer, aka item_count. (next_char): Cleanup whitespace. (read_logical): Use unget_char to assure that the first character of the bad logical is saved in case it is part of an object name. Remove the clearing of index and flag that is now in free_line. (read_real): Likewise. PR libfortran/35617 Backport from trunk. * io/list_read.c (eat_separator): If next character after eatline is '!' then eatline again. Modified: branches/gcc-4_3-branch/libgfortran/ChangeLog branches/gcc-4_3-branch/libgfortran/io/list_read.c
Subject: Bug 35617 Author: jvdelisle Date: Fri Mar 21 01:37:38 2008 New Revision: 133413 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=133413 Log: 2008-03-20 Jerry DeLisle <jvdelisle@gcc.gnu.org> Backport from trunk: PR libfortran/35627 * gfortran.dg/namelist_46.f90: New test. PR libfortran/35617 * gfortran.dg/namelist_45.f90: New test. Added: branches/gcc-4_3-branch/gcc/testsuite/gfortran.dg/namelist_45.f90 Modified: branches/gcc-4_3-branch/gcc/testsuite/ChangeLog
Fixed on 4.3