2010-07-28  Tobias Burnus  <burnus@net-b.de>

	PR fortran/45077
	* trans-types.c (gfc_get_derived_type): Fix DT declaration
	from modules for whole-file mode.

2010-07-28  Tobias Burnus  <burnus@net-b.de>

	PR fortran/45077
	* gfortran.dg/whole_file_24.f90: New.

Index: gcc/fortran/trans-types.c
===================================================================
--- gcc/fortran/trans-types.c	(revision 162617)
+++ gcc/fortran/trans-types.c	(working copy)
@@ -1994,8 +1994,10 @@ gfc_get_derived_type (gfc_symbol * deriv
 	  gfc_symbol *s;
 	  s = NULL;
 	  gfc_find_symbol (derived->name, gsym->ns, 0, &s);
-	  if (s && s->backend_decl)
+	  if (s)
 	    {
+	      if (!s->backend_decl)
+		s->backend_decl = gfc_get_derived_type (s);
 	      gfc_copy_dt_decls_ifequal (s, derived, true);
 	      goto copy_derived_types;
 	    }
Index: gcc/testsuite/gfortran.dg/whole_file_24.f90
===================================================================
--- gcc/testsuite/gfortran.dg/whole_file_24.f90	(revision 0)
+++ gcc/testsuite/gfortran.dg/whole_file_24.f90	(revision 0)
@@ -0,0 +1,35 @@
+! { dg-do compile }
+!
+! PR fortran/45077
+!
+! Contributed by Dominique d'Humieres, based on a test
+! case of Juergen Reuter.
+!
+
+module iso_red
+  type, public :: varying_string
+     character(LEN=1), dimension(:), allocatable :: chars
+  end type varying_string
+end module iso_red
+
+module ifiles
+  use iso_red, string_t => varying_string
+contains
+  function line_get_string_advance (line) result (string)
+    type(string_t) :: string
+    character :: line
+  end function line_get_string_advance
+end module ifiles
+
+module syntax_rules
+  use iso_red, string_t => varying_string
+  use ifiles, only: line_get_string_advance
+contains
+  subroutine syntax_init_from_ifile ()
+    type(string_t) :: string
+       string = line_get_string_advance ("")
+  end subroutine syntax_init_from_ifile
+end module syntax_rules
+end
+
+! { dg-final { cleanup-modules "iso_red ifiles syntax_rules" } }
