gcc/fortran/ChangeLog:
PR fortran/104573
* resolve.cc (resolve_structure_cons): Avoid NULL pointer
dereference when there is no valid component.
gcc/testsuite/ChangeLog:
PR fortran/104573
* gfortran.dg/assumed_type_14.f90: New test.
}
}
- cons = gfc_constructor_first (expr->value.constructor);
-
/* A constructor may have references if it is the result of substituting a
parameter variable. In this case we just pull out the component we
want. */
if (expr->ref)
comp = expr->ref->u.c.sym->components;
- else
+ else if ((expr->ts.type == BT_DERIVED || expr->ts.type == BT_CLASS
+ || expr->ts.type == BT_UNION)
+ && expr->ts.u.derived)
comp = expr->ts.u.derived->components;
+ else
+ return false;
+
+ cons = gfc_constructor_first (expr->value.constructor);
for (; comp && cons; comp = comp->next, cons = gfc_constructor_next (cons))
{
--- /dev/null
+! { dg-do compile }
+! PR fortran/104573 - ICE in resolve_structure_cons
+! Contributed by G.Steinmetz
+! Contributed by M.Morin
+
+program p
+ type t
+ end type
+ type(*), parameter :: x = t() ! { dg-error "Assumed type of variable" }
+ print *, x
+end
+
+subroutine s
+ type t
+ integer :: a
+ end type
+ character(3), parameter :: x = t(2) ! { dg-error "Cannot convert" }
+ character(3), parameter :: y = x ! { dg-error "Unclassifiable statement" }
+ print *, y
+end
+
+! { dg-prune-output "Cannot convert" }