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

            Bug ID: 124639
           Summary: New Fortran 2018 IMPORT statement fails with derived
                    types
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: martinjotte at gmail dot com
  Target Milestone: ---

Hello,

The new "import, only" Fortran syntax added to the latest compiler does not
seem to work with derived types. Consider this simple program:

program test
  implicit none

  type mytype
     integer :: i
     real    :: r
  end type mytype

  type(mytype) :: myvar

  read(*,*) myvar%i
  call sub

contains

  subroutine sub
    import, only: myvar
    write(*,*) myvar%i
  end subroutine sub

end program test

Compiling with a recent development gfortran gives:

gfortran test2.f90
test2.f90:18:14:

   18 |     write(*,*) myvar%i
      |              1
Error: F2018: C8102 'mytype' at (1) is host associated but does not appear in
an IMPORT or IMPORT, ONLY list

It looks like gfortran is expecting the type definition along with the variable
name in the import statement. If I change the import line to "import, only:
myvar, mytype" it does compile, but this should not be necessary.

I am using: gfortran --version
GNU Fortran (GCC) 16.0.1 20260325 (experimental)

Reply via email to