This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug fortran/33221] Cannot declare variables of TYPE without components

------- Comment #2 from fxcoudert at gcc dot gnu dot org  2007-09-18 08:26 -------
This is because, in gfc_use_derived (symbol.c), when checking whether a derived
type is in the current unit or a parent unit, we check (sym->components !=
NULL) and if it's true, we take it to mean that the derived type was in a
parent unit (while, in fact, it's simply NULL because there *is* no component).
We need either a better test for the derived type being in the current scoping
unit, or a way to indicate a derived type without components other than setting
components to NULL.

One thing that comes to mind is the following patch. It allows derived types
with zero components to be accepted, but I fear that it might make us accept
invalid code with empty derived types outside the current scoping unit.

Index: symbol.c
--- symbol.c    (revision 128540)
+++ symbol.c    (working copy)
@@ -1703,7 +1703,7 @@ gfc_use_derived (gfc_symbol *sym)
   gfc_symtree *st;
   int i;

-  if (sym->components != NULL)
+  if (sym->components != NULL || sym->attr.zero_comp)
     return sym;               /* Already defined.  */

   if (sym->ns->parent == NULL)
Index: decl.c
--- decl.c      (revision 128540)
+++ decl.c      (working copy)
@@ -3414,7 +3414,8 @@ gfc_match_data_decl (void)
       goto cleanup;

-  if (current_ts.type == BT_DERIVED && current_ts.derived->components == NULL)
+  if (current_ts.type == BT_DERIVED && current_ts.derived->components == NULL
+      && !current_ts.derived->attr.zero_comp)

       if (current_attr.pointer && gfc_current_state () == COMP_DERIVED)
Index: gfortran.h
--- gfortran.h  (revision 128540)
+++ gfortran.h  (working copy)
@@ -650,8 +650,9 @@ typedef struct
   unsigned cray_pointer:1, cray_pointee:1;

   /* The symbol is a derived type with allocatable components, pointer 
-     components or private components, possibly nested.  */
-  unsigned alloc_comp:1, pointer_comp:1, private_comp:1;
+     components or private components, possibly nested.  zer_comp
+     is true if the derived type has no component at all.  */
+  unsigned alloc_comp:1, pointer_comp:1, private_comp:1, zero_comp:1;

   /* The namespace where the VOLATILE attribute has been set.  */
   struct gfc_namespace *volatile_ns;
Index: resolve.c
--- resolve.c   (revision 128540)
+++ resolve.c   (working copy)
@@ -7567,7 +7567,8 @@ resolve_symbol (gfc_symbol *sym)
      the type is not declared in the scope of the implicit
      statement. Change the type to BT_UNKNOWN, both because it is so
      and to prevent an ICE.  */
-  if (sym->ts.type == BT_DERIVED && sym->ts.derived->components == NULL)
+  if (sym->ts.type == BT_DERIVED && sym->ts.derived->components == NULL
+      && !sym->ts.derived->attr.zero_comp)
       gfc_error ("The derived type '%s' at %L is of type '%s', "
                 "which has not been defined", sym->name,
Index: parse.c
--- parse.c     (revision 128540)
+++ parse.c     (working copy)
@@ -1651,6 +1651,9 @@ parse_derived (void)

+  if (!seen_component)
+    sym->attr.zero_comp = 1;
   pop_state ();


fxcoudert at gcc dot gnu dot org changed:

           What    |Removed                     |Added
                 CC|                            |fxcoudert at gcc dot gnu dot
                   |                            |org

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]