| 1 |
! PR 101337 |
| 2 |
! { dg-do compile } |
| 3 |
! |
| 4 |
! TS 29113 |
| 5 |
! C407b An assumed-type 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-type, or as the first argument to any of |
| 8 |
! the intrinsic and intrinsic module functions IS_CONTIGUOUS, LBOUND, |
| 9 |
! PRESENT, RANK, SHAPE, SIZE, UBOUND, and C_LOC. |
| 10 |
! |
| 11 |
! This file contains tests that are expected to give diagnostics. |
| 12 |
|
| 13 |
! Check that passing an assumed-type variable as an actual argument |
| 14 |
! corresponding to a non-assumed-type dummy gives a diagnostic. |
| 15 |
|
| 16 |
module m |
| 17 |
interface |
| 18 |
subroutine f (a, b) |
| 19 |
implicit none |
| 20 |
integer :: a |
| 21 |
integer :: b |
| 22 |
end subroutine |
| 23 |
subroutine g (a, b) |
| 24 |
implicit none |
| 25 |
type(*) :: a |
| 26 |
integer :: b |
| 27 |
end subroutine |
| 28 |
subroutine h (a, b) |
| 29 |
implicit none |
| 30 |
type(*) :: a(*) |
| 31 |
integer :: b |
| 32 |
end subroutine |
| 33 |
end interface |
| 34 |
end module |
| 35 |
|
| 36 |
subroutine s0 (x) |
| 37 |
use m |
| 38 |
implicit none |
| 39 |
type(*) :: x |
| 40 |
|
| 41 |
call g (x, 1) |
| 42 |
call f (x, 1) ! { dg-error "Type mismatch" } |
| 43 |
call h (x, 1) ! Scalar to type(*),dimension(*): Invalid in TS29113 but valid since F2018 |
| 44 |
end subroutine |
| 45 |
|
| 46 |
! Check that you can't use an assumed-type array variable in an array |
| 47 |
! element or section designator. |
| 48 |
|
| 49 |
subroutine s1 (x, y) |
| 50 |
use m |
| 51 |
implicit none |
| 52 |
integer :: x(*) |
| 53 |
type(*) :: y(*) |
| 54 |
|
| 55 |
call f (x(1), 1) |
| 56 |
call g (y(1), 1) ! { dg-error "Assumed.type" } |
| 57 |
call h (y, 1) ! ok |
| 58 |
call h (y(1:3:1), 1) ! { dg-error "Assumed.type" } |
| 59 |
end subroutine |
| 60 |
|
| 61 |
! Check that you can't use an assumed-type array variable in other |
| 62 |
! expressions. This is clearly not exhaustive since few operations |
| 63 |
! are even plausible from a type perspective. |
| 64 |
|
| 65 |
subroutine s2 (x, y) |
| 66 |
implicit none |
| 67 |
type(*) :: x, y |
| 68 |
integer :: i |
| 69 |
|
| 70 |
! select type |
| 71 |
select type (x) ! { dg-error "Assumed.type|Selector shall be polymorphic" } |
| 72 |
type is (integer) |
| 73 |
i = 0 |
| 74 |
type is (real) |
| 75 |
i = 1 |
| 76 |
class default |
| 77 |
i = -1 |
| 78 |
end select |
| 79 |
|
| 80 |
! relational operations |
| 81 |
if (x & ! { dg-error "Assumed.type" "pr101337" } |
| 82 |
.eq. y) then ! { dg-error "Assumed.type" } |
| 83 |
return |
| 84 |
end if |
| 85 |
if (.not. (x & ! { dg-error "Assumed.type" "pr101337" } |
| 86 |
.ne. y)) then ! { dg-error "Assumed.type" } |
| 87 |
return |
| 88 |
end if |
| 89 |
if (.not. x) then ! { dg-error "Assumed.type" } |
| 90 |
return |
| 91 |
end if |
| 92 |
|
| 93 |
! assignment |
| 94 |
x & ! { dg-error "Assumed.type" } |
| 95 |
= y ! { dg-error "Assumed.type" } |
| 96 |
i = x ! { dg-error "Assumed.type" } |
| 97 |
y = i ! { dg-error "Assumed.type" } |
| 98 |
|
| 99 |
! arithmetic |
| 100 |
i = x + 1 ! { dg-error "Assumed.type" } |
| 101 |
i = -y ! { dg-error "Assumed.type" } |
| 102 |
i = (x & ! { dg-error "Assumed.type" "pr101337" } |
| 103 |
+ y) ! { dg-error "Assumed.type" } |
| 104 |
|
| 105 |
! computed go to |
| 106 |
goto (10, 20, 30), x ! { dg-error "Assumed.type|must be a scalar integer" } |
| 107 |
10 continue |
| 108 |
20 continue |
| 109 |
30 continue |
| 110 |
|
| 111 |
! do loops |
| 112 |
do i = 1, x ! { dg-error "Assumed.type" } |
| 113 |
continue |
| 114 |
end do |
| 115 |
do x = 1, i ! { dg-error "Assumed.type" } |
| 116 |
continue |
| 117 |
end do |
| 118 |
|
| 119 |
end subroutine |
| 120 |
|
| 121 |
! Check that calls to disallowed intrinsic functions produce a diagnostic. |
| 122 |
! Again, this isn't exhaustive, there are just too many intrinsics and |
| 123 |
! hardly any of them are plausible. |
| 124 |
|
| 125 |
subroutine s3 (x, y) |
| 126 |
implicit none |
| 127 |
type(*) :: x, y |
| 128 |
integer :: i |
| 129 |
|
| 130 |
i = bit_size (x) ! { dg-error "Assumed.type" } |
| 131 |
i = exponent (x) ! { dg-error "Assumed.type" } |
| 132 |
|
| 133 |
if (extends_type_of (x, & ! { dg-error "Assumed.type" } |
| 134 |
y)) then ! { dg-error "Assumed.type" "pr101337" } |
| 135 |
return |
| 136 |
end if |
| 137 |
|
| 138 |
if (same_type_as (x, & ! { dg-error "Assumed.type" } |
| 139 |
y)) then ! { dg-error "Assumed.type" "pr101337" } |
| 140 |
return |
| 141 |
end if |
| 142 |
|
| 143 |
i = storage_size (x) ! { dg-error "Assumed.type" } |
| 144 |
|
| 145 |
i = iand (x, & ! { dg-error "Assumed.type" } |
| 146 |
y) ! { dg-error "Assumed.type" "pr101337" } |
| 147 |
|
| 148 |
i = kind (x) ! { dg-error "Assumed.type" } |
| 149 |
|
| 150 |
end subroutine |