https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84487

--- Comment #19 from Thomas Koenig <tkoenig at gcc dot gnu.org> ---
Unfortunately, this patch

Index: class.c
===================================================================
--- class.c     (Revision 269895)
+++ class.c     (Arbeitskopie)
@@ -911,6 +911,9 @@ finalize_component (gfc_expr *expr, gfc_symbol *de
   if (!comp_is_finalizable (comp))
     return;

+  if (comp->finalized)
+    return;
+
   e = gfc_copy_expr (expr);
   if (!e->ref)
     e->ref = ref = gfc_get_ref ();
@@ -1038,6 +1041,7 @@ finalize_component (gfc_expr *expr, gfc_symbol *de
                            sub_ns);
       gfc_free_expr (e);
     }
+  comp->finalized = true;
 }


@@ -2290,9 +2294,10 @@ gfc_find_derived_vtab (gfc_symbol *derived)
          gfc_find_symbol (name, ns, 0, &vtype);
          if (vtype == NULL)
            {
-             gfc_component *c;
+             gfc_component *c, *csave;
              gfc_symbol *parent = NULL, *parent_vtab = NULL;
              bool rdt = false;
+             bool has_init = false;

              /* Is this a derived type with recursive allocatable
                 components?  */
@@ -2299,6 +2304,8 @@ gfc_find_derived_vtab (gfc_symbol *derived)
              c = (derived->attr.unlimited_polymorphic
                   || derived->attr.abstract) ?
                  NULL : derived->components;
+             csave = c;
+
              for (; c; c= c->next)
                if (c->ts.type == BT_DERIVED
                    && c->ts.u.derived == derived)
@@ -2307,6 +2314,15 @@ gfc_find_derived_vtab (gfc_symbol *derived)
                    break;
                  }

+             for (c = csave; c; c = c->next)
+               {
+                 if (c->initializer)
+                   {
+                     has_init = true;
+                     break;
+                   }
+               }
+
              gfc_get_symbol (name, ns, &vtype);
              if (!gfc_add_flavor (&vtype->attr, FL_DERIVED, NULL,
                                   &gfc_current_locus))
@@ -2383,7 +2399,7 @@ gfc_find_derived_vtab (gfc_symbol *derived)
              c->ts.type = BT_DERIVED;
              c->ts.u.derived = derived;
              if (derived->attr.unlimited_polymorphic
-                 || derived->attr.abstract)
+                 || derived->attr.abstract || !has_init)
                c->initializer = gfc_get_null_expr (NULL);
              else
                {
Index: gfortran.h
===================================================================
--- gfortran.h  (Revision 269895)
+++ gfortran.h  (Arbeitskopie)
@@ -1094,6 +1094,7 @@ typedef struct gfc_component
   struct gfc_typebound_proc *tb;
   /* When allocatable/pointer and in a coarray the associated token.  */
   tree caf_token;
+  bool finalized;
 }
 gfc_component;

leads to testsuite failures (allocate_with_source_5.f90,
allocate_with_source_6.f90 and possibly others).

So, it seems as if the BSS idea might have some merit.  Ideas on how
to implement this, anybody?

Reply via email to