290-parse-const-ternary-shortcircuit.c (515B)
1 /* Constant-expression ternary `?:` must evaluate only the chosen 2 * branch (C11 §6.6 ¶3 + §6.5.15/4): the unevaluated subexpression 3 * need not be a valid constant expression. parse-const-cond was 4 * eagerly evaluating both arms, so `1 ? 2 : 1/0` aborted with 5 * "const-expr: divide by zero" instead of returning 2. 6 */ 7 8 enum { TRUE_ARM = 1 ? 7 : 1/0 }; 9 enum { FALSE_ARM = 0 ? 1/0 : 11 }; 10 11 int main(int argc, char **argv) { 12 if (TRUE_ARM != 7) return 1; 13 if (FALSE_ARM != 11) return 2; 14 return 0; 15 }