_Pragma diagnostic not working

Luca Bacci luca.bacci@outlook.com
Mon Feb 10 10:30:28 GMT 2025


Consider this file:

test-gcc.c
-------------------------
#if defined(__clang__)
#  if __clang_major__ >= 12
#    define FENV_ACCESS_ON _Pragma ("STDC FENV_ACCESS ON")
#  endif
#elif defined(_MSC_VER)
#  define FENV_ACCESS_ON __pragma (fenv_access (on))
#elif defined(__GNUC__)
   // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=34678
#  define FENV_ACCESS_ON \
     _Pragma ("GCC diagnostic push") \
     _Pragma ("GCC diagnostic ignored \"-Wunknown-pragmas\"") \
     _Pragma ("STDC FENV_ACCESS ON") \
     _Pragma ("GCC diagnostic pop")
#else
#  define FENV_ACCESS_ON _Pragma ("STDC FENV_ACCESS ON")
#endif

FENV_ACCESS_ON
-------------------------

When compiling with -Wall I get an "unknown pragma" warning:


test-gcc.c:18: warning: ignoring '#pragma STDC FENV_ACCESS' [-Wunknown-pragmas]

Yet, if I preprocess separately and compile, I don't get any warning:


gcc -E -P test-gcc.c | gcc -c -Wall -xc -

Anyobdy knows why?

Kind regards,
Luca


More information about the Gcc-help mailing list