static if AssignExpression

rikki cattermole rikki at cattermole.co.nz
Wed Feb 13 17:42:37 UTC 2019


On 14/02/2019 6:33 AM, H. S. Teoh wrote:
> 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.

Ugh...

https://github.com/dlang/dmd/blob/master/src/dmd/parse.d#L2407



More information about the Digitalmars-d mailing list