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

            Bug ID: 82161
           Summary: Failure of a complicated initialization expression
           Product: gcc
           Version: 8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pault at gcc dot gnu.org
  Target Milestone: ---

As reported on
https://groups.google.com/forum/#!topic/comp.lang.fortran/yqT4TInGjC0 by James
Van Buskirk:

program data_var2
   implicit none
   integer, parameter :: IMAX = 2, JMAX = 3, NMAX = 4
   type mydata
      real var(NMAX)
   end type mydata
   integer i, j, n
   type(mydata), parameter :: data(IMAX, JMAX) = reshape( &
      [((mydata([(1.0e2*i+1.0e1*j+1.0e0*n,n=1,NMAX)]), &
      i=1,IMAX),j=1,JMAX)], [IMAX,JMAX])

end program data_var2

produces

[pault@pc30 pdt]$ ~/irun/bin/gfortran -static-libgfortran init.f90
-fdump-tree-original -g
init.f90:9:25:

       [((mydata([(1.0e2*i+1.0e1*j+1.0e0*n,n=1,NMAX)]), &
                         1
Error: Parameter ā€˜i’ at (1) has not been declared or is a variable, which does
not reduce to a constant expression


* On the other hand, this compiles fine:

program data_var2
   implicit none
   integer, parameter :: IMAX = 2, JMAX = 3, NMAX = 4
   type mydata
      real var(NMAX)
   end type mydata
   integer i, j, n
   type(mydata), parameter :: data(IMAX, JMAX) = reshape( &
      [((mydata([(1.0e0*n,n=1,NMAX)]), &
      i=1,IMAX),j=1,JMAX)], [IMAX,JMAX])

end program data_var2

In the original testcase, simplification is obviously thrown by having to deal
with both the array constructor, which  appears as an argument of the derived
type constructor, and the outer array constructor. In particular, 'i' and 'j'
are not being recognised as parameters.

Regards

Paul

Reply via email to