https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102685
--- Comment #3 from anlauf at gcc dot gnu.org ---
Preliminary patch (untested):
diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
index 0d0af39d23f..c5df42ba67a 100644
--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -1333,6 +1333,31 @@ resolve_structure_cons (gfc_expr *expr, int init)
t = false;
}
+ /* Validate shape. */
+ if (cons->expr->expr_type == EXPR_ARRAY && rank == cons->expr->rank
+ && !(comp->attr.allocatable || comp->attr.pointer))
+ {
+ mpz_t tmp;
+ int n;
+ mpz_init (tmp);
+ for (n = 0; n < rank; n++)
+ {
+ mpz_set_ui (tmp, 1);
+ mpz_add (tmp, tmp, comp->as->upper[n]->value.integer);
+ mpz_sub (tmp, tmp, comp->as->lower[n]->value.integer);
+ if (mpz_cmp (cons->expr->shape[n], tmp) != 0)
+ {
+ gfc_error ("The shape of a component in the structure "
+ "constructor at %L differs from the shape of the "
+ "declared component (%ld/%ld)",
&cons->expr->where,
+ mpz_get_si (cons->expr->shape[n]),
+ mpz_get_si (tmp));
+ t = false;
+ }
+ }
+ mpz_clear (tmp);
+ }
+
/* If we don't have the right type, try to convert it. */
if (!comp->attr.proc_pointer &&