OSDN Git Service

50729495c8f8b8fd6536221ec47e9207e53188dc
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gfortran.dg / protected_6.f90
1 ! { dg-compile }
2 ! { dg-shouldfail "Invalid Fortran 2003 code" }
3 ! { dg-options "-std=f2003 -fall-intrinsics" }
4 ! PR fortran/23994
5 !
6 ! Test PROTECTED attribute. Within the module everything is allowed.
7 ! Outside (use-associated): For pointers, their association status
8 ! may not be changed. For nonpointers, their value may not be changed.
9 !
10 ! Test of a invalid code
11
12 module protmod
13   implicit none
14   integer, Protected          :: a
15   integer, protected, target  :: at
16   integer, protected, pointer :: ap
17 end module protmod
18
19 program main
20   use protmod
21   implicit none
22   a = 43       ! { dg-error "Assigning to PROTECTED variable" }
23   ap => null() ! { dg-error "Assigning to PROTECTED variable" }
24   nullify(ap)  ! { dg-error "Assigning to PROTECTED variable" }
25   ap => at     ! { dg-error "Assigning to PROTECTED variable" }
26   ap = 3       ! { dg-error "Assigning to PROTECTED variable" }
27   allocate(ap) ! { dg-error "Assigning to PROTECTED variable" }
28   ap = 73      ! { dg-error "Assigning to PROTECTED variable" }
29   call increment(a,at) ! { dg-error "use-associated with PROTECTED attribute" }
30 contains
31   subroutine increment(a1,a3)
32     integer, intent(inout) :: a1, a3
33     a1 = a1 + 1
34     a3 = a3 + 1
35   end subroutine increment
36   subroutine pointer_assignments(p)
37     integer, pointer :: p ! with [pointer] intent(out)
38     p => null()           ! this is invalid
39   end subroutine pointer_assignments
40 end program main
41
42 module prot2
43   implicit none
44 contains
45   subroutine bar
46     real, protected :: b ! { dg-error "only allowed in specification part of a module" }
47   end subroutine bar
48 end module prot2
49
50 ! { dg-final { cleanup-modules "protmod" } }