240-parse-const-shortcircuit.c (516B)
1 /* Constant-expression && / || must short-circuit (C11 §6.6 ¶3 and 2 * §6.5.13/14): the unevaluated subexpression need not be a valid 3 * constant expression. The parser's constant-expression evaluator 4 * was eagerly evaluating both sides, so `1 || (1/0)` aborted with 5 * "const-expr: divide by zero" instead of returning 1. 6 */ 7 8 enum { ANY_TRUE = 1 || (1/0) }; 9 enum { ANY_FALSE = 0 && (1/0) }; 10 11 int main(int argc, char **argv) { 12 if (ANY_TRUE != 1) return 1; 13 if (ANY_FALSE != 0) return 2; 14 return 0; 15 }