Why not push/pop warnings to ignore in the library?
_Pragma("GCC diagnostic push")
_Pragma("GCC diagnostic ignored \"-Wshadow\"")
int a = 1;
{
int a = 2;
}
_Pragma("GCC diagnostic pop")Why not push/pop warnings to ignore in the library?
_Pragma("GCC diagnostic push")
_Pragma("GCC diagnostic ignored \"-Wshadow\"")
int a = 1;
{
int a = 2;
}
_Pragma("GCC diagnostic pop")But you don't want to disable warnings throughout the file, just locally.
> Then you don't have non-portable cruft littering the code,
You can make it perfectly portable, with a little macro work. See, ,for example:
https://github.com/eyalroz/printf/blob/013db1e345cbb166a7eb7...
(this is from the standalone-no-libc-printf-family-implementation I maintain; the library is C, the test suite is C++ but it doesn't matter for the purposes of my point here.)
and that you only need to do once in your project (you can make it your own header). Even when it comes to use - you can place your warning-disabling within another macro, so that you end up only using a simple single macro for your actual code.
* Some versions can only change compiler options at top level, not within a function.
* I had problems with trying to push/ignore/pop a warning around an expression in a macro, since the entire thing expands at a single location.