This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: Does anyone grok this one ?
- From: Tobias Burnus <burnus at net-b dot de>
- To: Toon Moene <toon at moene dot indiv dot nluug dot nl>
- Cc: gfortran <fortran at gcc dot gnu dot org>
- Date: Wed, 31 Jan 2007 21:32:47 +0100
- Subject: Re: Does anyone grok this one ?
- References: <45C0E5E2.1030402@moene.indiv.nluug.nl>
Hi Toon,
Toon Moene wrote:
> $ /usr/snp/bin/gfortran -c globals.f90
> globals.f90:37.24:
>
> TYPE(weight_t) g_winfo ! weights info
> 1
> Error: Object 'g_winfo' at (1) must have the SAVE attribute for
> default initialization of a component
> *I* don't see any "default initialization of a component" ...
Neither do I ...
I could reproduce it with gfortran 4.2 and 4.3.
Well, the solution is simple: Either fill a PR or better provide a patch ;-)
Looking at resolve_fl_variable and gfc_default_initializer, I think the
problem is that you have allocatable variables which are treated for
this test wrongly as default initializer.
I don't see at the moment why allocatables need a special treatment, but
gfc_default_initializer is used in:
- decl.c: variable_decl
- resolve.c: resolve_allocate_expr and apply_default_init and
resolve_fl_variable (twice)
Maybe someone who knows the allocate extension should have a look at
this as he might remember why gfc_default_initializer returns also for
allocatables non-NULL.
Tobias
------------
resolve.c: resolve_fl_variable
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)
{
gfc_error("Object '%s' at %L must have the SAVE attribute %s",
And in expr.c:
gfc_default_initializer (gfc_typespec *ts)
init = NULL;
/* See if we have a default initializer. */
for (c = ts->derived->components; c; c = c->next)
{
if ((c->initializer || c->allocatable) && init == NULL)
init = gfc_get_expr ();
}