1

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?

5
  • 2
    Could you wrap in #ifdef __GNUC__? Commented Nov 2, 2020 at 21:35
  • 1
    You could also, as the message suggests, use -Wno-unknown-warning-option when compiling with clang. Commented Nov 2, 2020 at 21:37
  • @NateEldredge Something like that could, and should. Potentially with an equivalent for LLVM in the else branch. After thinking hard about whether the diagnostic may be actually correct, and even if not whether it may be simpler to just bite the apple and initialize the bloody thing, redundantly. A move of an immediate to a register is not that expensive ;-). Commented Nov 2, 2020 at 21:37
  • 3
    @NateEldredge clang also defines __GNUC__. Better check for __GNUC__ && !__clang__. More info
    – rustyx
    Commented Nov 2, 2020 at 21:42
  • Thanks @NateEldredge. It seems that using the -Wno-unkown-warning-option is the simplest way to approach this.
    – jlconlin
    Commented Nov 2, 2020 at 21:58

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.