[Issue 20653] Short-circuiting boolean logic not working

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Mar 10 20:31:15 UTC 2020


https://issues.dlang.org/show_bug.cgi?id=20653

Dennis <dkorpel at live.nl> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dkorpel at live.nl

--- Comment #3 from Dennis <dkorpel at live.nl> ---
(In reply to Ketmar Dark from comment #1)
> it never worked with static ifs. i was pretty sure that it was By Design,
> but i cannot remember if i really read that somewhere in the specs, or
> simply made it out.

Short circuiting actually works in certain static conditions:

```
static if (false && bogusName) {}
static assert(true || bogusName);
void foo(T)() if (true ? true : bogusName) {};
alias x = foo!int;
```

This is implemented in staticcond.d, function `evalStaticCondition`:

> Semantically analyze and then evaluate a static condition at compile time.
> This is special because short circuit operators &&, || and ?: at the top
> level are not semantically analyzed if the result of the expression is not
> necessary.

That function is not used to evaluate enums however.

--


More information about the Digitalmars-d-bugs mailing list