https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118838
Bug ID: 118838
Summary: _Pragma diagnostic ignored inside macro
Product: gcc
Version: 14.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: luca.bacci at outlook dot com
Target Milestone: ---
Consider the following source file:
test.c:
---------------------------------------
#define STDC_FENV_ACCESS_ON \
_Pragma ("GCC diagnostic push") \
_Pragma ("GCC diagnostic ignored \"-Wunknown-pragmas\"") \
_Pragma ("STDC FENV_ACCESS ON") \
_Pragma ("GCC diagnostic pop")
STDC_FENV_ACCESS_ON
---------------------------------------
GCC doesn't support pragma STDC FENV_ACCESS
(https://gcc.gnu.org/bugzilla/show_bug.cgi?id=34678), but the macro should
suppress the warning. This macro is useful for compat with both GCC and CLang.
However the diagnostic pragmas don't seem to have any effect:
$ gcc -c test-gcc.c -Wall
test-gcc.c:7: warning: ignoring '#pragma STDC FENV_ACCESS' [-Wunknown-pragmas]
7 | STDC_FENV_ACCESS_ON
If we avoid the macro, everything works correctly:
test.c:
---------------------------------------
_Pragma ("GCC diagnostic push")
_Pragma ("GCC diagnostic ignored \"-Wunknown-pragmas\"")
_Pragma ("STDC FENV_ACCESS ON")
_Pragma ("GCC diagnostic pop")
---------------------------------------
There are a few similar bug reports that are closed as RESOLVED:
- https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55578
- https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69558
Thanks in advance,
Luca