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

            Bug ID: 85395
           Summary: [7/8] F03 private clause contained in derived type
                    acquires spurious scope
           Product: gcc
           Version: 8.0.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: c...@mnet-mail.de
  Target Milestone: ---

The following valid Fortran2003 sample code fails to compile with gfortran
7.2.0/8.0.1, apparently because the private clause contained in derived
type "base2" obtains a spurious scope and affects the declaration of 
variables in the (subsequently defined) derived type "options":

$ cat scope.f90 
module defs

   implicit none

   private
   public :: base2, options

   abstract interface
      subroutine proc( res,a )
         real(8), dimension(:,:), intent(out) :: res
         real(8), dimension(:,:), intent(in) :: a
      end subroutine proc
   end interface

   type, abstract :: base1
   contains
   end type base1

   type, abstract :: base2
   contains
      ! This private clause acquires spurious scope
      private
   end type base2

   type, abstract, extends(base1) :: options
      procedure(proc), pointer, nopass :: ptr1
      procedure(proc), pointer, nopass :: ptr2
   contains
   end type options

end module defs


module setup

   use defs, only: options

   implicit none

   private
   public :: settings

   type, extends(options) :: settings
   contains
      procedure :: init
   end type settings

contains

   subroutine init(self)
      class(settings) :: self
      ! initialize procedure pointers
      self%ptr1 => null()
      self%ptr2 => null()
   end subroutine init

end module setup

Trying to compile this gives:

$ gfortran8 -c scope.f90 
scope.f90:53:15:

       self%ptr1 => null()
               1
Error: Component ‘ptr1’ at (1) is a PRIVATE component of ‘options’
scope.f90:54:15:

       self%ptr2 => null()
               1
Error: Component ‘ptr2’ at (1) is a PRIVATE component of ‘options’


Presently the only ways to get the above code to compile with gfortran
are by
i)  deleting the aforementioned private clause, or
ii) explicitly declaring the procedure pointers in type options as "public".

The original code compiles fine with pgfortran 17.4 and flang 6.0.
Gfortran version 8.0.1 used is:


Using built-in specs.
COLLECT_GCC=/home/kk/Gcc-8/bin/gfortran8
COLLECT_LTO_WRAPPER=/home/kk/Gcc-8/bin/../libexec/gcc/x86_64-pc-linux-gnu/8.0.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure --disable-checking
--enable-languages=c,c++,fortran --disable-multilib --enable-multiarch
--enable-shared --enable-threads=posix --program-suffix=8
--with-gmp=/usr/local/lib --with-mpc=/usr/lib --with-mpfr=/usr/lib
--without-included-gettext --with-system-zlib --with-tune=generic
--prefix=/home/kk/GCC-8
Thread model: posix
gcc version 8.0.1 20180409 (experimental) (GCC)

Reply via email to