C++ Logo

SG10

Advanced search

Subject: Re: [wg14/wg21 liaison] Feature test macro for P0306 (__VA_OPT__)
From: Richard Smith (richardsmith_at_[hidden])
Date: 2021-01-27 14:47:18


Uh-oh. Using

#ifdef __VA_OPT__

as a feature test system is problematic because we previously said that
__VA_OPT__ is ill-formed if it appears anywhere other than in a #define for
a variadic macro. Several existing C++20 implementations reject that #ifdef.

Perhaps we don't need a feature-test macro, though:

#define HAS_VA_OPT_IMPL___VA_OPT__(...) 0
#define HAS_VA_OPT_IMPL_YES 1
#define HAS_VA_OPT_IMPL(A, ...) HAS_VA_OPT_IMPL_ ## __VA_OPT__(YES)
#define HAS_VA_OPT HAS_VA_OPT_IMPL(HAS_VA_OPT_IMPL_, YES)

#if HAS_VA_OPT
...
#else
...
#endif

... seems to work out OK.

On Tue, Jan 26, 2021 at 6:28 AM Ben Craig <ben.craig_at_[hidden]> wrote:

> +1
>
>
>
> *From:* Liaison <liaison-bounces_at_[hidden]> *On Behalf Of *Thomas
> Köppe via Liaison
> *Sent:* Monday, January 25, 2021 5:21 PM
> *To:* Richard Smith <richardsmith_at_[hidden]>
> *Cc:* Thomas Köppe <tkoeppe_at_[hidden]>; liaison_at_[hidden];
> sg10_at_[hidden]
> *Subject:* [EXTERNAL] Re: [wg14/wg21 liaison] Feature test macro for
> P0306 (__VA_OPT__)
>
>
>
> The proposed solution seems elegant to me. If you say that's
> implementable, I'd be in favour of that.
>
>
>
> I have very regrettably not sent an updated paper to WG14 for this
> feature, it's one of the things on my list. I shall prioritize getting it
> done!
>
>
>
> On Mon, 25 Jan 2021 at 23:02, Richard Smith <richardsmith_at_[hidden]>
> wrote:
>
> [+WG14 liaison list]
>
>
>
>
>
> On Mon, Jan 25, 2021 at 2:59 PM Richard Smith <richardsmith_at_[hidden]>
> wrote:
>
> Hi,
>
>
>
> SD-FeatureTest doesn't mention P0306. I think a feature test macro would
> be useful here, to allow projects to incrementally adopt the new
> functionality. Example:
>
>
>
> #if __cpp_va_opt
>
> #define FOO(a, ...) f(a __VA_OPT__(,) __VA_ARGS__)
>
> #elif __GNUC__
>
> #define FOO(a, ...) f(a , ## __VA_ARGS__)
>
> #else
>
> // Hopefully we get the MSVC implicit comma deletion behavior.
>
> #define FOO(a, ...) f(a , __VA_ARGS__)
>
> #endif
>
>
>
> Note that the __GNUC__ extension is enabled by default, even in conforming
> modes, in GCC, Clang, and ICC. However, after the adoption of P0306, it's
> no longer a conforming extension, so presumably it will be phased out at
> some point, and uses of the feature-test macro, such as in the above
> example, are going to become necessary.
>
>
>
> Regarding the name of the macro: this functionality is shared with C, and
> as such, a __cpp_* name is probably not ideal. However, there's another
> interesting option: we could use
>
>
>
> #ifdef __VA_OPT__
>
> ...
>
>
>
> as the feature test mechanism. This doesn't appear to conflict with
> anything else, and is in line with our feature test mechanism for
> __has_cpp_attribute and __has_include.
>
>
>
> So that's my suggestion: #ifdef/#ifndef/defined should treat `__VA_OPT__`
> as if it were the name of a defined macro.
>
>
>
> Thoughts?
>
> Richard
>
>



SG10 list run by sg10-owner@lists.isocpp.org