https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109099

Jerry DeLisle <jvdelisle at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jvdelisle at gcc dot gnu.org

--- Comment #5 from Jerry DeLisle <jvdelisle at gcc dot gnu.org> ---
Well I got curious here as I implemented many of the namelist features and have
not seen too many namelist related bugs.  This is with the example in the
original post.

$ gfc -std=f2003 pr109099.f90 
$ ./a.out 
At line 9 of file pr109099.f90
Fortran runtime error: Cannot match namelist object name 234

My thinking is auto-filling anything is a legacy extension.

Now if one comments out the READ and sees how gfortran writes the namelist:

$ gfc -std=f2003 pr109099.f90 
$ ./a.out 
&GROUP
 X= 12*999        ,
 /

My own thought is that it is always good to check things this way to see if the
"form" of the namelist input is good. Modifying your program:

program testit
integer, allocatable :: x(:,:); namelist / group / x
character(len=80) :: input(3)
   allocate( x(3,4),source=999)
   x = reshape ([999, 999, 999, 999, 999, 999, 1, 2, 3, 4, 999, 999], [3, 4]) 
   print *, shape(x), size(x)
   input=[&
   "&group          ",&
   " x(2,3)=1,2,3,4,",&
   "/               "]
   !read( input, nml=group)
   write(*,group)
end program testit

Assuming I have your intent right in the reshape.

$ ./a.out 
           3           4          12
&GROUP
 X= 6*999        ,1          ,2          ,3          ,4          ,
  2*999        ,
 /

and then doing the following shows a safer way to do these things:

program testit
integer, allocatable :: x(:,:); namelist / group / x
character(len=20) :: input(3)
   allocate( x(3,4),source=999)
   input=["&GROUP            ",&
   " X= 6*999,1,2,3,4,",&
   " 2*999,/          "]
   read( input, nml=group)
   write(*,group)
end program testit

$ gfc -std=f2003 pr109099.f90 
$ ./a.out 
&GROUP
 X= 6*999        ,1          ,2          ,3          ,4          ,
  2*999        ,
 /

Reply via email to