https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106771
--- Comment #2 from anlauf at gcc dot gnu.org --- Playing a little, I found that the issue might be related to the elemental function isa. The following dumb replacement function isa(this,i) class(t), intent(in) :: this integer, intent(in) :: i(:) logical :: isa(size(i)) integer :: j do j = 1, size(i) if (i(j)>0 .and. i(j)<=merge(size(this%iloc),0,allocated(this%iloc))) then isa(j) = this%iloc(i(j))>0 else isa(j) = .false. end if end do end function isa also avoids the ICE.