私はマクロに少し慣れていないので簡単ですが、Windowsでコンパイルすると大量の警告を生成する外部ライブラリがあります(Linuxではそれほど悪くありません)。ヘッダーのみのライブラリなので、ライブラリ全体の警告をオフにすることはできませんが、警告を生成している各セクションを無効にすることはできます (これは少し面倒です)。
それで、マクロを作成できるかどうか疑問に思っていたので、以下に次のように入力する代わりに、数行でそれを実行できます。
#ifdef _WIN32
#pragma warning (push)
#pragma warning(disable : 4355) // 'this' used in base member initialize list
#endif
code that generates warning
#ifdef _WIN32
#pragma warning (pop)
#endif
ただし、次のようなマクロを作成しようとすると
// Disable a warning on win32 platform
// You must call DISABLE_WIN32_PRAGMA_WARN_END afterwards
#define DISABLE_WIN32_PRAGMA_WARN (nnn) \
#ifdef _WIN32 \
#pragma warning (push) \
#pragma warning(disable : nnn ) \
#endif
#define DISABLE_WIN32_PRAGMA_WARN_END \
#ifdef _WIN32 \
#pragma warning (pop) \
#endif
ただし、VS2012 を使用してコンパイルすると、次のエラーが発生します。
error C2121: '#' : invalid character : possibly the result of a macro expansion
error C2065: 'nnn' : undeclared identifier
error C2351: obsolete C++ constructor initialization syntax
error C2612: trailing 'identifier' illegal in base/member initializer list