Support for __VA_OPT__ in gcc

Edward Diener eldlistmailingz@tropicsoft.com
Sat Sep 28 03:28:00 GMT 2019


Given this program:

#define PP_THIRD_ARG(a,b,c,...) c
#define VA_OPT_SUPPORTED_I(...) PP_THIRD_ARG(__VA_OPT__(,),1,0,)
#define VA_OPT_SUPPORTED() VA_OPT_SUPPORTED_I(?)

#include <iostream>

int main()
      {
      int result = VA_OPT_SUPPORTED();
      std::cout << result;
      return 0;
      }

as a test for __VA_OPT__ support in a C++ compiler ( taken from
https://stackoverflow.com/questions/48045470/portably-detect-va-opt-support 
)
I have discovered that __VA_OPT__ support started with gcc-8.1. However 
I have also discovered that the support occurs no matter what the C++ 
standard level is used for the compilation and not just when the option 
is 'std=c++2a'. In other words I can compile the program with 
'std=c++03', link and run the program and the program will output 1, 
showing __VA_OPT__ support, rather than 0, which shows that __VA_OPT__ 
is not supported.

If I compile the above with any version of gcc lower than gcc-8.1 the 
program will outpyt 0 no matter what -std mode I use.

Is this intended, that the C++20 __VA_OPT__ support works in all modes 
for gcc-8.1 and higher ?



More information about the Gcc-help mailing list