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

            Bug ID: 61376
           Summary: Error using private statement in polymorphic derived
                    type
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: stuart.moffatt at axsym dot co.uk

I am getting a compiler error with the gfortran v4.9.0 compiler when using the
private statement within a derived type class that is used to form a
polymorphic object. Conversely, ifort v14.0.2 does compile this code
successfully and the executable runs without error. The example source code
below results in the following error message from gfortran:

*** START ERROR MESSAGE ***
ch2605.poly.f90:58.2:

  s %x = shape_type(3)
  1
Error: Assignment to an allocatable polymorphic variable at (1) is not yet
supported
*** END ERROR MESSAGE ***

If the private statement is commented out and the entire shape_module
attributes/methods are made public, then gfortran compiles the code
successfully. It appears that there is no straightforwward way to make the
contents of the base derived type private. 

Notes: I have adapted this example source code from ch2605_2.f90 on the
fortranplus website. Standard gcc-4.9 installation using apt-get on Ubuntu
14.04 LTS. gfortran compiler options: -fcoarray=single.

*** START EXAMPLE SOURCE CODE ***
! Test to demonstrate problem private attributesin polymorphic 
! derived type using gfortan v4.9.0 (works OK in ifort v14.0.2)

module shape_module
  implicit none
  private        ! *** Commenting out this statement works with gfortran v4.9.0
  type shape_type
    integer :: n_ 
    character(len=2), allocatable, dimension(:) :: cname_  
  contains
    procedure, pass(this) :: get_size
  end type shape_type
  interface shape_type
    module procedure shape_type_constructor
  end interface
  interface assignment (=)
    module procedure generic_shape_assign
  end interface
  public :: shape_type, generic_shape_assign
  public :: shape_type_constructor, get_size ! *** Not even this works.
contains

  type (shape_type) function shape_type_constructor(n)
    implicit none
    integer, intent (in) :: n
    shape_type_constructor%n_ = n
    allocate ( shape_type_constructor%cname_(n) ) 
  end function shape_type_constructor

  integer function get_size(this)
    implicit none
    class (shape_type), intent (in) :: this
    get_size = size(this%cname_)
  end function get_size

  subroutine generic_shape_assign(lhs,rhs)
    implicit none
    class (shape_type), intent (out), allocatable :: lhs
    class (shape_type), intent (in) :: rhs
    allocate (lhs,source=rhs)
  end subroutine generic_shape_assign
end module shape_module


module shape_wrapper_module
  use shape_module
  type shape_wrapper
  class (shape_type), allocatable :: x
  end type shape_wrapper
end module shape_wrapper_module


program ch2605_mod
  use shape_module
  use shape_wrapper_module
  implicit none
  type (shape_wrapper) :: s
  s %x = shape_type(3)
  print *, 'size = ', s%x%get_size()
end program ch2605_mod
*** END EXAMPLE SOURCE CODE ***

Reply via email to