newdata = gfc_get_data ();
newdata->var = gfc_get_data_variable ();
newdata->var->expr = gfc_get_variable_expr (st);
+ newdata->var->expr->where = sym->declared_at;
newdata->where = gfc_current_locus;
/* Match initial value list. This also eats the terminal '/'. */
{
gfc_constructor_base array_head = NULL;
gfc_expr *expr = NULL;
- match m;
+ match m = MATCH_ERROR;
locus where;
- mpz_t repeat, size;
+ mpz_t repeat, cons_size, as_size;
bool scalar;
int cmp;
gcc_assert (ts);
- mpz_init_set_ui (repeat, 0);
- mpz_init (size);
- scalar = !as || !as->rank;
-
/* We have already matched '/' - now look for a constant list, as with
top_val_list from decl.c, but append the result to an array. */
if (gfc_match ("/") == MATCH_YES)
{
gfc_error ("Empty old style initializer list at %C");
- goto cleanup;
+ return MATCH_ERROR;
}
where = gfc_current_locus;
+ scalar = !as || !as->rank;
+
+ if (!scalar && !spec_size (as, &as_size))
+ {
+ gfc_error ("Array in initializer list at %L must have an explicit shape",
+ as->type == AS_EXPLICIT ? &as->upper[0]->where : &where);
+ /* Nothing to cleanup yet. */
+ return MATCH_ERROR;
+ }
+
+ mpz_init_set_ui (repeat, 0);
+
for (;;)
{
m = match_data_constant (&expr);
m = match_data_constant (&expr);
if (m == MATCH_NO)
- gfc_error ("Expected data constant after repeat spec at %C");
+ {
+ m = MATCH_ERROR;
+ gfc_error ("Expected data constant after repeat spec at %C");
+ }
if (m != MATCH_YES)
goto cleanup;
}
goto syntax;
}
+ /* If we break early from here out, we encountered an error. */
+ m = MATCH_ERROR;
+
/* Set up expr as an array constructor. */
if (!scalar)
{
expr->rank = as->rank;
expr->shape = gfc_get_shape (expr->rank);
- /* Validate sizes. */
- gcc_assert (gfc_array_size (expr, &size));
- gcc_assert (spec_size (as, &repeat));
- cmp = mpz_cmp (size, repeat);
+ /* Validate sizes. We built expr ourselves, so cons_size will be
+ constant (we fail above for non-constant expressions).
+ We still need to verify that the sizes match. */
+ gcc_assert (gfc_array_size (expr, &cons_size));
+ cmp = mpz_cmp (cons_size, as_size);
if (cmp < 0)
- gfc_error ("Not enough elements in array initializer at %C");
+ gfc_error ("Not enough elements in array initializer at %C");
else if (cmp > 0)
- gfc_error ("Too many elements in array initializer at %C");
+ gfc_error ("Too many elements in array initializer at %C");
+ mpz_clear (cons_size);
if (cmp)
- goto cleanup;
+ goto cleanup;
}
/* Make sure scalar types match. */
expr->ts.u.cl->length_from_typespec = 1;
*result = expr;
- mpz_clear (size);
- mpz_clear (repeat);
- return MATCH_YES;
+ m = MATCH_YES;
+ goto done;
syntax:
+ m = MATCH_ERROR;
gfc_error ("Syntax error in old style initializer list at %C");
cleanup:
expr->value.constructor = NULL;
gfc_free_expr (expr);
gfc_constructor_free (array_head);
- mpz_clear (size);
+
+done:
mpz_clear (repeat);
- return MATCH_ERROR;
+ if (!scalar)
+ mpz_clear (as_size);
+ return m;
}
! Old-style (clist) initialization
integer,parameter :: as = 3
-structure /t1/
+structure /t1/ ! { dg-error "Type definition.*T1" }
integer*1 a /300_2/ ! { dg-error "Arithmetic overflow" }
integer b // ! { dg-error "Empty old style initializer list" }
integer c /2*3/ ! { dg-error "Repeat spec invalid in scalar" }
structure /t2/
ENTRY here ! { dg-error "ENTRY statement.*cannot appear" }
- integer a
+ integer a ! { dg-error "Component.*already declared" }
integer a ! { dg-error "Component.*already declared" }
structure $z ! { dg-error "Invalid character in name" }
structure // ! { dg-error "Invalid character in name" }
structure // x ! { dg-error "Invalid character in name" }
structure /t3/ ! { dg-error "Invalid character in name" }
structure /t3/ x,$y ! { dg-error "Invalid character in name" }
- structure /t4/ y
+ structure /t4/ y ! { dg-error "Type definition.*T4" }
integer i, j, k
end structure
structure /t4/ z ! { dg-error "Type definition.*T4" }