On 9/30/2019 6:08 AM, Jonathan Wakely wrote:
On Sat, 28 Sep 2019 at 04:29, Edward Diener wrote:
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.
You could also consult
https://gcc.gnu.org/projects/cxx-status.html#cxx2a which notes that
the support is incomplete.
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 ?
Yes, it's available as a GNU extension. You can get a diagnostic with
-std=c++14 -Wpedantic, but not with any -std=gnu++NN modes.
I would strongly argue that if it is available as a GNU extension
outside of normal C++20 support in gcc 8.1 on up then it should be
available when specifying '-std=gnu++nn' but not available when
specifying '-std=c++nn' for any C++ level except for '-std=c++2a'. Isn't
the idea of gnu extensions that they should only be available when the
programmer is using a gnu compiler mode, but not available if a
programmer is using a c++ compiler mode ?