[patch,gfortran] PR 23843: IO on derived types with PRIVATE components

Erik Edelmann erik.edelmann@iki.fi
Wed Sep 21 20:35:00 GMT 2005


:ADDPATCH fortran:

Here is a patch for PR 23843.

Currently we reject code like

------------------
module gfortran2
    type tp
        private
        integer :: i
    end type
contains
    subroutine test(x)
        type(tp), intent(in) :: x
        write(*,*) x
    end subroutine test
end module
------------------

with the error message

        write(*,*) x
                   1
    Error: Data transfer element at (1) cannot have PRIVATE components

This is because, in resolve.c/resolve_transfer() we only check if
the type to be transferred has private components, but not if it
is defined in the same module.  To fix the problem, I added a check to
see if the type is use associated.

Bubblestrapped and reg.tested on mainline & 4.0, Linux/x86.
Please commit if OK.


2005-09-21  Erik Edelmann  <erik.edelmann@iki.fi>

        PR fortran/23843
        * resolve.c (resolve_transfer): For types with PRIVATE
          components, also check if the type is use associated.


2005-09-21  Erik Edelmann  <erik.edelmann@iki.fi>

        PR fortran/23843
        * gfortran.dg/der_io_2.f90: New test.



        Erik
-------------- next part --------------
Index: gcc/fortran/resolve.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/fortran/resolve.c,v
retrieving revision 1.54
diff -u -p -r1.54 resolve.c
--- gcc/fortran/resolve.c	18 Sep 2005 05:50:01 -0000	1.54
+++ gcc/fortran/resolve.c	21 Sep 2005 20:14:16 -0000
@@ -3184,7 +3184,8 @@ resolve_select (gfc_code * code)
 
 /* Resolve a transfer statement. This is making sure that:
    -- a derived type being transferred has only non-pointer components
-   -- a derived type being transferred doesn't have private components
+   -- a derived type being transferred doesn't have private components, unless 
+      it's being transferred from the module where the type was defined
    -- we're not trying to transfer a whole assumed size array.  */
 
 static void
@@ -3219,7 +3220,8 @@ resolve_transfer (gfc_code * code)
 	  return;
 	}
 
-      if (ts->derived->component_access == ACCESS_PRIVATE)
+      if (ts->derived->attr.use_assoc 
+          && ts->derived->component_access == ACCESS_PRIVATE)
 	{
 	  gfc_error ("Data transfer element at %L cannot have "
 		     "PRIVATE components",&code->loc);
-------------- next part --------------
! { dg-do compile }
! PR 23843
! IO of derived types with private components allowed in the module itself,
! but not elsewhere
module gfortran2
    type tp
        private
        integer :: i
    end type
contains
    subroutine test(x)
        type(tp), intent(in) :: x
        write(*,*) x
    end subroutine test
end module

program prog
    use gfortran2
    implicit none
    type(tp) :: Y

    write (*, *) Y  ! { dg-error "PRIVATE components" }
end program prog


More information about the Gcc-patches mailing list