summaryrefslogtreecommitdiff
path: root/gcc/fortran/resolve.c
diff options
context:
space:
mode:
authorkargl <kargl@138bc75d-0d04-0410-961f-82ee72b054a4>2006-02-03 19:11:27 +0000
committerkargl <kargl@138bc75d-0d04-0410-961f-82ee72b054a4>2006-02-03 19:11:27 +0000
commit3d7e03fa7539c0ee0f126f3cf1a3c515007f33fb (patch)
tree50c12e62ea4c706beae0f2e06912b333f9904b99 /gcc/fortran/resolve.c
parent961ee3ff391d899e4cfd940da3a75dbd2ecb0d1f (diff)
downloadgcc-3d7e03fa7539c0ee0f126f3cf1a3c515007f33fb.tar.gz
2006-02-03 Steven G. Kargl <kargls@comcast.net>
Paul Thomas <pault@gcc.gnu.org> * resolve.c (resolve_symbol): Default initialization of derived type component reguires the SAVE attribute. 2006-02-03 Steven G. Kargl <kargls@comcast.net> * gfortran.dg/char_result_11.f90: Add SAVE. * gfortran.dg/der_pointer_4.f90: Ditto. * gfortran.dg/default_initialization.f90: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@110554 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/fortran/resolve.c')
-rw-r--r--gcc/fortran/resolve.c31
1 files changed, 26 insertions, 5 deletions
diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
index ca89f887931..3767992bbb0 100644
--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -4511,11 +4511,12 @@ resolve_symbol (gfc_symbol * sym)
int formal_ns_save, check_constant, mp_flag;
int i, flag;
gfc_namelist *nl;
- gfc_symtree * symtree;
- gfc_symtree * this_symtree;
- gfc_namespace * ns;
- gfc_component * c;
- gfc_formal_arglist * arg;
+ gfc_symtree *symtree;
+ gfc_symtree *this_symtree;
+ gfc_namespace *ns;
+ gfc_component *c;
+ gfc_formal_arglist *arg;
+ gfc_expr *constructor_expr;
if (sym->attr.flavor == FL_UNKNOWN)
{
@@ -4857,6 +4858,26 @@ resolve_symbol (gfc_symbol * sym)
return;
}
+ /* 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 (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)
+ {
+ gfc_error("Object '%s' at %L must have the SAVE attribute %s",
+ sym->name, &sym->declared_at,
+ "for default initialization of a component");
+ return;
+ }
+
/* Assign default initializer. */
if (sym->ts.type == BT_DERIVED && !(sym->value || flag)
&& !sym->attr.pointer)