Subject: Re: [wg14/wg21 liaison] Feature test macro for P0306 (__VA_OPT__)
From: Aaron Ballman (aaron_at_[hidden])
Date: 2021-01-28 07:01:15
On Thu, Jan 28, 2021 at 5:22 AM Jonathan Wakely via Liaison
> On Thu, 28 Jan 2021 at 10:18, Jonathan Wakely <cxx_at_[hidden]> wrote:
>> On Thu, 28 Jan 2021 at 10:15, Ville Voutilainen <ville.voutilainen_at_[hidden]> wrote:
>>> On Thu, 28 Jan 2021 at 12:13, Jonathan Wakely via SG10
>>> <sg10_at_[hidden]> wrote:
>>> > On Wed, 27 Jan 2021 at 20:54, Barry Revzin via Liaison <liaison_at_[hidden]> wrote:
>>> >> Eric Niebler actually asked this on StackOverflow a few years ago: https://stackoverflow.com/q/48045470/2069064
>>> >> The accepted answer there is:
>>> >> #define PP_THIRD_ARG(a,b,c,...) c
>>> >> #define VA_OPT_SUPPORTED_I(...) PP_THIRD_ARG(__VA_OPT__(,),true,false,)
>>> >> #define VA_OPT_SUPPORTED VA_OPT_SUPPORTED_I(?)
>>> > Who is going to remember that without having to look it up though?
>>> Is it going to be written so often that that becomes a major problem?
>>> > The #ifdef __VA_OPT__ solution was my first thought, it's unfortunate we forbid it. If we can't have that then I think we do need a feature test macro. The voodoo above will make most developers wish they were using Rust.
>>> If they're using VA_OPT, the cause is already lost.
>> And even if we add a feature test macro now (or allow #ifdef __VA_OPT__) there are still compilers that will reject it with an error (e.g. with -pedantic-errors in pre-C++20 modes). So maybe the ship has sailed and support this feature is already "untestable". You just have to know if your code can use it or not.
> Actually that would be true for the #ifdef __VA_OPT__ solution (we could say it's allowed, but if you try to use it on today's shipping compilers, it's ill-formed) but if we add a new macro you can be conservative:
> #ifdef __cpp_va_opt
> // Use it.
> // Maybe it's actually available, but we can't be sure.
> // Assume it isn't.
> So the question is whether to spell it __STDC_VA_OPT for WG14 compat, or __cpp_va_opt.
C doesn't currently have __VA_OPT__ (it's proposed with plenty of
support but not officially adopted into C23), so I'd be wary of naming
it __STDC_VA_OPT until WG14 adopts the feature. Also, WG14 reserves
all names that start with __STDC_ per C2x 6.11.8p1, so that's a little
bit awkward without running it by WG14 first.
One possible approach forward is to propose that macro as a predefined
conditional macro name in an update to WG14 N2160. If WG14 adopts the
feature and the macro name, then WG21 can adopt a similar change to
[cpp.predefined] and we're all good. If WG14 doesn't adopt the
feature, then WG21 can go with __cpp_va_opt.
> Liaison mailing list
> Subscription: https://lists.isocpp.org/mailman/listinfo.cgi/liaison
> Link to this post: http://lists.isocpp.org/liaison/2021/01/0259.php
SG10 list run by email@example.com