[patch,gfortran] PR 24426: initialization of component pointers

Erik Edelmann erik.edelmann@iki.fi
Fri Oct 21 14:57:00 GMT 2005


:ADDPATCH fortran:

Here's a patch for PR 24426, a bug very similar to PR 15975/16606.  In code like

        type foo
            integer :: i = 0
            type (foo), pointer :: next
        end type foo

we try to assign a default initializer to foo%next, eventhough
it's a pointer.  This patch avoids assigning default initializers to
pointers.

Bubblestrapped and reg.tested on Linux/x86.
OK for mainline?  4.0?


        Erik


2005-10-21  Erik Edelmann  <eedelman@gcc.gnu.org>

        PR fortran/24426
        * decl.c (variable_decl): Don't assign default initializers to
          pointers.



2005-10-21  Erik Edelmann  <eedelman@gcc.gnu.org>

        PR fortran/24426
        * gfortran.dg/der_pointer_4.f90: New.
-------------- next part --------------
Index: gcc/fortran/decl.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/fortran/decl.c,v
retrieving revision 1.43
diff -u -p -r1.43 decl.c
--- gcc/fortran/decl.c	17 Oct 2005 20:52:36 -0000	1.43
+++ gcc/fortran/decl.c	21 Oct 2005 12:26:21 -0000
@@ -1094,7 +1094,7 @@ variable_decl (int elem)
     t = add_init_expr_to_sym (name, &initializer, &var_locus);
   else
     {
-      if (current_ts.type == BT_DERIVED && !initializer)
+      if (current_ts.type == BT_DERIVED && !current_attr.pointer && !initializer)
 	initializer = gfc_default_initializer (&current_ts);
       t = build_struct (name, cl, &initializer, &as);
     }
-------------- next part --------------
! {dg-do compile }
! PR 24426
! Pointer-components of derived type with initialized components
module crash
  implicit none
  type foo
    integer :: i = 0
    type (foo), pointer :: next
  end type foo
  type (foo) :: bar
end module crash


More information about the Fortran mailing list