Debian Codegraph @

gcc/testsuite/gfortran.dg/protected_10.f90

raw
1 ! { dg-do compile }
2 ! PR fortran/83135 - fix checking of protected variables in submodules
3
4 module mod1
5 implicit none
6 private
7 integer, protected, public :: xx = 42
8 public :: set_xx
9 public :: echo1_xx, echo2_xx
10 interface
11 module subroutine echo1_xx()
12 end subroutine echo1_xx
13 module subroutine echo2_xx()
14 end subroutine echo2_xx
15 end interface
16 contains
17 subroutine set_xx(arg)
18 integer, intent(in) :: arg
19 xx = arg ! valid (it is host_associated)
20 end
21 end module
22 !
23 submodule (mod1) s1mod1
24 implicit none
25 contains
26 module subroutine echo1_xx()
27 xx = 11 ! valid (it is from the ancestor)
28 write(*,*) "xx=", xx
29 end subroutine echo1_xx
30 end submodule
31 !
32 submodule (mod1:s1mod1) s2mod1
33 implicit none
34 contains
35 module subroutine echo2_xx()
36 xx = 12 ! valid (it is from the ancestor)
37 write(*,*) "xx=", xx
38 end subroutine echo2_xx
39 end submodule
40 !
41 module mod2
42 use mod1
43 implicit none
44 integer, protected, public :: yy = 43
45 interface
46 module subroutine echo_xx()
47 end subroutine echo_xx
48 end interface
49 contains
50 subroutine bla
51 ! xx = 999 ! detected, leads to fatal error
52 end
53 end module
54 !
55 submodule (mod2) smod2
56 implicit none
57 contains
58 module subroutine echo_xx ()
59 xx = 10 ! { dg-error "is PROTECTED" }
60 write(*,*) "xx=", xx
61 yy = 22 ! valid (it is from the ancestor)
62 end
63 end submodule
64 !
65 program test_protected
66 use mod1
67 use mod2
68 implicit none
69 write(*,*) "xx=", xx
70 call set_xx(88)
71 write(*,*) "xx=", xx
72 call echo_xx
73 call echo1_xx
74 call echo2_xx
75 end program