3

What is the compiler warning flag for zero variadic macro arguments in GCC (I am using GCC 5.3.0)?

The warning is triggered by code like this

// for illustration purposes only:
int foo(int i) { return 0; };
#define FOO(A, ...) foo(A, ##__VA_ARGS__)
FOO(1);
      ^  warning: ISO C++11 requires at least one argument for the "..." in a variadic macro

but the warning doesn't indicate which flag is used to enable/disable the warning (this is typically shown in square brackets [-Wwarning-flag-name]).

In clang it is -Wgnu-zero-variadic-macro-arguments. I haven't been able to find anything like that in the warning documentation of gcc-5.3.0.

I've tried -Wgnu-zero-variadic-macro-arguments, -Wvarargs, -Wno-variadic-macros (thanks to @ Revolver_Ocelot) but none of these is in charge of this warning.

gnzlbg
  • 7,135
  • 5
  • 53
  • 106
  • What exactly are you trying to achieve? It doesn't look like `foo(int i)` has been defined in a way that makes it compatible with variadic macros. – Xirema Feb 23 '16 at 19:29
  • @Xirema I am trying to disable a warning, the example is for illustration purposes. – gnzlbg Feb 23 '16 at 19:33
  • [This question](http://stackoverflow.com/questions/11761703/overloading-macro-on-number-of-arguments) might help out. You could "overload" the macro with different number of variables so that the macro with one parameter works. – callyalater Feb 23 '16 at 19:35
  • @callyalater That's pretty wrong. I actually just want to pass the compiler the `-Wno-warning-flag-name` and be done with it. Its a warning, it must have a flag. Another option is to use `push`/`pop` locally but you still need the warning flag name. – gnzlbg Feb 23 '16 at 19:36
  • Does `-Wno-variadic-macros` helps? – Revolver_Ocelot Feb 23 '16 at 19:36
  • @Revolver_Ocelot nope, that flag doesn't remove this warning. I've added to the list of tried one in the question (with attribution). In the webpage it say that that flag is for warning on variadic macros in older versions of C (C90). – gnzlbg Feb 23 '16 at 19:37
  • 1
    How about this: http://stackoverflow.com/q/16767901/620382 – Zulan Feb 23 '16 at 19:39
  • @Zulan the first answer there provides the warning flag for clang, but not for GCC (where it shows the GCC warning, the warning flag is missing, and without that you cannot use it to disable the warning). – gnzlbg Feb 23 '16 at 19:41
  • 1
    And what about `FOO(1,);`? – Zulan Feb 23 '16 at 19:42
  • @Zulan I want to disable the warning not work around it :D Basically the only answer for this question is the flag that enables/disables this particular warning in GCC. – gnzlbg Feb 23 '16 at 19:45
  • What flag is used to specify standard? Omitting variadic arguments is illegal and it should be an error. There are gnu extensions which prevent it. Try to use `std=gnu++11`. It might be that compiling with strict adherence to standard gives you this message. – Revolver_Ocelot Feb 23 '16 at 19:46
  • I've rephrased the question to make it clear that i am just looking for the name of the warning flag. – gnzlbg Feb 23 '16 at 19:46
  • 1
    From what I can see it looks like this warning is only surfaced when compiling with `-pedantic`. If not using that there is no warning(on my machine). I am not sure if you can surpress the warnings that come form using `-pedantic` – NathanOliver Feb 23 '16 at 19:48
  • `Omitting variadic arguments is illegal and it should be an error`. No, omitting variadic arguments requires a diagnostic but it is not an error (the standard just require compilers to emit a diagnostic to be standard conformant). All compilers (IBM, Cray, Intel, MSVC, gcc, clang, nvcc...) expand `FOO(1)` to `foo(1)`, none of them expands it to `foo(1,)`, but to be standard compliant they need to tell you about it. – gnzlbg Feb 23 '16 at 19:49
  • @NathanOliver i've tried `#pragma GCC diagnostic push`, `#pragma GCC diagnostic ignored "-Wpedantic"`, ..., without luck :/ – gnzlbg Feb 23 '16 at 19:52
  • Yes but since a diagnostic is required I doubt they want it suppressed since it is `-pedantic`. – NathanOliver Feb 23 '16 at 19:52
  • @NathanOliver compiling without `-Wpedantic` removes the warning. Now I need to find a way to remove this warning in a couple of lines instead of in my whole program :/ – gnzlbg Feb 23 '16 at 19:54
  • @gnzlbg Maybe this will help: http://stackoverflow.com/questions/14304255/partially-disable-pedantic-warnings-in-gcc-within-source – NathanOliver Feb 23 '16 at 19:57
  • @NathanOliver the problem there is that for disabling pedantic you have to write `__extension__` before the expression that causes the warning, and this warning is only issued when the expression is omitted... – gnzlbg Feb 23 '16 at 20:00
  • @gnzlbg Write what up as an answer? do not use `-Wpedantic` and the warning will go away? – NathanOliver Feb 23 '16 at 20:04
  • I've posted a new question, now that this one is answered and we know the name of the warning flag (-Wpedantic) to figure out how to disable it for a macro definition within a source file: http://stackoverflow.com/questions/35587137/how-to-suppress-gcc-variadic-macro-argument-warning-for-zero-arguments-for-a-par – gnzlbg Feb 23 '16 at 20:08
  • @NathanOliver that the name of the warning flag to enable disable this warning is `-Wpedantic` basically. – gnzlbg Feb 23 '16 at 20:08

1 Answers1

4

The warning flag that is causing the issue is -Wpedantic. This is because omitting variadic arguments is illegal and it requires a diagnostic. A warning satisfies that requirement.

NathanOliver
  • 171,901
  • 28
  • 288
  • 402
  • I don't get the sense of this warning : `warning: ISO C++11 requires at least one argument for the "..." in a variadic macro` Isn't the `##` before `__VA_ARGS__` supposed to delete the comma if it isn't used ? That doesn't make any the -pedantic flag output this. Good thing the warning disappeared in the next versions of g++. – Tesla123 Mar 01 '23 at 10:02