File: unlimited_polymorphic_17.f90

package info (click to toggle)
gcc-arm-none-eabi 15%3A14.2.rel1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,099,328 kB
  • sloc: cpp: 3,627,108; ansic: 2,571,498; ada: 834,230; f90: 235,082; makefile: 79,231; asm: 74,984; xml: 51,692; exp: 39,736; sh: 33,298; objc: 15,629; python: 15,069; fortran: 14,429; pascal: 7,003; awk: 5,070; perl: 3,106; ml: 285; lisp: 253; lex: 204; haskell: 135
file content (51 lines) | stat: -rw-r--r-- 1,361 bytes parent folder | download | duplicates (3)
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
! { dg-do run }
! Tests fix for PR60717 in which offsets in recursive calls below
! were not being set correctly.
!
! Reported on comp.lang.fortran by Thomas Schnurrenberger
!
module m
  implicit none
  real :: chksum0 = 0, chksum1 = 0, chksum2 = 0
contains
  recursive subroutine show_real(a)
    real, intent(in) :: a(:)
    if (size (a) > 0) then
      chksum0 = a(1) + chksum0
      call show_real (a(2:))
    end if
    return
  end subroutine show_real
  recursive subroutine show_generic1(a)
    class(*), intent(in) :: a(:)
    if (size (a) > 0) then
      select type (a)
      type is (real)
        chksum1 = a(1) + chksum1
      end select
      call show_generic1 (a(2:)) ! recursive call outside SELECT TYPE
    end if
    return
  end subroutine show_generic1
  recursive subroutine show_generic2(a)
    class(*), intent(in) :: a(:)
    if (size (a) > 0) then
      select type (a)
      type is (real)
        chksum2 = a(1) + chksum2
        call show_generic2 (a(2:)) ! recursive call inside SELECT TYPE
      end select
    end if
    return
  end subroutine show_generic2
end module m
program test
  use :: m
  implicit none
  real :: array(1:6) = (/ 0, 1, 2, 3, 4, 5 /)
  call show_real (array)
  call show_generic1 (array)
  call show_generic2 (array)
  if (chksum0 .ne. chksum1) STOP 1
  if (chksum0 .ne. chksum2) STOP 2
end program test