OSDN Git Service

2006-10-03 Steven G. Kargl <kargl@gcc.gnu.org>
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gfortran.dg / recursive_reference_1.f90
1 ! { dg-do compile }
2 ! Tests the patch for PR27613, in which directly recursive, scalar
3 ! functions were generating an "unclassifiable statement" error
4 ! for the recursive statement(s).
5 !
6 ! Based on PR testcase by Nicolas Bock  <nicolasbock@gmail.com>
7 !
8 program test
9   if (original_stuff(1) .ne. 5) call abort ()
10   if (scalar_stuff(-4) .ne. 10) call abort ()
11   if (any (array_stuff((/-19,-30/)) .ne. (/25,25/))) call abort ()
12 contains
13   recursive function original_stuff(n)
14     integer :: original_stuff
15     integer :: n
16     original_stuff = 1
17     if(n < 5) then
18       original_stuff = original_stuff + original_stuff (n+1)
19     endif
20   end function original_stuff
21
22   recursive function scalar_stuff(n) result (tmp)
23     integer :: tmp
24     integer :: n
25     tmp = 1
26     if(n < 5) then
27       tmp = tmp + scalar_stuff (n+1)
28     endif
29   end function scalar_stuff
30
31   recursive function array_stuff(n) result (tmp)
32     integer :: tmp (2)
33     integer :: n (2)
34     tmp = 1
35     if(maxval (n) < 5) then
36       tmp = tmp + array_stuff (n+1)
37     endif
38   end function array_stuff
39
40   recursive function bad_stuff(n)
41     integer :: bad_stuff (2)
42     integer :: n(2)
43     bad_stuff = 1
44     if(maxval (n) < 5) then
45       bad_stuff = bad_stuff + bad_stuff (n+1) ! { dg-error "RESULT must be specified" }
46     endif
47   end function bad_stuff
48 end program test