Date: Tue, 6 May 2025 22:39:30 +0900
Hi Jens,
On Mar. 6 May 2025 at 02:42, Jens Maurer <jens.maurer_at_[hidden]> wrote:
> On 05/05/2025 18.24, Jāāā Gustedt via Liaison wrote:
(...)
> 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.)
I do not think that this works in C23. As far as I can see, when writing:
((void)1, 1);
the expression is not an integer constant expression, even with the
extra parentheses. At least, both GCC and clang complain about it.
Here are a few extra examples:
https://godbolt.org/z/YqM45MjPz
But at the end, my point it that if static_assert() yields an integer,
it can be used with both the comma operator and with other operator
(such as the +, c.f. prior works). So, yielding an integer does not
close any doors.
Yours sincerely,
Vincent Mailhol
On Mar. 6 May 2025 at 02:42, Jens Maurer <jens.maurer_at_[hidden]> wrote:
> On 05/05/2025 18.24, Jāāā Gustedt via Liaison wrote:
(...)
> 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.)
I do not think that this works in C23. As far as I can see, when writing:
((void)1, 1);
the expression is not an integer constant expression, even with the
extra parentheses. At least, both GCC and clang complain about it.
Here are a few extra examples:
https://godbolt.org/z/YqM45MjPz
But at the end, my point it that if static_assert() yields an integer,
it can be used with both the comma operator and with other operator
(such as the +, c.f. prior works). So, yielding an integer does not
close any doors.
Yours sincerely,
Vincent Mailhol
Received on 2025-05-06 13:39:45