Debian Codegraph @

gcc/testsuite/gfortran.dg/optional_absent_13.f90

raw
1 ! { dg-do run }
2 ! PR fortran/119656 - wrong code with impure elemental subroutine and interface
3 !
4 ! Derived from testcase at:
5 ! https://fortran-lang.discourse.group/t/
6 ! problem-with-impure-elemental-subroutine-in-interface-with-gfortran/9545
7
8 module m2
9 implicit none
10 interface foo
11 module procedure foo_mat
12 module procedure foo_df
13 module procedure foo_cmat
14 end interface foo
15 contains
16
17 subroutine foo_mat(x, nacf, label)
18 real, intent(in) :: x(:,:)
19 integer, intent(in) :: nacf
20 character(len=*), intent(in), optional :: label
21 end subroutine foo_mat
22
23 impure elemental subroutine foo_df(nacf, outu, xstr)
24 integer , intent(in) :: nacf
25 integer , intent(in), optional :: outu
26 character(len=*), intent(in), optional :: xstr
27 if (present(xstr)) then
28 if (len (xstr) /= 2) then
29 print *,"nacf, len(xstr) =", nacf, len(xstr)
30 stop nacf
31 end if
32 end if
33 end subroutine foo_df
34
35 subroutine foo_cmat(x, nacf, label)
36 complex, intent(in) :: x(:,:)
37 integer, intent(in) :: nacf
38 character(len=*), intent(in), optional :: label
39 end subroutine foo_cmat
40
41 end module m2
42
43 program main
44 use m2, only: foo, foo_df
45 implicit none
46 call foo_df(nacf = 1, xstr="ab")
47 call foo (nacf = 2, xstr="ab")
48 end program main