&& expr3 && expr3->ts.type != BT_CLASS
&& expr3_elem_size != NULL_TREE && expr3_desc == NULL_TREE)
{
+ tmp = gfc_conv_descriptor_dtype (descriptor);
+ gfc_add_modify (pblock, tmp, gfc_get_dtype (type));
tmp = gfc_conv_descriptor_elem_len (descriptor);
gfc_add_modify (pblock, tmp,
fold_convert (TREE_TYPE (tmp), expr3_elem_size));
--- /dev/null
+! { dg-do run }
+!
+! Test case contributed by Andrew Benson <abensonca@gmail.com>
+
+module m
+ implicit none
+ type :: t
+ integer :: i
+ end type t
+ type :: container
+ class(t), allocatable :: arr(:)
+ end type container
+ type(t) :: scalar_mold
+contains
+ subroutine get_rank (x, r)
+ class(*), intent(in) :: x(..)
+ integer, intent(out) :: r
+ r = rank (x)
+ end subroutine get_rank
+end module m
+
+program main
+ use m
+ implicit none
+ type(container), pointer :: c
+ integer :: r
+
+ allocate (c)
+ allocate (c%arr(1), mold = scalar_mold)
+
+ ! Check the rank
+ call get_rank (c%arr, r)
+ if (r /= 1) stop 1
+
+ deallocate (c)
+end program main
--- /dev/null
+! { dg-do run }
+!
+module m
+ implicit none
+ type :: container
+ class(*), allocatable :: arr(:)
+ end type container
+contains
+ subroutine get_rank (x, r)
+ class(*), intent(in) :: x(..)
+ integer, intent(out) :: r
+ r = rank (x)
+ end subroutine get_rank
+end module m
+
+program main
+ use m
+ implicit none
+ type(container), pointer :: c
+ integer(1), allocatable :: junk(:)
+ integer :: r
+
+ allocate (c)
+ allocate (c%arr(3), mold = 7)
+
+ call get_rank (c%arr, r)
+ if (r /= 1) stop 1
+
+ select type (y => c%arr)
+ type is (integer)
+ class default
+ stop 2
+ end select
+
+ deallocate (c)
+end program main