Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suppressing warnings in the source with pragma when compiling with g++ [duplicate]

What's the closest GCC equivalent to this MSVC preprocessor code?

#pragma warning( push )                    // Save the current warning state.
#pragma warning( disable : 4723 )          // C4723: potential divide by 0
// Code which would generate warning 4723.
#pragma warning( pop )                     // Restore warnings to previous state.

We have code in commonly included headers which we do not want to generate a specific warning for. However, we want files which include those headers to continue to generate that warning (if the project has that warning enabled).

like image 367
Jon-Eric Avatar asked Jan 01 '26 14:01

Jon-Eric


1 Answers

The closest thing is the GCC diagnostic pragma, #pragma GCC diagnostic [warning|error|ignored] "-Wwhatever". It isn't very close to what you want, and see the link for details and caveats.

like image 141
chaos Avatar answered Jan 03 '26 02:01

chaos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!