libgfortran/ChangeLog:
[official-gcc.git] / gcc / testsuite / gfortran.dg / save_5.f90
blob20d3b7ad88a947fae252c4b6688698571538ec83
1 ! { dg-do run }
2 ! { dg-options "-fno-automatic" }
4 ! PR fortran/55733
6 ! Check that -fno-automatic makes the local variable SAVEd
9 ! Scalar allocatable
10 subroutine foo(i)
11 integer :: i
12 integer, allocatable :: j
13 if (i == 1) j = 42
14 if (.not. allocated (j)) call abort ()
15 if (j /= 42) call abort ()
16 end
18 ! Deferred-length string scalar
19 subroutine bar()
20 logical, save :: first = .true.
21 character(len=:), allocatable :: str
22 if (first) then
23 first = .false.
24 if (allocated (str)) call abort ()
25 str = "ABCDEF"
26 end if
27 if (.not. allocated (str)) call abort ()
28 if (len (str) /= 6) call abort ()
29 if (str(1:6) /= "ABCDEF") call abort ()
30 end subroutine bar
32 ! Deferred-length string array
33 subroutine bar_array()
34 logical, save :: first = .true.
35 character(len=:), allocatable :: str
36 if (first) then
37 first = .false.
38 if (allocated (str)) call abort ()
39 str = "ABCDEF"
40 end if
41 if (.not. allocated (str)) call abort ()
42 if (len (str) /= 6) call abort ()
43 if (str(1:6) /= "ABCDEF") call abort ()
44 end subroutine bar_array
46 call foo(1)
47 call foo(2)
48 call bar()
49 call bar_array()
50 call bar()
51 call bar_array()
52 end