4 ms·
I use -W4 and -WX with MSVC to enable the highest warning level and flag all warnings as errors. Then I disable a couple of the more pointless warnings (unrefe
by CamperBob2 10y ago
I use -W4 and -WX with MSVC to enable the highest warning level and flag all warnings as errors. Then I disable a couple of the more pointless warnings (unreferenced formal parameter, unreferenced local function, unreachable code...) that would otherwise keep me from being able to use -W4 without jumping through arbitrary hoops.
The problem with GCC, at least at the time I was using it several years ago, is that there seemed to be no way to disable individual warnings. Is that still true (or was it ever?)
- tubs 10y ago-Wno-specific-warning (I think it's always had this, or at least for a very long time).
- MaulingMonkey 10y agoAnd: #pragma GCC diagnostic push #pragma GCC diagnostic warning "-Wspecific-warning" #pragma GCC diagnostic ignored "-Wspecific-warning" ... #pragma GCC diagnostic pop For warnings you want to disable in a smaller scope. s/GCC/clang/ for clang. Bonus points: #define MM_WARNING_IGNORE_GCC(x) MM_IF_GCC( _Pragma(GCC diagnostic ignored x) ) #define MM_WARNING_IGNORE_CLANG(x) MM_IF_CLANG( _Pragma(clang diagnostic ignored x) ) #define MM_WARNING_IGNORE_MSVC(x) MM_IF_MSVC( __pragma(warning(disable: x)) ) #define MM_WARNING_PUSH() \ IF_GCC( _Pragma(GCC diagnostic push) ) \ IF_CLANG( _Pragma(clang diagnostic push) ) \ IF_MSVC( __pragma(warning(push)) ) #define MM_WARNING_POP() \ IF_GCC( _Pragma(GCC diagnostic pop) ) \ IF_CLANG( _Pragma(clang diagnostic pop) ) \ IF_MSVC( __pragma(warning(pop)) ) MM_WARNING_PUSH() MM_WARNING_IGNORE_GCC("-Wspecific-warning") MM_WARNING_IGNORE_CLANG("-Wspecific-warning") MM_WARNING_IGNORE_MSVC(1234) ... MM_WARNING_POP() Defining MM_IF_*() is left as an exercise to the reader.
- bla2 10y agoclang understands #pragma GCC diagnostic fine, no need to have special code for it.
- MaulingMonkey 10y agoHmm. I could swear this wasn't the case in one of the build environments I ran into (possibly an older version of clang or something? or perhaps I'm thinking of some other non-diagnostic pragma...)
- LukeShu 10y agoGCC has pretty much always had `-Wno-YOUR_SPECIFIC_ERROR`. By that, I mean it was present in a random version from 1993 (2.4.5). But it wasn't there in 1987 (1.35, the oldest version that can be easily downloaded), so it didn't literally always have it. Edit: I wasn't satisfied not knowing; so I dug through some more versions. The -Wno- flags were introduced in GCC 2.0 (1992). (Though only tracked down 1.41, not 1.42, the last of the 1.X line).