Debian Codegraph @

gcc/testsuite/gfortran.dg/optional_absent_2.f90

raw
1 ! { dg-do run }
2 !
3 ! PR fortran/51758
4 !
5 ! Contributed by Mikael Morin
6 !
7 ! Check whether passing NULL() to an elemental procedure works,
8 ! where NULL() denotes an absent optional argument.
9 !
10 program p
11
12 integer :: a(2)
13 integer :: b
14
15 a = 0
16 a = foo((/ 1, 1 /), null())
17 ! print *, a
18 if (any(a /= 2)) STOP 1
19
20 a = 0
21 a = bar((/ 1, 1 /), null())
22 ! print *, a
23 if (any(a /= 2)) STOP 2
24
25 b = 0
26 b = bar(1, null())
27 ! print *, b
28 if (b /= 2) STOP 3
29
30 contains
31
32 function foo(a, b)
33 integer :: a(:)
34 integer, optional :: b(:)
35 integer :: foo(size(a))
36
37 if (present(b)) STOP 4
38
39 foo = 2
40 end function foo
41
42 elemental function bar(a, b)
43 integer, intent(in) :: a
44 integer, intent(in), optional :: b
45 integer :: bar
46
47 bar = 2
48
49 if (present(b)) bar = 1
50
51 end function bar
52
53 end program p