How to disable all warnings using pragma directives in GCC

I am looking for a way to suppress all possible warnings that I can get with Gcc with pragma directives. I made some protective macros that helped me disconnect third-party headers from warnings, and so far they work like a charm for msvc and clang. I still lack the correct way to use the Gcc diagnostic pragmas to suppress every warning in a section. Let me give you some examples:

In msvc we can do this:

#pragma warning(push, 0) // Code that produces warnings... #pragma warning(pop) 

And in clang we can do this:

 #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wall" #pragma clang diagnostic ignored "-Wextra" // Code that produces warnings... #pragma clang diagnostic pop 

And the code in the middle is now disconnected from warnings forever.

And in Gcc, we also have similar pragma directives with clang, and I thought I could try something like this:

 #pragma GCC diagnostic push #pramga GCC diagnostic ignored "-Wall" #pragma GCC diagnostic ignored "-Wextra" // Code that produces warnings... #pramga GCC diagnostic pop 

But passing -Wall and -Wextra in a diagnostic ignored pragma in GCC does not work like clang and does not disable all possible warnings. Instead, a special warning is sent to disable the operation:

 #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-parameter" void foo (int x) // No longer getting "unused parameter 'x'" warning { } #pragma GCC diagnostic pop 

So the only workaround I can make so far is to create a long list with all the GCC warnings and use them as mentioned above. Is there a more elegant solution? If not, where can I get a complete list of Gcc alerts (preferably on an equal list)?

+7
c ++ gcc warnings pragma
source share
1 answer

The documentation says:

Currently, you can only monitor warnings (usually controlled by "-W ...) and not all of them . Use the -fdiagnostics-show-option to determine which diagnostics are manageable and which option controls them.

+1
source share

All Articles