Using C++20 __VA_OPT__ in a macro gives an error

Jonathan Wakely jwakely.gcc@gmail.com
Mon Sep 30 10:19:00 GMT 2019


On Sun, 29 Sep 2019 at 05:08, Edward Diener
<eldlistmailingz@tropicsoft.com> wrote:
>
> On 9/26/2019 3:25 PM, Edward Diener wrote:
> > I have a macro which uses the C++20 construct of __VA_OPT__. During a
> > compilation with og gcc-9.2 with the '-std=c++11' option the macro is
> > encountered in a header file, but it is never actually invoked in the
> > code. And yet gcc-9.2 gives an error of:
> >
> > error: __VA_OPT__ is not available until C++2a
> >
> > Why would this be happening ?
> >
> > I realize I can surround the macro with
> >
> > # if defined(__cplusplus) && __cplusplus > 201703L
> > #endif
> >
> > but my understanding is that macro code is not checked until it is
> > actually invoked during the preprocessing stage.
> >
> >
> >
>
> I know I saw this message but since I can not reproduce the occurrence
> in my code the OP should be ignored.

You were probably using an option like -pedantic-errors when you saw the error.

The token __VA_OPT__ is a reserved name, so in older standards that
don't define __VA_OPT__ the compiler is free to decide what it means.
If it wants to issue an error if that  token is encountered, it can do
so. If you think there's a good reason to allow it and delay errors
until it is used please file it in bugzilla (although it might not be
feasible to change the preprocessor that way).



More information about the Gcc-help mailing list