summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gfortran.dg/save_5.f90
blob: 20d3b7ad88a947fae252c4b6688698571538ec83 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
! { dg-do run }
! { dg-options "-fno-automatic" }
!
! PR fortran/55733
!
! Check that -fno-automatic makes the local variable SAVEd
!

! Scalar allocatable
subroutine foo(i)
  integer :: i
  integer, allocatable :: j
  if (i == 1) j = 42
  if (.not. allocated (j)) call abort ()
  if (j /= 42) call abort ()
end

! Deferred-length string scalar
subroutine bar()
  logical, save :: first = .true.
  character(len=:), allocatable :: str
  if (first) then
    first = .false.
    if (allocated (str)) call abort ()
    str = "ABCDEF"
  end if
  if (.not. allocated (str)) call abort ()
  if (len (str) /= 6) call abort ()
  if (str(1:6) /= "ABCDEF") call abort ()
end subroutine bar

! Deferred-length string array
subroutine bar_array()
  logical, save :: first = .true.
  character(len=:), allocatable :: str
  if (first) then
    first = .false.
    if (allocated (str)) call abort ()
    str = "ABCDEF"
  end if
  if (.not. allocated (str)) call abort ()
  if (len (str) /= 6) call abort ()
  if (str(1:6) /= "ABCDEF") call abort ()
end subroutine bar_array

call foo(1)
call foo(2)
call bar()
call bar_array()
call bar()
call bar_array()
end