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

kargl at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P4
                 CC|                            |kargl at gcc dot gnu.org

--- Comment #2 from kargl at gcc dot gnu.org ---
The following patch fixes the problem.  It has not been regression tested.

diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c
index 05081c40f1e..85c95cea17f 100644
--- a/gcc/fortran/decl.c
+++ b/gcc/fortran/decl.c
@@ -8695,7 +8695,9 @@ attr_decl1 (void)
   /* Update symbol table.  DIMENSION attribute is set in
      gfc_set_array_spec().  For CLASS variables, this must be applied
      to the first component, or '_data' field.  */
-  if (sym->ts.type == BT_CLASS && sym->ts.u.derived->attr.is_class)
+  if (sym->ts.type == BT_CLASS
+      && sym->ts.u.derived
+      && sym->ts.u.derived->attr.is_class)
     {
       /* gfc_set_array_spec sets sym->attr not CLASS_DATA(sym)->attr.  Check
         for duplicate attribute here.  */
diff --git a/gcc/fortran/parse.c b/gcc/fortran/parse.c
index 6d7845e8517..8d6d4f4e98f 100644
--- a/gcc/fortran/parse.c
+++ b/gcc/fortran/parse.c
@@ -3813,7 +3813,7 @@ match_deferred_characteristics (gfc_typespec * ts)
   m = gfc_match_prefix (ts);
   gfc_buffer_error (false);

-  if (ts->type == BT_DERIVED)
+  if (ts->type == BT_DERIVED || ts->type == BT_CLASS)
     {
       ts->kind = 0;

@@ -4094,7 +4094,7 @@ declSt:
   if (bad_characteristic)
     {
       ts = &gfc_current_block ()->result->ts;
-      if (ts->type != BT_DERIVED)
+      if (ts->type != BT_DERIVED && ts->type != BT_CLASS)
        gfc_error ("Bad kind expression for function %qs at %L",
                   gfc_current_block ()->name,
                   &gfc_current_block ()->declared_at);

Reply via email to