https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99585
--- Comment #1 from anlauf at gcc dot gnu.org --- Reduced example: module m type t end type type t2 type(t), allocatable :: my(:) end type t2 contains function h (x) result(z) class(t2) :: x(:) type(t) :: z(size(x(1)%my)) end subroutine s () type(t2), allocatable :: a(:) type(t), allocatable :: u(:) u = h (a) end end