This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[gfortran] PR17222: Functions with derived type


Since Scott didn't find time to finish his patch, I took a look at what needs
to be done for derived type returns, and I have to say that I was surprised by
how easy this was: after removing the TODO error, the compiler does the right
thing all by itself.

Built and tested, new testcase attached.

- Tobi

2004-08-31  Tobias Schlueter  <tobias.schlueter@physik.uni-muenchen.de>

	PR fortran/17222
	* trans-types.c (gfc_return_by_reference): Remove TODO error,
	add comment pointing out possible issue WRT compatibility with g77.

Index: trans-types.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/trans-types.c,v
retrieving revision 1.23
diff -u -p -r1.23 trans-types.c
--- trans-types.c       31 Aug 2004 14:06:47 -0000      1.23
+++ trans-types.c       31 Aug 2004 16:27:19 -0000
@@ -1451,9 +1451,7 @@ gfc_return_by_reference (gfc_symbol * sy
   if (sym->ts.type == BT_CHARACTER)
     return 1;

-  if (sym->ts.type == BT_DERIVED)
-    gfc_todo_error ("Returning derived types");
-  /* Possibly return derived types by reference.  */
+  /* Possibly return complex numbers by reference for g77 compatibility.  */
   return 0;
 }



! { dg-do run }
! PR 17244
! verifies that functions returning derived type work
module m
  type t
     integer i
     real x
     character*5 c
     integer arr(5,5)
  end type t
end module m

use m
type(t) :: r
integer arr(5,5), vect(25), vect2(25)
do i=1,25
   vect = 0
   vect(i) = i
   arr = reshape (vect, shape(arr))
   r = f(i,real(i),"HALLO",arr)

   if (r%i .ne. i) call abort()
   if (r%x .ne. real(i)) call abort()
   if (r%c .ne. "HALLO") call abort()
   vect2 = reshape (r%arr, shape(vect2))
   if (any(vect2.ne.vect)) call abort()
end do
contains

function f(i,x,c,arr)
  type(t) :: f
  character*5 c
  integer arr(5,5)
  
  f = t(i,x,c,arr)
end function f

end

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]