aboutsummaryrefslogtreecommitdiff
path: root/gcc/fortran/decl.c
diff options
context:
space:
mode:
authorPaul Brook <paul@codesourcery.com>2004-05-18 00:48:05 +0000
committerPaul Brook <pbrook@gcc.gnu.org>2004-05-18 00:48:05 +0000
commit54b4ba60f20d3870a79467caa3b604971225d388 (patch)
treec59d49b2984c03bcf5e5f018b12cc2f44288e7a1 /gcc/fortran/decl.c
parentb7cefb87f053f26b4354d18f94c4e3baa4266645 (diff)
downloadgcc-54b4ba60f20d3870a79467caa3b604971225d388.zip
gcc-54b4ba60f20d3870a79467caa3b604971225d388.tar.gz
gcc-54b4ba60f20d3870a79467caa3b604971225d388.tar.bz2
re PR fortran/13930 (derived type with intent(in) attribute not accepted)
PR fortran/13930 * decl.c (add_init_expr_to_sym): Remove incorrect check. (default_initializer): Move to expr.c. (variable_decl): Don't assign default initializer to variables. * expr.c (gfc_default_initializer): Move to here. * gfortran.h (gfc_default_initializer): Add prototype. * resolve.c (resolve_symbol): Check for illegal initializers. Assign default initializer. testsuite/ * gfortran.fortran-torture/execute/der_init_4.f90: New test. From-SVN: r81966
Diffstat (limited to 'gcc/fortran/decl.c')
-rw-r--r--gcc/fortran/decl.c68
1 files changed, 6 insertions, 62 deletions
diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c
index ff87bee..84547a4 100644
--- a/gcc/fortran/decl.c
+++ b/gcc/fortran/decl.c
@@ -254,7 +254,6 @@ static try
add_init_expr_to_sym (const char *name, gfc_expr ** initp,
locus * var_locus)
{
- int i;
symbol_attribute attr;
gfc_symbol *sym;
gfc_expr *init;
@@ -311,19 +310,6 @@ add_init_expr_to_sym (const char *name, gfc_expr ** initp,
&& gfc_check_assign_symbol (sym, init) == FAILURE)
return FAILURE;
- for (i = 0; i < sym->attr.dimension; i++)
- {
- if (sym->as->lower[i] == NULL
- || sym->as->lower[i]->expr_type != EXPR_CONSTANT
- || sym->as->upper[i] == NULL
- || sym->as->upper[i]->expr_type != EXPR_CONSTANT)
- {
- gfc_error ("Array '%s' at %C cannot have initializer",
- sym->name);
- return FAILURE;
- }
- }
-
/* Add initializer. Make sure we keep the ranks sane. */
if (sym->attr.dimension && init->rank == 0)
init->rank = sym->as->rank;
@@ -447,47 +433,6 @@ gfc_match_null (gfc_expr ** result)
}
-/* Get an expression for a default initializer. */
-static gfc_expr *
-default_initializer (void)
-{
- gfc_constructor *tail;
- gfc_expr *init;
- gfc_component *c;
-
- init = NULL;
-
- /* First see if we have a default initializer. */
- for (c = current_ts.derived->components; c; c = c->next)
- {
- if (c->initializer && init == NULL)
- init = gfc_get_expr ();
- }
-
- if (init == NULL)
- return NULL;
-
- init->expr_type = EXPR_STRUCTURE;
- init->ts = current_ts;
- init->where = current_ts.derived->declared_at;
- tail = NULL;
- for (c = current_ts.derived->components; c; c = c->next)
- {
- if (tail == NULL)
- init->value.constructor = tail = gfc_get_constructor ();
- else
- {
- tail->next = gfc_get_constructor ();
- tail = tail->next;
- }
-
- if (c->initializer)
- tail->expr = gfc_copy_expr (c->initializer);
- }
- return init;
-}
-
-
/* Match a variable name with an optional initializer. When this
subroutine is called, a variable is expected to be parsed next.
Depending on what is happening at the moment, updates either the
@@ -644,18 +589,17 @@ variable_decl (void)
}
}
- if (current_ts.type == BT_DERIVED && !initializer)
- {
- initializer = default_initializer ();
- }
-
- /* Add the initializer. Note that it is fine if &initializer is
+ /* Add the initializer. Note that it is fine if initializer is
NULL here, because we sometimes also need to check if a
declaration *must* have an initialization expression. */
if (gfc_current_state () != COMP_DERIVED)
t = add_init_expr_to_sym (name, &initializer, &var_locus);
else
- t = build_struct (name, cl, &initializer, &as);
+ {
+ if (current_ts.type == BT_DERIVED && !initializer)
+ initializer = gfc_default_initializer (&current_ts);
+ t = build_struct (name, cl, &initializer, &as);
+ }
m = (t == SUCCESS) ? MATCH_YES : MATCH_ERROR;