static if AssignExpression

H. S. Teoh hsteoh at quickfur.ath.cx
Wed Feb 13 17:33:44 UTC 2019


On Wed, Feb 13, 2019 at 04:45:39PM +0000, Luís Marques via Digitalmars-d wrote:
> `static if` is defined in the D grammar as `static if (
> AssignExpression )`.  What's the point of AssignExpression, instead of
> just a ConditionalExpression?  In what situation can you even use
> `static if(x = y)?`, `static if(x += y)?`, etc?

It's either an oversight, or was probably chosen just for consistency
with the normal `if` condition (to make it simpler to implement in the
compiler since we could just use the same code for parsing the
condition).

Though, in an extreme case, one could potentially have a user-defined
that overloads += to return bool at compile-time.  Probably an example
of operator overload abuse, though.


T

-- 
I don't trust computers, I've spent too long programming to think that they can get anything right. -- James Miller


More information about the Digitalmars-d mailing list