https://gcc.gnu.org/g:ff2fb8508b8fb203faf8cd9a733b7b79d176810f

commit r16-8376-gff2fb8508b8fb203faf8cd9a733b7b79d176810f
Author: Jerry DeLisle <[email protected]>
Date:   Tue Mar 31 19:54:25 2026 -0700

    fortran: Fix INQUIRE(id=integer-expression) is rejected.
    
            PR fortran/124739
    
    gcc/fortran/ChangeLog:
    
            * io.cc (match_inquire_element): Change tag_id from a
            variable tag to an expression tag.
    
    gcc/testsuite/ChangeLog:
    
            * gfortran.dg/pr124739.f90: New test.

Diff:
---
 gcc/fortran/io.cc                      |  4 ++--
 gcc/testsuite/gfortran.dg/pr124739.f90 | 28 ++++++++++++++++++++++++++++
 2 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/gcc/fortran/io.cc b/gcc/fortran/io.cc
index 2db2245351e6..0a81d4a168ad 100644
--- a/gcc/fortran/io.cc
+++ b/gcc/fortran/io.cc
@@ -103,7 +103,7 @@ static const io_tag
        tag_err         = {"ERR", " err =", " %l", BT_UNKNOWN},
        tag_end         = {"END", " end =", " %l", BT_UNKNOWN},
        tag_eor         = {"EOR", " eor =", " %l", BT_UNKNOWN},
-       tag_id          = {"ID", " id =", " %v", BT_INTEGER},
+       tag_id          = {"ID", " id =", " %e", BT_INTEGER},
        tag_pending     = {"PENDING", " pending =", " %v", BT_LOGICAL},
        tag_newunit     = {"NEWUNIT", " newunit =", " %v", BT_INTEGER},
        tag_s_iqstream  = {"STREAM", " stream =", " %v", BT_CHARACTER};
@@ -4565,7 +4565,7 @@ match_inquire_element (gfc_inquire *inquire)
   RETM m = match_vtag (&tag_convert, &inquire->convert);
   RETM m = match_out_tag (&tag_strm_out, &inquire->strm_pos);
   RETM m = match_vtag (&tag_pending, &inquire->pending);
-  RETM m = match_vtag (&tag_id, &inquire->id);
+  RETM m = match_etag (&tag_id, &inquire->id);
   RETM m = match_vtag (&tag_s_iqstream, &inquire->iqstream);
   RETM m = match_dec_vtag (&tag_v_share, &inquire->share);
   RETM m = match_dec_vtag (&tag_v_cc, &inquire->cc);
diff --git a/gcc/testsuite/gfortran.dg/pr124739.f90 
b/gcc/testsuite/gfortran.dg/pr124739.f90
new file mode 100644
index 000000000000..f7ed37b413a3
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr124739.f90
@@ -0,0 +1,28 @@
+! { dg-do run }
+program pr
+  integer, parameter :: lun = 42
+  character(*), parameter :: lfn = 'fort.42'
+  integer :: id = -45
+  logical :: pending
+
+! Make sure there is no file with the name we will be using
+  open (lun, file=lfn, status='old', iostat=iostat)
+  if (iostat /= 0) then
+    close (lun, status='delete')
+  end if
+
+  open (lun, file=lfn)
+  write (lun,*) 'hello world!'
+  rewind (lun)
+
+  pending  = .true.
+  inquire (file=lfn, id=id, pending=pending)   ! Accepted
+  if (pending) stop 20
+  pending = .true.
+  inquire (file="/no/such/file", id=(id), pending=pending) ! Fixed
+  if (pending) stop 23
+  pending = .true.
+  inquire (unit=lun, id=(15 + 35 - 2*8), pending=pending) ! Fixed
+  if (pending) stop 23
+  close (lun, status='delete')
+end program pr

Reply via email to