[patch/gfortran] fix to pr 15365

Victor Leikehman lei@haifasphere.co.il
Tue May 11 08:39:00 GMT 2004


When a variable of derived type was defined without :: (such as b in the
example below), its initializer was not set to the default initializer.
Fixed as attached.  Regtested.
	Victor

program main
  type xyz
     integer :: x = 123
  end

  type (xyz) :: a  !! ok
  type (xyz) b    !!! not initialized !!!
  print*, a%x, b%x
  if (a%x.ne.123) call abort
  if (b%x.ne.123) call abort
end



Index: decl.c
===================================================================
RCS file: /home/lei/cvsroot/fortran/decl.c,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 decl.c
--- decl.c	4 Feb 2004 11:42:50 -0000	1.1.1.1
+++ decl.c	11 May 2004 07:39:17 -0000
@@ -619,10 +619,11 @@ variable_decl (void)
 	  if (m != MATCH_YES)
 	    goto cleanup;
 	}
-      else if (current_ts.type == BT_DERIVED)
-        {
-          initializer = default_initializer ();
-        }
+    }
+
+  if (current_ts.type == BT_DERIVED && !initializer)
+    {
+      initializer = default_initializer ();
     }

   /* Add the initializer.  Note that it is fine if &initializer is
-- 
  Victor Leikehman
  IBM Research Labs in Haifa, Israel



More information about the Fortran mailing list