On 11 January 2011 07:52, Patrick Horgan wrote: > int > main() > { > Â Â size_t a = 7; > Â Â int b = -3; > #if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >>= 6)) I use something like this: #if ((__GNUC__*100)+__GNUC_MINOR__) >= 406 If the macros aren't defined they will evaluate to zero. > #pragma GCC diagnostic push > #pragma GCC diagnostic ignored "-Wsign-compare" > #endif > Ugly but effective. I wrote this last week, which tames some of the ugliness: #if ((__GNUC__ * 100) + __GNUC_MINOR__) >= 405 # define GCC_DIAG_DO_PRAGMA(x) _Pragma (#x) # define GCC_DIAG_PRAGMA(x) GCC_DIAG_DO_PRAGMA(GCC diagnostic x) # if ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406 # define GCC_DIAG_OFF(x) GCC_DIAG_PRAGMA(push) \ GCC_DIAG_PRAGMA(ignored x) # define GCC_DIAG_ON(x) GCC_DIAG_PRAGMA(pop) # else # define GCC_DIAG_OFF(x) GCC_DIAG_PRAGMA(ignored x) # define GCC_DIAG_ON(x) GCC_DIAG_PRAGMA(warning x) # endif #else # define GCC_DIAG_OFF(x) # define GCC_DIAG_ON(x) #endif That gives convenient macros which are used like so: GCC_DIAG_OFF("-Wsign-compare") if (a < b) { GCC_DIAG_ON("-Wsign-compare") std::cout << "a<b\n"; } The macros use push/pop for 4.6+, or for 4.5 they just change the behaviour to "ignored" then back to "warning". They expand to nothing for older versions of GCC or for non-GCC compilers. The 4.5 behaviour is wrong if e.g. -Werror=sign-compare was being used, because GCC_DIAG_ON re-enables a warning not an error. For my purposes that was sufficient, it's probably not acceptable for library code. I've been using this for super-strict compilations with a modified GCC that has extra warnings I've added. One of my extra warnings has too many false positives, so I really needed to disable some known warnings I wasn't going to fix. For these super-strict builds, I need to temporarily disable warnings in third-party libraries which I can't or don't want to change (Boost in particular.) To do this I include them with -isystem instead of -I, which has the same effect as adding the system_header pragma to them. That allows me to make warnings fatal with -Werror without having to worry about errors in code I don't own.