Debian Codegraph @

gcc/testsuite/gfortran.dg/proc_ptr_55.f90

raw
1 ! { dg-do compile }
2 !
3 ! Test the fix for pr117434, in which the F2008 addition of being permitted to
4 ! pass an external, internal or module procedure to a dummy procedure pointer
5 ! gave the error "Expected a procedure pointer for argument ‘<arg_name>’ at (1).
6 !
7 ! This testcase tests that interface checking is OK in this situation.
8 !
9 ! Contributed by Damian Rouson <[email protected]>
10 !
11 module julienne_test_description_m
12 implicit none
13
14 abstract interface
15 logical function test_function_i(arg)
16 integer, intent(in) :: arg
17 end function
18 end interface
19
20 type test_description_t
21 procedure(test_function_i), pointer, nopass :: test_function_
22 end type
23
24
25 contains
26
27 type(test_description_t) function new_test_description(test_function)
28 procedure(test_function_i), intent(in), pointer :: test_function
29 new_test_description%test_function_ => test_function
30 end function
31
32 end module
33
34 use julienne_test_description_m
35 implicit none
36 type(test_description_t) test_description
37
38 test_description = new_test_description(test1)
39 test_description = new_test_description(test2) ! { dg-error "Type mismatch in function" }
40 test_description = new_test_description(test3) ! { dg-error "wrong number of arguments" }
41 test_description = new_test_description(test4) ! { dg-error "Rank mismatch in argument" }
42 test_description = new_test_description(test5) ! { dg-error "Rank mismatch in function result" }
43
44 contains
45
46 logical function test1(arg)
47 integer, intent(in) :: arg
48 if (arg == 3) then
49 test1 = .true.
50 else
51 test1 = .false.
52 endif
53 end function
54
55 real function test2(arg)
56 integer, intent(in) :: arg
57 if (arg == 3) then
58 test2 = 1.0
59 else
60 test2 = 0.0
61 endif
62 end function
63
64 logical function test3()
65 test3 = .false.
66 end function
67
68 logical function test4(arg)
69 integer, intent(in) :: arg(:)
70 if (sum (arg) == 3) then
71 test4 = .true.
72 else
73 test4 = .false.
74 endif
75 end function
76
77 function test5(arg) result(res)
78 integer, intent(in) :: arg
79 logical :: res(2)
80 if (arg == 3) then
81 res = .true.
82 else
83 res = .false.
84 endif
85 end function
86
87 end