lazy evaluation of logical operators in enum definition

Walter Bright newshound2 at digitalmars.com
Wed Apr 18 07:18:44 UTC 2018


On 4/15/2018 10:57 PM, Shachar Shemesh wrote:
> It seems that the && evaluation does not stop when the first false is found.


Evaluation does stop, semantic analysis does not. For example:

   bool foo() {
     return 0 && undefined_variable;
   }

does not compile. I'd speculate that most would consider this code compiling 
successfully as surprising behavior. It would also be difficult to specify, as 
just when is e1 of (e1 && e2) statically known at compile time (i.e. how much 
flow analysis is the compiler expected to do to determine this?).


More information about the Digitalmars-d mailing list