https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125533
Bug ID: 125533
Summary: CPP stringify operator emits \" for double-quotes in
Fortran mode causing syntax error
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: jvdelisle at gcc dot gnu.org
Target Milestone: ---
The CPP stringification operator (#x / "x" form) escapes embedded double-quote
characters with a backslash (\"). This is correct for C but invalid Fortran:
Fortran represents an embedded double-quote by doubling
it (""), not with a backslash. The backslash-escaped
output is rejected by the Fortran scanner with a spurious
syntax error.
This pattern appears in the assert and julienne fpm
packages, which use a CPP_STRINGIFY_SOURCE macro to
embed assertion expressions in error messages.
#define CPP_STRINGIFY_SOURCE(x) "x"
#define SHOW(a) print *, CPP_STRINGIFY_SOURCE(a)
program test
implicit none
character(len=20) :: key
key = "metadata"
SHOW(key .eq. "metadata")
end program
$ gfortran -cpp cpp_stringify_quote.F90
gfortran rejects the expansion of SHOW(key .eq. "metadata")
with a syntax error because the stringified argument
contains \". The program should compile and run
cleanly.
This one was rather sneaky.