Please consider the following code:

module m

  implicit none
  private

  public :: public_t
  public :: public_sub
  !public :: private_t  (*)

  type :: private_t
    integer :: i
  end type

  type :: public_t
     type(private_t), pointer :: public_comp_with_private_type  !(#1)
     procedure(ifc) , nopass, pointer :: ppc
  end type

  abstract interface
     integer function ifc ()
     end function
  end interface

  type(private_t), save, public :: public_var_with_private_type !(#2)

contains

  subroutine public_sub(arg)    !(#3)
    type(private_t) :: arg
  end subroutine

end module m

program test
use m
implicit none
type(public_t) :: x
integer :: j
print *,public_var_with_private_type%i
j = x%ppc()  ! Error: Can't convert UNKNOWN to INTEGER(4)
end


With current trunk versions of gfortran, this produces the error indicated in
the last line of the program. Of course this error is bogus, since ppc has an
explicit interface (with an integer return type).

However, I believe this program is invalid for the following reason: The type
'public_t' is public in the module m, and it has a public component, indicated
by (#1), whose type is private in the module. So this component is accessible
outside of the module, but its type is not.

Up to now I was not able to find a rule in the F03 Standard, which explicitly
forbids this. But my common sense tells me that it should be invalid (hoping my
common sense works alright).

Following the same reasoning, the cases (#2) and (#3) should be invalid, too,
but none of them is detected by gfortran. Unfortunately, I could not find any
other compiler which rejects the program (ifort and g95 accept it). Still I
think it is invalid.

If the line indicated by (*) is uncommented, the error message goes away. With
this modification the program should be valid, and all is fine.

Thanks to Juergen Reuter for reporting this.


-- 
           Summary: Public type with public component which has a private
                    type
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: janus at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40089

Reply via email to