Why should I initialize member variables in the order they’re declared in?

The reason is because they’re initialized in the order they’re declared in your class, not the order you initialize them in the constructor and it’s warning you that your constructor’s order won’t be used. This is to help prevent errors where the initialization of b depends on a or vice-versa. The reason for this ordering … Read more

Does there exist a static_warning?

Playing off of Michael E’s comment: #if defined(__GNUC__) #define DEPRECATE(foo, msg) foo __attribute__((deprecated(msg))) #elif defined(_MSC_VER) #define DEPRECATE(foo, msg) __declspec(deprecated(msg)) foo #else #error This compiler is not supported #endif #define PP_CAT(x,y) PP_CAT1(x,y) #define PP_CAT1(x,y) x##y namespace detail { struct true_type {}; struct false_type {}; template <int test> struct converter : public true_type {}; template <> struct … Read more

Is using #pragma warning push/pop the right way to temporarily alter warning level?

This will work with multiple compilers (and different versions of compilers). Header “push” #if defined(__clang__) # pragma clang diagnostic push #endif #if defined(_MSC_VER) # pragma warning(push) #endif #if defined(YOUR_FAVORITE_COMPILER) # pragma your compiler push warning #endif Header “pop” #if defined(__clang__) # pragma clang diagnostic pop #endif #if defined(_MSC_VER) # pragma warning(pop) #endif Some warning #if … Read more

Selectively disable GCC warnings for only part of a translation unit

This is possible in GCC since version 4.6, or around June 2010 in the trunk. Here’s an example: #pragma GCC diagnostic push #pragma GCC diagnostic error “-Wuninitialized” foo(a); /* error is given for this one */ #pragma GCC diagnostic push #pragma GCC diagnostic ignored “-Wuninitialized” foo(b); /* no diagnostic for this one */ #pragma GCC … Read more

How can I get rid of an “unused variable” warning in Xcode?

I’m unsure if it’s still supported in the new LLVM compiler, but GCC has an “unused” attribute you can use to suppress that warning: BOOL saved __attribute__((unused)) = [moc save:&error]; Alternatively (in case LLVM doesn’t support the above), you could split the variable declaration into a separate line, guaranteeing that the variable would be “used” … Read more

How do I get rid of “[some event] never used” compiler warnings in Visual Studio?

This appears to be warning 67 and can thus be suppressed with: #pragma warning disable 67 Don’t forget to restore it as soon as possible (after the event declaration) with: #pragma warning restore 67 However, I’d check again and make sure you’re raising the event somewhere, not just subscribing to it. The fact that the … Read more