C++ Logo

std-proposals

Advanced search

Re: [std-proposals] condexpr: new syntax for preprocessor conditional inclusion

From: Peter Olsson <dataapa_at_[hidden]>
Date: Thu, 15 Dec 2022 14:41:51 +0100
> > > condexpr if (ABCD)
> >
> > Is this equivalent to `#ifdef ABCD` or `#if ABCD` ?
> >
> #ifdef ABCD is equivalent to #if define ABCD. My current proposal
> technically means to include both. I would consider all of these
> acceptable:
> condexpr if (ABCD) // replacement syntax for #ifdef ABCD or #if define
> ABCD
> condexpr if (ABCD == 2) // replacement syntax for #if ABCD == 2 (an
> expression, rather than just an identifier)
> and the combination of both checks via:
> condexpr if (ABCD && ABCD == 2) // equivalent to #ifdef ABCD ; #if ABCD == 2
>
> A 2nd possible syntax could replace the `condexpr if (ABCD)`, with
> `condexpr if (defined ABCD)` // slightly more verbose but closer to the
> current `#if defined ABCD` syntax.
> Similarly, `condexpr if (ABCD && ABCD == 2)` could be replaced with
> `condexpr if (defined ABCD && ABCD == 2)` to further highlight the
> difference in the parameters between identifier checks and expressions
> without requiring an implicit identifier check as the first version would.

I think the first syntax is problematic because an identifier could be
a valid expression.

Received on 2022-12-15 13:42:03