I'm using a GCC #pragma like this:
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
...
#pragma GCC diagnostic pop
This works great and removes the erroneous maybe-uninitialized
errors that I'm seeing.
However, in old-ish versions of LLVM/clang++ (seen in clang version 9.0.0) this pragma is unknown and throws a warning. Since we also use -Werror
, these warnings are turned to errors and compilation fails. See this output:
/home/path/to/include.hpp:22:32: warning: unknown warning group '-Wmaybe-uninitialized', ignored [-Wunknown-warning-option]
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
^
In file included from /home/path/to/main.cpp:1:
/home/path/to/include.hpp:22:32: error: unknown warning group '-Wmaybe-uninitialized', ignored [-Werror,-Wunknown-warning-option]
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
^
1 error generated.
How can I use this GCC #pragma when compiling with LLVM?
#ifdef __GNUC__
?-Wno-unknown-warning-option
when compiling with clang.__GNUC__
. Better check for__GNUC__ && !__clang__
. More info-Wno-unkown-warning-option
is the simplest way to approach this.