| 1 |
! { dg-do compile } |
| 2 |
! { dg-additional-options "-fcoarray=single" } |
| 3 |
! |
| 4 |
! TS 29113 |
| 5 |
! C535b An assumed-rank variable name shall not appear in a designator |
| 6 |
! or expression except as an actual argument corresponding to a dummy |
| 7 |
! argument that is assumed-rank, the argument of the C_LOC function |
| 8 |
! in the ISO_C_BINDING intrinsic module, or the first argument in a |
| 9 |
! reference to an intrinsic inquiry function. |
| 10 |
! |
| 11 |
! This has been renamed C838 in the Fortran 2018 standard, with C_SIZEOF |
| 12 |
! and SELECT_RANK additionally added. |
| 13 |
! |
| 14 |
! This test file contains tests that are expected to all pass. |
| 15 |
|
| 16 |
! Check that passing an assumed-rank variable as an actual argument |
| 17 |
! corresponding to an assumed-rank dummy works. |
| 18 |
|
| 19 |
module m |
| 20 |
interface |
| 21 |
subroutine g (a, b) |
| 22 |
implicit none |
| 23 |
real :: a(..) |
| 24 |
integer :: b |
| 25 |
end subroutine |
| 26 |
end interface |
| 27 |
end module |
| 28 |
|
| 29 |
subroutine s0 (x) |
| 30 |
use m |
| 31 |
implicit none |
| 32 |
real :: x(..) |
| 33 |
|
| 34 |
call g (x, 1) |
| 35 |
end subroutine |
| 36 |
|
| 37 |
! Check that calls to the permitted intrinsic functions work. |
| 38 |
|
| 39 |
function test_c_loc (a) |
| 40 |
use iso_c_binding |
| 41 |
implicit none |
| 42 |
integer, target :: a(..) |
| 43 |
type(c_ptr) :: test_c_loc |
| 44 |
|
| 45 |
test_c_loc = c_loc (a) |
| 46 |
end function |
| 47 |
|
| 48 |
function test_allocated (a) |
| 49 |
implicit none |
| 50 |
integer, allocatable :: a(..) |
| 51 |
logical :: test_allocated |
| 52 |
|
| 53 |
test_allocated = allocated (a) |
| 54 |
end function |
| 55 |
|
| 56 |
! 2-argument forms of the associated intrinsic are tested in c535b-3.f90. |
| 57 |
function test_associated (a) |
| 58 |
implicit none |
| 59 |
integer, pointer :: a(..) |
| 60 |
logical :: test_associated |
| 61 |
|
| 62 |
test_associated = associated (a) |
| 63 |
end function |
| 64 |
|
| 65 |
function test_bit_size (a) |
| 66 |
implicit none |
| 67 |
integer :: a(..) |
| 68 |
integer :: test_bit_size |
| 69 |
|
| 70 |
test_bit_size = bit_size (a) |
| 71 |
end function |
| 72 |
|
| 73 |
function test_digits (a) |
| 74 |
implicit none |
| 75 |
integer :: a(..) |
| 76 |
integer :: test_digits |
| 77 |
|
| 78 |
test_digits = digits (a) |
| 79 |
end function |
| 80 |
|
| 81 |
function test_epsilon (a) |
| 82 |
implicit none |
| 83 |
real :: a(..) |
| 84 |
real :: test_epsilon |
| 85 |
|
| 86 |
test_epsilon = epsilon (a) |
| 87 |
end function |
| 88 |
|
| 89 |
function test_huge (a) |
| 90 |
implicit none |
| 91 |
integer :: a(..) |
| 92 |
integer :: test_huge |
| 93 |
|
| 94 |
test_huge = huge (a) |
| 95 |
end function |
| 96 |
|
| 97 |
function test_is_contiguous (a) |
| 98 |
implicit none |
| 99 |
integer :: a(..) |
| 100 |
logical :: test_is_contiguous |
| 101 |
|
| 102 |
test_is_contiguous = is_contiguous (a) |
| 103 |
end function |
| 104 |
|
| 105 |
function test_kind (a) |
| 106 |
implicit none |
| 107 |
integer :: a(..) |
| 108 |
integer :: test_kind |
| 109 |
|
| 110 |
test_kind = kind (a) |
| 111 |
end function |
| 112 |
|
| 113 |
function test_lbound (a) |
| 114 |
implicit none |
| 115 |
integer :: a(..) |
| 116 |
integer :: test_lbound |
| 117 |
|
| 118 |
test_lbound = lbound (a, 1) |
| 119 |
end function |
| 120 |
|
| 121 |
function test_len1 (a) |
| 122 |
implicit none |
| 123 |
character(len=5) :: a(..) |
| 124 |
integer :: test_len1 |
| 125 |
|
| 126 |
test_len1 = len (a) |
| 127 |
end function |
| 128 |
|
| 129 |
function test_len2 (a) |
| 130 |
implicit none |
| 131 |
character(len=*) :: a(..) |
| 132 |
integer :: test_len2 |
| 133 |
|
| 134 |
test_len2 = len (a) |
| 135 |
end function |
| 136 |
|
| 137 |
function test_len3 (a) |
| 138 |
implicit none |
| 139 |
character(len=5), pointer :: a(..) |
| 140 |
integer :: test_len3 |
| 141 |
|
| 142 |
test_len3 = len (a) |
| 143 |
end function |
| 144 |
|
| 145 |
function test_len4 (a) |
| 146 |
implicit none |
| 147 |
character(len=*), pointer :: a(..) |
| 148 |
integer :: test_len4 |
| 149 |
|
| 150 |
test_len4 = len (a) |
| 151 |
end function |
| 152 |
|
| 153 |
function test_len5 (a) |
| 154 |
implicit none |
| 155 |
character(len=:), pointer :: a(..) |
| 156 |
integer :: test_len5 |
| 157 |
|
| 158 |
test_len5 = len (a) |
| 159 |
end function |
| 160 |
|
| 161 |
function test_len6 (a) |
| 162 |
implicit none |
| 163 |
character(len=5), allocatable :: a(..) |
| 164 |
integer :: test_len6 |
| 165 |
|
| 166 |
test_len6 = len (a) |
| 167 |
end function |
| 168 |
|
| 169 |
function test_len7 (a) |
| 170 |
implicit none |
| 171 |
character(len=*), allocatable :: a(..) |
| 172 |
integer :: test_len7 |
| 173 |
|
| 174 |
test_len7 = len (a) |
| 175 |
end function |
| 176 |
|
| 177 |
function test_len8 (a) |
| 178 |
implicit none |
| 179 |
character(len=:), allocatable :: a(..) |
| 180 |
integer :: test_len8 |
| 181 |
|
| 182 |
test_len8 = len (a) |
| 183 |
end function |
| 184 |
|
| 185 |
function test_maxexponent (a) |
| 186 |
implicit none |
| 187 |
real :: a(..) |
| 188 |
integer :: test_maxexponent |
| 189 |
|
| 190 |
test_maxexponent = maxexponent (a) |
| 191 |
end function |
| 192 |
|
| 193 |
function test_minexponent (a) |
| 194 |
implicit none |
| 195 |
real :: a(..) |
| 196 |
integer :: test_minexponent |
| 197 |
|
| 198 |
test_minexponent = minexponent (a) |
| 199 |
end function |
| 200 |
|
| 201 |
function test_new_line (a) |
| 202 |
implicit none |
| 203 |
character :: a(..) |
| 204 |
character :: test_new_line |
| 205 |
|
| 206 |
test_new_line = new_line (a) |
| 207 |
end function |
| 208 |
|
| 209 |
function test_precision (a) |
| 210 |
implicit none |
| 211 |
real :: a(..) |
| 212 |
integer :: test_precision |
| 213 |
|
| 214 |
test_precision = precision (a) |
| 215 |
end function |
| 216 |
|
| 217 |
function test_present (a, b, c) |
| 218 |
implicit none |
| 219 |
integer :: a, b |
| 220 |
integer, optional :: c(..) |
| 221 |
integer :: test_present |
| 222 |
|
| 223 |
if (present (c)) then |
| 224 |
test_present = a |
| 225 |
else |
| 226 |
test_present = b |
| 227 |
end if |
| 228 |
end function |
| 229 |
|
| 230 |
function test_radix (a) |
| 231 |
implicit none |
| 232 |
real :: a(..) |
| 233 |
integer :: test_radix |
| 234 |
|
| 235 |
test_radix = radix (a) |
| 236 |
end function |
| 237 |
|
| 238 |
function test_range (a) |
| 239 |
implicit none |
| 240 |
real :: a(..) |
| 241 |
integer :: test_range |
| 242 |
|
| 243 |
test_range = range (a) |
| 244 |
end function |
| 245 |
|
| 246 |
function test_rank (a) |
| 247 |
implicit none |
| 248 |
integer :: a(..) |
| 249 |
integer :: test_rank |
| 250 |
|
| 251 |
test_rank = rank (a) |
| 252 |
end function |
| 253 |
|
| 254 |
function test_shape (a) |
| 255 |
implicit none |
| 256 |
integer :: a(..) |
| 257 |
logical :: test_shape |
| 258 |
|
| 259 |
test_shape = (rank (a) .eq. size (shape (a))) |
| 260 |
end function |
| 261 |
|
| 262 |
function test_size (a) |
| 263 |
implicit none |
| 264 |
integer :: a(..) |
| 265 |
logical :: test_size |
| 266 |
|
| 267 |
test_size = (size (a) .eq. product (shape (a))) |
| 268 |
end function |
| 269 |
|
| 270 |
function test_storage_size (a) |
| 271 |
implicit none |
| 272 |
integer :: a(..) |
| 273 |
integer :: test_storage_size |
| 274 |
|
| 275 |
test_storage_size = storage_size (a) |
| 276 |
end function |
| 277 |
|
| 278 |
function test_tiny (a) |
| 279 |
implicit none |
| 280 |
real :: a(..) |
| 281 |
real :: test_tiny |
| 282 |
|
| 283 |
test_tiny = tiny (a) |
| 284 |
end function |
| 285 |
|
| 286 |
function test_ubound (a) |
| 287 |
implicit none |
| 288 |
integer :: a(..) |
| 289 |
integer :: test_ubound |
| 290 |
|
| 291 |
test_ubound = ubound (a, 1) |
| 292 |
end function |
| 293 |
|
| 294 |
! Note: there are no tests for these inquiry functions that can't |
| 295 |
! take an assumed-rank array argument for other reasons: |
| 296 |
! |
| 297 |
! coshape, lcobound, ucobound: requires CODIMENSION attribute, which is |
| 298 |
! not permitted on an assumed-rank variable. |
| 299 |
! |
| 300 |
|
| 301 |
! F2018 additionally permits the first arg to C_SIZEOF to be |
| 302 |
! assumed-rank (C838). |
| 303 |
|
| 304 |
function test_c_sizeof (a) |
| 305 |
use iso_c_binding |
| 306 |
implicit none |
| 307 |
integer :: a(..) |
| 308 |
integer :: test_c_sizeof |
| 309 |
|
| 310 |
test_c_sizeof = c_sizeof (a) |
| 311 |
end function |
| 312 |
|
| 313 |
! F2018 additionally permits an assumed-rank array as the selector |
| 314 |
! in a SELECT RANK construct (C838). |
| 315 |
|
| 316 |
function test_select_rank (a) |
| 317 |
implicit none |
| 318 |
integer :: a(..) |
| 319 |
integer :: test_select_rank |
| 320 |
|
| 321 |
select rank (a) |
| 322 |
rank (0) |
| 323 |
test_select_rank = 0 |
| 324 |
rank (1) |
| 325 |
test_select_rank = 1 |
| 326 |
rank (2) |
| 327 |
test_select_rank = 2 |
| 328 |
rank default |
| 329 |
test_select_rank = -1 |
| 330 |
end select |
| 331 |
end function |