2017-02-20 Paul Thomas <pault@gcc.gnu.org>
[official-gcc.git] / gcc / testsuite / gfortran.dg / optional_absent_2.f90
blob717bab7e7bdc348a196267e7bc569316b59b8e42
1 ! { dg-do run }
3 ! PR fortran/51758
5 ! Contributed by Mikael Morin
7 ! Check whether passing NULL() to an elemental procedure works,
8 ! where NULL() denotes an absent optional argument.
10 program p
12 integer :: a(2)
13 integer :: b
15 a = 0
16 a = foo((/ 1, 1 /), null())
17 ! print *, a
18 if (any(a /= 2)) call abort
20 a = 0
21 a = bar((/ 1, 1 /), null())
22 ! print *, a
23 if (any(a /= 2)) call abort
25 b = 0
26 b = bar(1, null())
27 ! print *, b
28 if (b /= 2) call abort
30 contains
32 function foo(a, b)
33 integer :: a(:)
34 integer, optional :: b(:)
35 integer :: foo(size(a))
37 if (present(b)) call abort
39 foo = 2
40 end function foo
42 elemental function bar(a, b)
43 integer, intent(in) :: a
44 integer, intent(in), optional :: b
45 integer :: bar
47 bar = 2
49 if (present(b)) bar = 1
51 end function bar
53 end program p