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

            Bug ID: 102240
           Summary: [F03] derived type parameter does not shadow variable
                    name in enclosing scope
           Product: gcc
           Version: 9.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: roland_wirth at web dot de
  Target Milestone: ---

Consider the following module definition:

    MODULE mo
    IMPLICIT NONE

    INTEGER :: n

    TYPE t(n)
      INTEGER, LEN :: n
      INTEGER :: a(n)
    END TYPE t
    END MODULE

gfortran 9.1.0 produces the following error when trying to compile:

        8 |     INTEGER :: a(n)
          |                 1
    Error: Variable 'n' at (1) in this context must be constant

Upon renaming the INTEGER variable to some other name `nn` the unit compiles
fine.

The Fortran 2003 standard (N1601) says in the Host association section
[16.4.1.3] that "A name that appears in the scoping unit as [...] (3) A
type-param-name in a derived-type-stmt [...] is a local identifier in the
scoping unit and any entity of the host that has this as its nongeneric name is
inaccessible by that name by host association." If I read that correctly the
type parameter `n` shadows the variable `n`, and the module definition should
be valid Fortran.

Reply via email to