13

We're doing some code cleanup, fixing signed/unsigned comparisons, running static analysis, etc, on the code base of C, C++, and Java.

One of the warnings we're getting is

warning: ISO C does not permit named variadic macros

And its companion warning

warning: ISO C99 requires rest arguments to be used

Now, in the C code I used the C99 standard variadic macro to fix the problem, but in the C++ code, what is the correct answer? Using the same C99 style results in a different warning

warning: anonymous variadic macros were introduced in C99 

For which I don't see any answers.

We're using GCC (G++) 4.4.3 in Linux.

I'm hoping there is some flag, or other method that can correct, or disable it for the specific section of code - but its for the logging which is used in almost every file...

Community
  • 1
  • 1
Petriborg
  • 2,940
  • 3
  • 28
  • 49
  • possible duplicate of [Are Variadic macros nonstandard?](http://stackoverflow.com/questions/4786649/are-variadic-macros-nonstandard) – Bo Persson Mar 19 '12 at 17:59
  • 1
    Use C++11. Type `-std=c++0x` or `-std=c++11` on your GCC command line. Or just ignore the warning. – Kerrek SB Mar 19 '12 at 18:02
  • Yeah, using c++11 isn't yet in the cards, its just not supported well enough (yet) – Petriborg Mar 19 '12 at 18:04
  • So you're basically saying @Bo-Persson that there is no way to eliminate the warnings (short of turning them off) because variadic macros are not standard in C++ until c++11? – Petriborg Mar 19 '12 at 18:12
  • @Petri - I don't now of any other way. gcc 4.4.3 probably isn't aware of the latest changes to C++. – Bo Persson Mar 19 '12 at 18:15

1 Answers1

16

Use the gcc option -Wno-variadic-macros to disable that particular warning.

Edit: (from comments)

To disable the warning for a section of code but leave it on in general, use #pragma GCC diagnostic described here.

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wvariadic-macros"

    // Your code and/or include files
    // (No variadic warnings here)

#pragma GCC diagnostic pop
Drew Dormann
  • 59,987
  • 13
  • 123
  • 180
  • 1
    Is there a way to disable the warning for a section of code but leave it on in general? If I use this how do I disable `warning: ISO C99 requires rest arguments to be used` – Petriborg Mar 19 '12 at 18:10
  • 1
    @Petriborg: http://gcc.gnu.org/onlinedocs/gcc-4.6.3/gcc/Diagnostic-Pragmas.html#Diagnostic-Pragmas – Hasturkun Mar 19 '12 at 18:14
  • 1
    The pragma didn't work for me in stinky old gcc-4.2.3 but -Wno-variadic-macros did the job, so up-voted. – Martin Dorey Nov 23 '12 at 02:54
  • 1
    _That_ pragma didn't work for me either, but I got it working by `#pragma GCC diagnostic ignored "-Wvariadic-macros"` (without the `no-`) – Davide Jan 14 '15 at 17:02
  • It seems GCC doesn't work with the pragma but Clang does – Flamefire Sep 29 '20 at 09:49