https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122669
--- Comment #2 from Paul Thomas <pault at gcc dot gnu.org> ---
(In reply to Paul Thomas from comment #0)
> The following is lifted from pr122578 comment 5:
...and is fixed by:
diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc
index 2a73f2a7ab5..325b3fe2f8a 100644
--- a/gcc/fortran/resolve.cc
+++ b/gcc/fortran/resolve.cc
@@ -9800,7 +9800,8 @@ done_errmsg:
execute loop invariant code for each loop item. Therefore do it just
once here. */
if (code->expr3 && code->expr3->mold
- && code->expr3->ts.type == BT_DERIVED)
+ && code->expr3->ts.type == BT_DERIVED
+ && !(code->expr3->ref && code->expr3->ref->type == REF_ARRAY))
{
/* Default initialization via MOLD (non-polymorphic). */
gfc_expr *rhs = gfc_default_initializer (&code->expr3->ts);