https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119856
Bug ID: 119856
Summary: Missing commas in I/O formats not diagnosed by default
at compile time.
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: w6ws at earthlink dot net
Target Milestone: ---
Based on a posting in the Fortran discourse forum, I tried a few test cases
with missing comma in I/O formats. With the fix mentioned in PR 88052, my test
cases show diagnostics and the tests abend at run-time. However it would be
even better if these were caught at compile time.
Gfortran already has code for compile-time checking. But it isn't enabled by
default. It should be enabled by default to match the I/O library.
Tested with todays trunk:
$ gfortran --version
GNU Fortran (GCC) 16.0.0 20250417 (experimental)
Copyright (C) 2025 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$$ cat badfmt.f90
program badfmt
implicit none
integer :: ierr
character(*), parameter :: badfmt_p = '(a i0)'
character(8) :: badfmt_s = '(a i0)'
interface
function add_parens (s)
character(*), intent(in) :: s
character(len (s) + 2) :: add_parens
end function
end interface
! Test with character string in the I/O statement
write (*,"(ai0)", iostat=ierr) "hi", 3
if (ierr /= 0) print*,"could not write"
! Test checking FORMAT statements
write (*,100, iostat=ierr) "hi", 3
100 format (a i0)
! Test using a parameterized string
write (*,badfmt_p) "hi", 3
! Test using a regular character string (which might need to be diagnosed at
run-time,
! but in theory could be diagnosed at compile time.)
write (*,badfmt_s) "hi", 3
! Test using a regular character string (which will need to be diagnosed at
run-time)
write (*, add_parens (badfmt_s)) "hi", 3
end program
function add_parens (s)
character(*), intent(in) :: s
character(len (s) + 2) :: add_parens
add_parens = '(' // s // ')'
end function
$ gfortran -g badfmt.f90 # NOT diagnosed at compile time!
$ ./a.out
could not write
hi
At line 28 of file badfmt.f90 (unit = 6, file = 'stdout')
Fortran runtime error: Missing comma between descriptors
(a i0)
^
Error termination. Backtrace:
#0 0x7f4e7f7d588a in parse_format_list
at ../../../gcc-trunk/libgfortran/io/format.c:1240
#1 0x7f4e7f7e89a7 in data_transfer_init
at ../../../gcc-trunk/libgfortran/io/transfer.c:3298
#2 0x401599 in badfmt
at /home/wws/computer/fortran/tests/badfmt.f90:28
#3 0x4016bb in main
at /home/wws/computer/fortran/tests/badfmt.f90:33
$
$
$ gfortran -std=f95 -g badfmt.f90
badfmt.f90:16:13:
16 | write (*,"(ai0)", iostat=ierr) "hi", 3
| 1
Error: GNU Extension: Missing comma at (1)
badfmt.f90:21:15:
21 | 100 format (a i0)
| 1
Error: GNU Extension: Missing comma at (1)
badfmt.f90:24:14:
24 | write (*,badfmt_p) "hi", 3
| 1
Error: GNU Extension: Missing comma at (1)
badfmt.f90:20:36:
20 | write (*,100, iostat=ierr) "hi", 3
| 1
Error: FORMAT label 100 at (1) not defined
$