http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46838

janus at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2010.12.28 10:52:23
         AssignedTo|unassigned at gcc dot       |janus at gcc dot gnu.org
                   |gnu.org                     |
            Summary|[OOP] Wrong allocation      |[OOP] Initialization of
                   |status for polymorphic      |polymorphic allocatable
                   |component INTENT(OUT) dummy |components
     Ever Confirmed|0                           |1

--- Comment #4 from janus at gcc dot gnu.org 2010-12-28 10:52:23 UTC ---
(In reply to comment #2)
> The default initializer is obtained via expr.c's gfc_default_initializer.

Indeed this is the place where things go wrong. Here's a patch:


Index: gcc/fortran/expr.c
===================================================================
--- gcc/fortran/expr.c    (revision 168277)
+++ gcc/fortran/expr.c    (working copy)
@@ -3648,7 +3648,8 @@ gfc_default_initializer (gfc_typespec *ts)
   /* See if we have a default initializer in this, but not in nested
      types (otherwise we could use gfc_has_default_initializer()).  */
   for (comp = ts->u.derived->components; comp; comp = comp->next)
-    if (comp->initializer || comp->attr.allocatable)
+    if (comp->initializer || comp->attr.allocatable
+    || (comp->ts.type == BT_CLASS && CLASS_DATA (comp)->attr.allocatable))
       break;

   if (!comp)
@@ -3664,8 +3665,9 @@ gfc_default_initializer (gfc_typespec *ts)

       if (comp->initializer)
     ctor->expr = gfc_copy_expr (comp->initializer);
-
-      if (comp->attr.allocatable)
+      else if (comp->attr.allocatable
+           || (comp->ts.type == BT_CLASS
+           && CLASS_DATA (comp)->attr.allocatable))
     {
       ctor->expr = gfc_get_expr ();
       ctor->expr->expr_type = EXPR_NULL;


This fixes the test case in comment #1. However, I was not able to see a
failure with the test case in comment #0. Salvatore, can you check whether the
patch cures your troubles?

Reply via email to