char err[200];
gfc_component *ppc;
bool codimension = false;
+ gfc_array_spec *formal_as;
/* If the formal arg has type BT_VOID, it's to one of the iso_c_binding
procs c_f_pointer or c_f_procpointer, and we need to accept most
return false;
}
+ formal_as = (formal->ts.type == BT_CLASS
+ ? CLASS_DATA (formal)->as : formal->as);
+
if (codimension && formal->attr.allocatable)
{
gfc_ref *last = NULL;
if (symbol_rank (formal) == actual->rank || symbol_rank (formal) == -1)
return true;
- rank_check = where != NULL && !is_elemental && formal->as
- && (formal->as->type == AS_ASSUMED_SHAPE
- || formal->as->type == AS_DEFERRED)
- && actual->expr_type != EXPR_NULL;
+ rank_check = where != NULL && !is_elemental && formal_as
+ && (formal_as->type == AS_ASSUMED_SHAPE
+ || formal_as->type == AS_DEFERRED)
+ && actual->expr_type != EXPR_NULL;
/* Skip rank checks for NO_ARG_CHECK. */
if (formal->attr.ext_attr & (1 << EXT_ATTR_NO_ARG_CHECK))
/* Scalar & coindexed, see: F2008, Section 12.5.2.4. */
if (rank_check || ranks_must_agree
|| (formal->attr.pointer && actual->expr_type != EXPR_NULL)
- || (actual->rank != 0 && !(is_elemental || formal->attr.dimension))
+ || (actual->rank != 0
+ && !(is_elemental || formal->attr.dimension
+ || (formal->ts.type == BT_CLASS
+ && CLASS_DATA (formal)->attr.dimension)))
|| (actual->rank == 0
&& ((formal->ts.type == BT_CLASS
&& CLASS_DATA (formal)->as->type == AS_ASSUMED_SHAPE)
|| (formal->ts.type != BT_CLASS
&& formal->as->type == AS_ASSUMED_SHAPE))
&& actual->expr_type != EXPR_NULL)
- || (actual->rank == 0 && formal->attr.dimension
+ || (actual->rank == 0
+ && (formal->attr.dimension
+ || (formal->ts.type == BT_CLASS
+ && CLASS_DATA (formal)->attr.dimension))
&& gfc_is_coindexed (actual))
/* Assumed-rank actual argument; F2018 C838. */
|| actual->rank == -1)
}
return false;
}
- else if (actual->rank != 0 && (is_elemental || formal->attr.dimension))
+ else if (actual->rank != 0
+ && (is_elemental || formal->attr.dimension
+ || (formal->ts.type == BT_CLASS
+ && CLASS_DATA (formal)->attr.dimension)))
return true;
/* At this point, we are considering a scalar passed to an array. This
--- /dev/null
+! { dg-do compile }
+! PR fortran/58331 - rank checking for CLASS dummy arguments
+
+module mymod
+ implicit none
+contains
+ subroutine mysub(a, n)
+ integer, intent(in) :: n
+ class(*), intent(in) :: a(n)
+
+ select type(a)
+ type is(integer)
+ print *,'a is integer'
+ print *, "n=", n, ' a=', a
+ class default
+ print *,'a is unsupported type'
+ stop 1
+ end select
+ end
+
+ ! Assumed rank
+ subroutine sub_ar (a)
+ class(*), intent(in) :: a(..)
+ print *, rank (a), size (a), ":", shape (a)
+ end
+
+ ! Assumed shape
+ subroutine sub_as1 (a)
+ class(*), intent(in) :: a(:)
+ print *, rank (a), size (a), ":", shape (a)
+ end
+ subroutine sub_as2 (b)
+ class(*), intent(in) :: b(:,:)
+ print *, rank (b), size (b), ":", shape (b)
+ end
+end
+
+program p
+ use mymod
+ implicit none
+ integer :: a(3) = [11, 12, 13]
+ integer :: b(2,2) = reshape([21, 22, 23, 24], [2,2])
+ integer :: c = 1
+
+ call mysub(a,3)
+ call mysub(b,4)
+ call sub_ar(a)
+ call sub_ar(b)
+ call sub_ar(c)
+ call sub_as1(a)
+ call sub_as2(b)
+ !
+ call mysub(c,1) ! { dg-error "rank-1 and scalar" }
+ call sub_as1(b) ! { dg-error "rank-1 and rank-2" }
+ call sub_as2(a) ! { dg-error "rank-2 and rank-1" }
+end