https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107397
kargl at gcc dot gnu.org changed: What |Removed |Added ---------------------------------------------------------------------------- Priority|P3 |P4 CC| |kargl at gcc dot gnu.org --- Comment #3 from kargl at gcc dot gnu.org --- Interesting bug. The BOZ on the rhs is eventually rejected, but if any error/warning that might be queued is lost during a pass through add_init_expr_to_sym(). Eventually, the rhs expr is freed and the pointer to the initializer is wrong. This patch fixes the ICE and issues an error. It has passed regression testing. diff --git a/gcc/fortran/decl.cc b/gcc/fortran/decl.cc index 0f9b2ced4c2..1562dc22bc6 100644 --- a/gcc/fortran/decl.cc +++ b/gcc/fortran/decl.cc @@ -2221,6 +2221,14 @@ add_init_expr_to_sym (const char *name, gfc_expr **initp, locus *var_locus) sym->ts.f90_type = init->ts.f90_type; } + /* Catch the case: type(t), parameter :: x = z'1'. */ + if (sym->ts.type == BT_DERIVED && init->ts.type == BT_BOZ) + { + gfc_error ("Entity %qs at %L is incompatible with a BOZ " + "literal constant", name, &sym->declared_at); + return false; + } + /* Add initializer. Make sure we keep the ranks sane. */ if (sym->attr.dimension && init->rank == 0) {