https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124690
Bug ID: 124690
Summary: gfortran preprocessor recurses where the C standard
precludes recursion
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: damian at archaeologic dot codes
Target Milestone: ---
Clause 6.10.5.4 paragraph 2 in the C23 standard's working draft states, "If the
name of the macro being replaced is found during this scan of the replacement
list (not including the rest of the source file’s preprocessing tokens), it is
not replaced."
The above stipulation prevents infinite recursion. The gfortran preprocessor
nonetheless recurses, leading to the error demonstrated below. The flang and
ifx compilers don't recurse and thus compile the code without error.
$ gfortran --version
GNU Fortran (GCC) 16.0.1 20260309 (experimental)
$ cat prepro-repro.F90
module julienne_m
implicit none
contains
subroutine call_julienne_assert(assertion)
logical assertion
if (.not. assertion) error stop
end subroutine
end module
#if ASSERTIONS
# define call_julienne_assert(assertion) call call_julienne_assert(assertion)
#else
# define call_julienne_assert(assertion)
#endif
program main
use julienne_m, only : call_julienne_assert
implicit none
integer :: i = -1
call_julienne_assert(i>0)
end program
$ gfortran -DASSERTIONS prepro-repro.F90
prepro-repro.F90:20:0:
20 | call_julienne_assert(i>0)
Error: detected recursion whilst expanding macro ‘call_julienne_assert’
prepro-repro.F90:21:12:
21 | end program
| 1
Error: Syntax error in CALL statement at (1)