The program module sk1 implicit none type char character :: ch end type char interface read (formatted) module procedure read_formatted end interface read (formatted) contains subroutine read_formatted (dtv, unit, iotype, vlist, iostat, iomsg) class (char), intent(inout) :: dtv integer, intent(in) :: unit character (len=*), intent(in) :: iotype integer, intent(in) :: vlist(:) integer, intent(out) :: iostat character (len=*), intent(inout) :: iomsg character :: ch read (unit,fmt='(A1)', advance="no", iostat=iostat, iomsg=iomsg) ch iostat = 42 dtv%ch = ch end subroutine read_formatted end module sk1 program skip1 use sk1 implicit none type (char) :: x open (10,status="scratch") write (10,'(A)') '', 'a' rewind (10) read (10,*) x write (*,'(10(A))') "Read: '",x%ch,"'" end program skip1 runs to completion, but it should propagate the iostat to the caller and error out on the read.
GCC 13.1 is being released, retargeting bugs to GCC 13.2.
GCC 13.2 is being released, retargeting bugs to GCC 13.3.
On my list.
Created attachment 57504 [details] Proposed partial patch Proposed patch for the original test case with a READ function.
The master branch has been updated by Jerry DeLisle <jvdelisle@gcc.gnu.org>: https://gcc.gnu.org/g:3f58f96a4e8255e222953f9856bcd6c25f7b33cd commit r14-9168-g3f58f96a4e8255e222953f9856bcd6c25f7b33cd Author: Jerry DeLisle <jvdelisle@gcc.gnu.org> Date: Sun Feb 25 14:50:07 2024 -0800 libgfortran: Propagate user defined iostat and iomsg. PR libfortran/105456 libgfortran/ChangeLog: * io/list_read.c (list_formatted_read_scalar): Add checks for the case where a user defines their own error codes and error messages and generate the runtime error. * io/transfer.c (st_read_done): Whitespace. gcc/testsuite/ChangeLog: * gfortran.dg/pr105456.f90: New test.
The master branch has been updated by Jerry DeLisle <jvdelisle@gcc.gnu.org>: https://gcc.gnu.org/g:21edfb0051ed8d0ff46d5638c2bce2dd71f26d1f commit r14-9328-g21edfb0051ed8d0ff46d5638c2bce2dd71f26d1f Author: Jerry DeLisle <jvdelisle@gcc.gnu.org> Date: Tue Mar 5 20:49:23 2024 -0800 Fortran: Add user defined error messages for UDTIO. The defines IOMSG_LEN and MSGLEN were redundant so these are combined into IOMSG_LEN as defined in io.h. The remainder of the patch adds checks for when a user defined derived type IO procedure sets the IOSTAT or IOMSG variables independent of the librrary defined I/O messages. PR libfortran/105456 libgfortran/ChangeLog: * io/io.h (IOMSG_LEN): Moved to here. * io/list_read.c (MSGLEN): Removed MSGLEN. (convert_integer): Changed MSGLEN to IOMSG_LEN. (parse_repeat): Likewise. (read_logical): Likewise. (read_integer): Likewise. (read_character): Likewise. (parse_real): Likewise. (read_complex): Likewise. (read_real): Likewise. (check_type): Likewise. (list_formatted_read_scalar): Adjust to IOMSG_LEN. (nml_read_obj): Add user defined error message. * io/transfer.c (unformatted_read): Add user defined error message. (unformatted_write): Add user defined error message. (formatted_transfer_scalar_read): Add user defined error message. (formatted_transfer_scalar_write): Add user defined error message. * io/write.c (list_formatted_write_scalar): Add user defined error message. (nml_write_obj): Add user defined error message. gcc/testsuite/ChangeLog: * gfortran.dg/pr105456-nmlr.f90: New test. * gfortran.dg/pr105456-nmlw.f90: New test. * gfortran.dg/pr105456-ruf.f90: New test. * gfortran.dg/pr105456-wf.f90: New test. * gfortran.dg/pr105456-wuf.f90: New test.
The master branch has been updated by Jerry DeLisle <jvdelisle@gcc.gnu.org>: https://gcc.gnu.org/g:03932d3203bce244edd812b81921c2f16ea18d86 commit r14-9348-g03932d3203bce244edd812b81921c2f16ea18d86 Author: Jerry DeLisle <jvdelisle@gcc.gnu.org> Date: Wed Mar 6 19:46:04 2024 -0800 Fortran: Fix issue with using snprintf function. The previous patch used snprintf to set the message string. The message string is not a formatted string and the snprintf will interpret '%' related characters as format specifiers when there are no associated output variables. A segfault ensues. This change replaces snprintf with a fortran string copy function and null terminates the message string. PR libfortran/105456 libgfortran/ChangeLog: * io/list_read.c (list_formatted_read_scalar): Use fstrcpy from libgfortran/runtime/string.c to replace snprintf. (nml_read_obj): Likewise. * io/transfer.c (unformatted_read): Likewise. (unformatted_write): Likewise. (formatted_transfer_scalar_read): Likewise. (formatted_transfer_scalar_write): Likewise. * io/write.c (list_formatted_write_scalar): Likewise. (nml_write_obj): Likewise. gcc/testsuite/ChangeLog: * gfortran.dg/pr105456.f90: Revise using '%' characters in users error message.
Not planning any backport on this. Closing.