1

I have a chunk of code that I can disable compilation warnings for via pragmas, like the following example that disables a defined-but-not-used compilation warning:

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-function"
static int
bs_qd_debug_kv(void* cls, enum MHD_ValueKind kind, const char* key, const char* value)
{
    fprintf(stderr, "key [%s] -> value [%s]\n", key, value);
    return MHD_YES;
}
#pragma GCC diagnostic pop

This works fine, but how can I disable multiple warnings?

For instance, I get a defined-but-not-used compilation warning with the following two pragmas:

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-function"
static int
bs_qd_debug_kv(void* cls, enum MHD_ValueKind kind, const char* key, const char* value)
{
    fprintf(stderr, "key [%s] -> value [%s]\n", key, value);
    return MHD_YES;
}
#pragma GCC diagnostic pop
#pragma GCC diagnostic pop

Is there a different arrangement of #pragma directives, which allows specification of multiple pragmas on the enclosed code?

EDIT

Upon reading the linked question, it seems that question is almost entirely different from this one. This question asks about the use of multiple GCC-specific pragmas. The linked question asks about a compiler response to pragmas from OpenMP. I'm not sure that the two questions are identical, even though they both tangentially touch on the use of pragmas with GCC.

Alex Reynolds
  • 95,983
  • 54
  • 240
  • 345
  • just tested with gcc 6.2.1 and I get no warnings, even when using `-Wall`. If I remove the ununsed function pragma, I get the warning... BTW you could [edit] your post to only include base types & values so it would really be a [mcve], which isn't right now. – Jean-François Fabre Apr 26 '17 at 19:32
  • I am using GCC 4.8.5 and upgrading is not an option. If this is a "bug" with how GCC 4.8.5 handles pragmas, that's fine, if I can get some confirmation of this behavior. I do not get these warnings with Apple's current build of Clang, either (8.1.0), so I recognize this may be a GCC-specific issue and have tagged the question so. – Alex Reynolds Apr 26 '17 at 19:36
  • This is a known bug. See the linked dup. – dbush Apr 26 '17 at 19:44
  • @AlexReynolds if you cannot upgrade, you can always silence the unused parameter warnings using `(void)parameter` or attr ununused: http://stackoverflow.com/questions/3599160/unused-parameter-warnings-in-c-code so in your case, you only have 1 pragma warning to use. – Jean-François Fabre Apr 26 '17 at 19:47
  • also note that `-Wunused-parameter` isn't included in `-Wall` option in 6.2 – Jean-François Fabre Apr 26 '17 at 19:57
  • See if the answer to the supposed duplicate actually answers your question – M.M Apr 26 '17 at 21:43

0 Answers0