📅 2014-Mar-11 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ gcc, pragma, warning ⬩ 📚 Archive
You may sometimes want to ignore or disable a specific type of warning that is generated when compiling your C or C++ code. The diagnostic pragmas of GCC and G++ compilers can be used to achieve this.
-Wenum-compare
for an entire C++ source file, add this to your code at the top:#pragma GCC diagnostic ignored "-Wenum-compare"
/**
* Code that generates this warning
*/
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wenum-compare"
/**
* Code that generates this warning
*/
#pragma GCC diagnostic pop
Note: As of GCC 5.1, few of the warnings in G++ (that is, only for C++ code) will not be ignored even when this pragma is used! More details here and here.
Tried with: GCC 4.8 and Ubuntu 12.04 LTS