1! { dg-do compile }
2
3! PR fortran/45776
4! Variable definition context checks related to IO.
5
6! Contributed by Daniel Kraft, d@domob.eu.
7
8module m
9  implicit none
10  integer, protected :: a
11  character(len=128), protected :: msg
12end module m
13
14program main
15  use :: m
16  integer :: x
17  logical :: bool
18
19  write (*, iostat=a) 42 ! { dg-error "variable definition context" }
20  write (*, iomsg=msg) 42 ! { dg-error "variable definition context" }
21  read (*, '(I2)', advance='no', size=a) x ! { dg-error "variable definition context" }
22
23  ! These are ok.
24  inquire (unit=a)
25  inquire (file=msg, id=a, pending=bool)
26  inquire (file=msg)
27
28  ! These not, but list is not extensive.
29  inquire (unit=1, number=a) ! { dg-error "variable definition context" }
30  inquire (unit=1, encoding=msg) ! { dg-error "variable definition context" }
31  inquire (unit=1, formatted=msg) ! { dg-error "variable definition context" }
32
33  open (newunit=a, file="foo") ! { dg-error "variable definition context" }
34  close (unit=a)
35end program main
36