}
else if (derived && gfc_is_finalizable (derived, NULL))
{
- if (!derived->components && (!rank || attr.elemental))
+ tree type = TREE_TYPE (se->expr);
+ if (type && TYPE_SIZE_UNIT (type)
+ && integer_zerop (TYPE_SIZE_UNIT (type))
+ && (!rank || attr.elemental))
{
/* Any attempt to assign zero length entities, causes the gimplifier
all manner of problems. Instead, a variable is created to act as
- as the argument for the final call. */
- desc = gfc_create_var (TREE_TYPE (se->expr), "zero");
+ the argument for the final call. */
+ desc = gfc_create_var (type, "zero");
}
else if (se->direct_byref)
{
--- /dev/null
+! { dg-do compile }
+! PR fortran/121472 - ICE with constructor for finalized zero-size type
+
+module pr121472_m
+ implicit none
+ type r
+ end type
+
+ type ip
+ type(r) :: r_member
+ contains
+ final :: ipd
+ end type
+
+ interface ip
+ module procedure ipc
+ end interface
+contains
+ subroutine ipd(this)
+ type(ip), intent(inout) :: this
+ end subroutine
+
+ function ipc() result(res)
+ type(ip) :: res
+ end function
+end module
+
+program test
+ use pr121472_m
+ implicit none
+ type(ip) :: p
+ p = ip()
+end program