| 1 |
! { dg-do compile } |
| 2 |
|
| 3 |
! PR fortran/45776 |
| 4 |
! Variable definition context checks related to IO. |
| 5 |
|
| 6 |
! Contributed by Daniel Kraft, [email protected]. |
| 7 |
|
| 8 |
module m |
| 9 |
implicit none |
| 10 |
|
| 11 |
integer, protected :: a |
| 12 |
character(len=128), protected :: str |
| 13 |
end module m |
| 14 |
|
| 15 |
program main |
| 16 |
use :: m |
| 17 |
integer, parameter :: b = 42 |
| 18 |
integer :: x |
| 19 |
character(len=128) :: myStr |
| 20 |
|
| 21 |
namelist /definable/ x, myStr |
| 22 |
namelist /undefinable/ x, a |
| 23 |
|
| 24 |
! These are invalid. |
| 25 |
read (myStr, *) a ! { dg-error "variable definition context" } |
| 26 |
read (myStr, *) x, b ! { dg-error "variable definition context" } |
| 27 |
write (str, *) 5 ! { dg-error "variable definition context" } |
| 28 |
read (*, nml=undefinable) ! { dg-error "contains the symbol 'a' which may not" } |
| 29 |
|
| 30 |
! These are ok. |
| 31 |
read (str, *) x |
| 32 |
write (myStr, *) a |
| 33 |
write (myStr, *) b |
| 34 |
print *, a, b |
| 35 |
write (*, nml=undefinable) |
| 36 |
read (*, nml=definable) |
| 37 |
write (*, nml=definable) |
| 38 |
end program main |