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

--- Comment #2 from G. Steinmetz <gs...@t-online.de> ---

Hmm, exploring some more test cases;
z2 gives same ICE, z3 prints 128, z4 gives an error, z5 is ok/works :

$ cat z2.f90
program p
   type t
      character(:), allocatable :: c
   end type
   type(t) :: x                 ! without = t()
   integer, parameter :: n = storage_size(x)
end

$ cat z3.f90
program p
   type t
      character(:), allocatable :: c
   end type
   type(t), parameter :: x = t()   ! that is t(null())
   integer :: n = storage_size(x)
   print *, n
end

$ cat z4.f90
program p
   type t
      character(:), allocatable :: c
   end type
   type(t), parameter :: x = t('abc')   ! instead of t(null())
   integer :: n = storage_size(x)
   print *, n
end

$ cat z5.f90
program p
   type t
      character(:), allocatable :: c
   end type
   type(t) :: x 
   integer :: n
   n = storage_size(x)
   print *, n
end

---

Some examples without "type" :

$ cat zz1.f90
program p
   character(:), allocatable :: c
   integer :: n = storage_size(c)
   print *, n
end

$ cat zz2.f90
program p
   character(:), allocatable :: c
   integer, parameter :: n = storage_size(c)
   print *, n
end

$ cat zz3.f90
program p
   character(:), allocatable :: c
   print *, storage_size(c)
end


$ gfortran-13-20220619 -c zz1.f90
zz1.f90:3:31:

    3 |    integer :: n = storage_size(c)
      |                               1
Error: Parameter 'c' at (1) has not been declared or is a variable, which does
not reduce to a constant expression
$
$ gfortran-13-20220619 -c zz2.f90
zz2.f90:3:42:

    3 |    integer, parameter :: n = storage_size(c)
      |                                          1
Error: Parameter 'c' at (1) has not been declared or is a variable, which does
not reduce to a constant expression
$
$ gfortran-13-20220619 zz3.f90 ; a.out
           0
$

Via Compiler Explorer :
Latest ifort/ifx indeed compiles z1/2/3/5, rejects z4 with an error (ok).
Latest ifort/ifx rejects zz1/zz2 with an error, accepts zz3 and prints 0.

Reply via email to