Date: Mon, 5 May 2025 19:42:57 +0200
On 05/05/2025 18.24, Jāāā Gustedt via Liaison wrote:
> Hi
>
> on Mon, 5 May 2025 14:02:47 +0000 you ("Herring, Davis via Liaison"
> <liaison_at_[hidden]>) wrote:
>
>>> The author would appreciate WG21 feedback. I encourage you to take
>>> a moment to read the paper and share your thoughts.
>>
>> void does not disqualify C++ expressions from being constants and
>> seems patently superior to using + to join an assertion to an
>> integer.
>
>> Can't C make "void(1), 1" be a constant expression too?
>
> Not so easily, as can't C++, I think, because "constant expression"
> is "conditional expression" with additional semantics.
Right, for the top-level syntax.
> And the later
> excludes the comma operator by definition.
Indeed, but
( (void)1, 1 )
does not cause problems with the syntax for conditional-expression.
But there is an extra rule in C23 6.6 paragraph 3:
"Constant expressions shall not contain assignment, increment, decrement, function-call, or comma
operators, except when they are contained within a subexpression that is not evaluated."
> What the historical reason
> for this would be, I don't know, and if would be easy to change I
> don't know either.
Having static_assert(x) be an expression of void type and then just writing
( static_assert(whatever), x )
seems like the most user-friendly syntax.
(If you're in a macro, you likely want some outer parentheses anyway.)
Jens
> Hi
>
> on Mon, 5 May 2025 14:02:47 +0000 you ("Herring, Davis via Liaison"
> <liaison_at_[hidden]>) wrote:
>
>>> The author would appreciate WG21 feedback. I encourage you to take
>>> a moment to read the paper and share your thoughts.
>>
>> void does not disqualify C++ expressions from being constants and
>> seems patently superior to using + to join an assertion to an
>> integer.
>
>> Can't C make "void(1), 1" be a constant expression too?
>
> Not so easily, as can't C++, I think, because "constant expression"
> is "conditional expression" with additional semantics.
Right, for the top-level syntax.
> And the later
> excludes the comma operator by definition.
Indeed, but
( (void)1, 1 )
does not cause problems with the syntax for conditional-expression.
But there is an extra rule in C23 6.6 paragraph 3:
"Constant expressions shall not contain assignment, increment, decrement, function-call, or comma
operators, except when they are contained within a subexpression that is not evaluated."
> What the historical reason
> for this would be, I don't know, and if would be easy to change I
> don't know either.
Having static_assert(x) be an expression of void type and then just writing
( static_assert(whatever), x )
seems like the most user-friendly syntax.
(If you're in a macro, you likely want some outer parentheses anyway.)
Jens
Received on 2025-05-05 17:43:04