coarray_41.f90: Add "-latomic" option if libatomic_available.
[official-gcc.git] / gcc / testsuite / gfortran.dg / recursive_reference_1.f90
blob3ca6bcb17117e700a06c449f08c06e9fb6ddfc4e
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). This was subsequently determined
5 ! to be wrong code and the error on 'bad_stuff' was removed.
6 ! See 12.5.2.1 of the standard and PR30876.
8 ! Based on PR testcase by Nicolas Bock <nicolasbock@gmail.com>
10 program test
11 if (original_stuff(1) .ne. 5) call abort ()
12 if (scalar_stuff(-4) .ne. 10) call abort ()
13 if (any (array_stuff((/-19,-30/)) .ne. (/25,25/))) call abort ()
14 contains
15 recursive function original_stuff(n)
16 integer :: original_stuff
17 integer :: n
18 original_stuff = 1
19 if(n < 5) then
20 original_stuff = original_stuff + original_stuff (n+1) ! { dg-error "name of a recursive function" }
21 endif
22 end function original_stuff
24 recursive function scalar_stuff(n) result (tmp)
25 integer :: tmp
26 integer :: n
27 tmp = 1
28 if(n < 5) then
29 tmp = tmp + scalar_stuff (n+1)
30 endif
31 end function scalar_stuff
33 recursive function array_stuff(n) result (tmp)
34 integer :: tmp (2)
35 integer :: n (2)
36 tmp = 1
37 if(maxval (n) < 5) then
38 tmp = tmp + array_stuff (n+1)
39 endif
40 end function array_stuff
42 recursive function bad_stuff(n)
43 integer :: bad_stuff (2)
44 integer :: n(2)
45 bad_stuff = 1
46 if(maxval (n) < 5) then
47 bad_stuff = bad_stuff + bad_stuff (n+1)
48 endif
49 end function bad_stuff
50 end program test