2 ! Tests the patch that implements F2003 automatic allocation and
3 ! reallocation of allocatable arrays on assignment. The tests
4 ! below were generated in the final stages of the development of
6 ! test1 has been corrected for PR47051
8 ! Contributed by Dominique Dhumieres <dominiq@lps.ens.fr>
9 ! and Tobias Burnus <burnus@gcc.gnu.org>
23 ! Check that the bounds are set correctly, when assigning
24 ! to an array that already has the correct shape.
26 real :: a(10) = 1, b(51:60) = 2
27 real, allocatable :: c(:), d(:)
29 if (lbound (c, 1) .ne. lbound(a, 1)) STOP 1
30 if (ubound (c, 1) .ne. ubound(a, 1)) STOP 2
32 ! 7.4.1.3 "If variable is an allocated allocatable variable, it is
33 ! deallocated if expr is an array of different shape or any of the
34 ! corresponding length type parameter values of variable and expr
35 ! differ." Here the shape is the same so the deallocation does not
36 ! occur and the bounds are not recalculated. This was corrected
37 ! for the fix of PR47051.
38 if (lbound (c, 1) .ne. lbound(a, 1)) STOP 3
39 if (ubound (c, 1) .ne. ubound(a, 1)) STOP 4
41 if (lbound (d, 1) .ne. lbound(b, 1)) STOP 5
42 if (ubound (d, 1) .ne. ubound(b, 1)) STOP 6
44 ! The other PR47051 correction.
45 if (lbound (d, 1) .ne. lbound(b, 1)) STOP 7
46 if (ubound (d, 1) .ne. ubound(b, 1)) STOP 8
50 ! Check that the bounds are set correctly, when making an
51 ! assignment with an implicit conversion. First with a
52 ! non-descriptor variable....
54 integer(4), allocatable :: a(:)
57 if (lbound (a, 1) .ne. lbound(b, 1)) STOP 9
58 if (ubound (a, 1) .ne. ubound(b, 1)) STOP 10
62 ! ...and now a descriptor variable.
64 integer(4), allocatable :: a(:)
65 integer(8), allocatable :: b(:)
68 if (lbound (a, 1) .ne. lbound(b, 1)) STOP 11
69 if (ubound (a, 1) .ne. ubound(b, 1)) STOP 12
73 ! Check assignments of the kind a = f(...)
75 integer, allocatable :: a(:)
76 integer, allocatable :: c(:)
78 if (any (a .ne. [1, 2, 3, 4])) STOP 13
81 if (any ((a - 8) .ne. [1, 2, 3, 4])) STOP 14
84 if (any ((a - 4) .ne. [1, 2, 3, 4])) STOP 15
87 integer, allocatable, optional :: b(:)
89 if (.not.present (b)) then
91 elseif (.not.allocated (b)) then
100 ! Extracted from rnflow.f90, Polyhedron benchmark suite,
101 ! http://www.polyhedron.com
103 integer, parameter :: ncls = 233, ival = 16, ipic = 17
104 real, allocatable, dimension (:,:) :: utrsft
105 real, allocatable, dimension (:,:) :: dtrsft
106 real, allocatable, dimension (:,:) :: xwrkt
107 allocate (utrsft(ncls, ncls), dtrsft(ncls, ncls))
109 xwrkt = trs2a2 (ival, ipic, ncls)
110 if (any (shape (xwrkt) .ne. [ncls, ncls])) STOP 16
111 xwrkt = invima (xwrkt, ival, ipic, ncls)
112 if (nglobal .ne. 1) STOP 17
113 if (sum(xwrkt) .ne. xwrkt(ival, ival)) STOP 18
115 function trs2a2 (j, k, m)
116 real, dimension (1:m,1:m) :: trs2a2
117 integer, intent (in) :: j, k, m
118 nglobal = nglobal + 1
121 function invima (a, j, k, m)
122 real, dimension (1:m,1:m) :: invima
123 real, dimension (1:m,1:m), intent (in) :: a
124 integer, intent (in) :: j, k
126 invima (j, j) = 1.0 / (1.0 - a (j, j))
129 character(kind=1, len=100), allocatable, dimension(:) :: str
131 if (TRIM(str(1)) .ne. "abc") STOP 19
132 if (len(str) .ne. 100) STOP 20
135 character(kind=4, len=100), allocatable, dimension(:) :: str
136 character(kind=4, len=3) :: test = "abc"
138 if (TRIM(str(1)) .ne. test) STOP 21
139 if (len(str) .ne. 100) STOP 22
143 integer, allocatable :: a(:)
147 if (any (x%a .ne. [1,2,3])) STOP 23
149 if (any (x%a .ne. [4])) STOP 24