Pragma GCC Diagnostic Warning with GCC

I use gcc 4.5.1 and get warnings like:

warning: expected [error|warning|ignored] after '#pragma GCC diagnostic' 

The reason is the "diagnostic push" #Pragma GCC ", which does not exist for GCC <4.6.

I cannot change the code (this is not mine) and the gcc version. How to disable these warnings? Some gcc flags maybe?

PS I saw Why the "pragma GCC diagnostic push" pop warning in GCC / C ++? There is no answer to my question.

+4
source share
2 answers

gcc has these two flags for managing warnings regarding pragmas:

-Wunknown-pseudo-comments Warn when the "# pragma" directive is encountered that is not understood by GCC. If this command line parameter is used, warnings are even issued for unknown pragmas in the system header files. This is not the case if warnings are only enabled using the -Wall command line option.

-Wno-pseudo-comments Do not warn about abuses of pragmas, such as incorrect parameters, invalid syntax, or conflicts between pragmas. See also -Wunknown pr

You can disable them with -Wno-unknown-pragmas .

+8
source

Here are your options:

  • Use -Wno-pragmas to suppress all incorrect warnings about using pragmas. I do not consider it possible to ignore only the pragma that you are interested in.
  • Ignore warning outputs. You were warned by the compiler, so it did its job. You know why a warning occurs and regardless of whether the underlying case is harmless.
  • Use sed find / replace to remove only offensive #pragmas for your copy. You can probably include it in the build script and generate a copy of the source files on the fly. You can probably use sed to comment on violating #pragmas and use the inverse transform to undo it (say, before going to the shared repository).
  • Compile GCC 4.6 locally and use this instead.

http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html contains relevant warning information.

0
source

Source: https://habr.com/ru/post/1497288/


All Articles