aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gfortran.dg/associate_46.f90
blob: 69cc189bfa4e83b00032b3d14f6f2e20157bf72f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
! { dg-do run }
!
! Check the fix for PR88143, in which the associate name caused
! a segfault in resolve.c. Make sure that the associate construct
! does its job correctly, as well as compiles.
!
! Contributed by Andrew Wood  <andrew@fluidgravity.co.uk>
!
MODULE m
   IMPLICIT NONE
   TYPE t
      INTEGER, DIMENSION(:), ALLOCATABLE :: i
   END TYPE
   CONTAINS
      SUBROUTINE s(x, idx1, idx2, k)
         CLASS(*), DIMENSION(:), INTENT(IN), OPTIONAL :: x
         INTEGER :: idx1, idx2, k
         SELECT TYPE ( x )
         CLASS IS ( t )
            ASSOCIATE ( j => x(idx1)%i )
               k = j(idx2)
            END ASSOCIATE
         END SELECT
      END
END

  use m
  class (t), allocatable :: c(:)
  integer :: k
  allocate (c(2))
  allocate (c(1)%i, source = [3,2,1])
  allocate (c(2)%i, source = [6,5,4])
  call s(c, 1, 3, k)
  if (k .ne. 1) stop 1
  call s(c, 2, 1, k)
  if (k .ne. 6) stop 2
end