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

            Bug ID: 127733
           Summary: Type parameter inquiry on an array complex part
                    designator (z%re%kind) is not scalar
           Product: gcc
           Version: 16.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ivan.pribec at gmail dot com
  Target Milestone: ---

A type parameter inquiry is expected to be scalar even if its designator is an
array (F2023 9.4.5, Note 1): "It is scalar even if *designator* is an array".

gfortran returns z%re%kind as a rank-1 array when z%re is an array complex part
designator, while z%kind is scalar.

program p
  implicit none
  complex :: z(3) = (1., 2.)

  print '(a,t30,i2)', 'rank of z%kind',         size(shape(z%kind))
  print '(a,t30,i2)', 'rank of z%re%kind',      size(shape(z%re%kind))
  print '(a,t30,i2)', 'rank of z(2:3)%im%kind', size(shape(z(2:3)%im%kind))
  print '(a,t30,*(i2))', 'z%re%kind', z%re%kind
end program

The output of this program is, 

rank of z%kind                0
rank of z%re%kind             1
rank of z(2:3)%im%kind        1
z%re%kind                     4 4 4

Because of the wrong rank, gfortran also rejects these valid statements
(z%re%kind is a constant expression):

integer, parameter :: kp = z%re%kind
    Error: Array 'z' at (1) is a variable, which does not reduce to a
           constant expression
k = z%re%kind                       ! integer :: k
   Error: Incompatible ranks 0 and 1 in assignment at (1)

The same declarations with z%kind are accepted.

It looks like only complex-part designators are affected; inquiries on
derived-type components (non-complex) of arrays of structures (e.g. a%x%kind,
...) are scalar.

Reply via email to