1! { dg-do run }
2!
3! TS 29113
4! 6.3  Argument association
5! An assumed-rank dummy argument may correspond to an actual argument of
6! any rank. [...] If the actual argument has rank greater than zero, the
7! rank and extents of the dummy argument are assumed from the actual
8! argument, including the lack of a final extent in the case of an
9! assumed-size array. If the actual argument is an array and the dummy
10! argument is allocatable or a pointer, the bounds of the dummy argument
11! are assumed from the actual argument.
12
13program test
14
15  integer :: a(3, 4, 5)
16  integer :: b(-3:3, 0:4, 2:5, 10:20)
17
18  call testit (a, rank(a), shape(a), lbound(a), ubound(a))
19  call testit (b, rank(b), shape(b), lbound(b), ubound(b))
20
21contains
22
23  subroutine testit (x, r, s, l, u) bind (c)
24    integer :: x(..)
25    integer :: r
26    integer :: s(r)
27    integer :: l(r)
28    integer :: u(r)
29
30    ! expect rank to match
31    if (rank (x) .ne. r) stop 101
32
33    ! expect shape to match
34    if (size (shape (x)) .ne. r) stop 102
35    if (any (shape (x) .ne. s))  stop 103
36
37    ! expect lbound and ubound functions to return rank-sized arrays.
38    ! for non-pointer/non-allocatable arrays, bounds are normalized
39    ! to be 1-based.
40    if (size (lbound (x)) .ne. r) stop 104
41    if (any (lbound (x) .ne. 1)) stop 105
42
43    if (size (ubound (x)) .ne. r) stop 106
44    if (any (ubound (x) .ne. u - l + 1)) stop 107
45    if (any (ubound (x) .ne. s)) stop 108
46  end subroutine
47
48end program
49