This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug fortran/30660] Allocatable components of a derived type "require" the SAVE attribute.
- From: "pault at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 2 Feb 2007 16:15:26 -0000
- Subject: [Bug fortran/30660] Allocatable components of a derived type "require" the SAVE attribute.
- References: <bug-30660-109@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #3 from pault at gcc dot gnu dot org 2007-02-02 16:15 -------
This does the right thing and does not break anything. However, it is still
not quite the definitive fix - it is not right for derived type components and
gfc_default_initializer now does not look right. I'll need a few days on this
one.
Paul
Index: gcc/fortran/resolve.c
===================================================================
*** gcc/fortran/resolve.c (revision 121497)
--- gcc/fortran/resolve.c (working copy)
*************** resolve_fl_variable (gfc_symbol *sym, in
*** 5534,5540 ****
int flag;
int i;
gfc_expr *e;
! gfc_expr *constructor_expr;
const char *auto_save_msg;
auto_save_msg = "automatic object '%s' at %L cannot have the "
--- 5534,5540 ----
int flag;
int i;
gfc_expr *e;
! gfc_component *c;
const char *auto_save_msg;
auto_save_msg = "automatic object '%s' at %L cannot have the "
*************** resolve_fl_variable (gfc_symbol *sym, in
*** 5668,5685 ****
}
}
/* 4th constraint in section 11.3: "If an object of a type for which
component-initialization is specified (R429) appears in the
specification-part of a module and does not have the ALLOCATABLE
or POINTER attribute, the object shall have the SAVE attribute." */
! constructor_expr = NULL;
! if (sym->ts.type == BT_DERIVED && !(sym->value || flag))
! constructor_expr = gfc_default_initializer (&sym->ts);
!
! if (sym->ns->proc_name
&& sym->ns->proc_name->attr.flavor == FL_MODULE
- && constructor_expr
&& !sym->ns->save_all && !sym->attr.save
&& !sym->attr.pointer && !sym->attr.allocatable)
{
--- 5668,5689 ----
}
}
+ /* Do not use gfc_default_initializer to test for a default initializer
+ in the fortran because it generates a hidden default for allocatable
+ components. TODO - clean this up. */
+ c = NULL;
+ if (sym->ts.type == BT_DERIVED && !(sym->value || flag))
+ for (c = sym->ts.derived->components; c; c = c->next)
+ if (c->initializer)
+ break;
+
/* 4th constraint in section 11.3: "If an object of a type for which
component-initialization is specified (R429) appears in the
specification-part of a module and does not have the ALLOCATABLE
or POINTER attribute, the object shall have the SAVE attribute." */
! if (c && sym->ns->proc_name
&& sym->ns->proc_name->attr.flavor == FL_MODULE
&& !sym->ns->save_all && !sym->attr.save
&& !sym->attr.pointer && !sym->attr.allocatable)
{
--
pault at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
AssignedTo|unassigned at gcc dot gnu |pault at gcc dot gnu dot org
|dot org |
Status|NEW |ASSIGNED
Last reconfirmed|2007-02-02 13:14:05 |2007-02-02 16:15:26
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30660