Home | History | Annotate | Line # | Download | only in lint1
d_c99_bool.c revision 1.1
      1 /*	$NetBSD: d_c99_bool.c,v 1.1 2021/01/10 11:24:42 rillig Exp $	*/
      2 # 3 "d_bool.c"
      3 
      4 /*
      5  * C99 6.3.1.2 says: "When any scalar value is converted to _Bool, the result
      6  * is 0 if the value compares equal to 0; otherwise the result is 1."
      7  *
      8  * This is different from the other integer types, which get truncated or
      9  * invoke undefined behavior.
     10  */
     11 
     12 /* Below, the wrong assertions produce warning 20. */
     13 
     14 int int_0_converts_to_false[(_Bool)0 ? -1 : 1];
     15 int int_0_converts_to_true_[(_Bool)0 ? 1 : -1];
     16 
     17 int int_1_converts_to_false[(_Bool)1 ? -1 : 1];
     18 int int_1_converts_to_true_[(_Bool)1 ? 1 : -1];
     19 
     20 int int_2_converts_to_false[(_Bool)2 ? -1 : 1];
     21 int int_2_converts_to_true_[(_Bool)2 ? 1 : -1];
     22 
     23 int int_256_converts_to_false[(_Bool)256 ? -1 : 1]; // FIXME
     24 int int_256_converts_to_true_[(_Bool)256 ? 1 : -1]; // FIXME
     25 
     26 int null_pointer_converts_to_false[(_Bool)(void *)0 ? -1 : 1];
     27 int null_pointer_converts_to_true_[(_Bool)(void *)0 ? 1 : -1];
     28 
     29 int nonnull_pointer_converts_to_false[(_Bool)"not null" ? -1 : 1]; // FIXME 133
     30 int nonnull_pointer_converts_to_true_[(_Bool)"not null" ? 1 : -1]; // FIXME 133
     31 
     32 int double_minus_1_0_converts_to_false[(_Bool)-1.0 ? -1 : 1]; // FIXME 119
     33 int double_minus_1_0_converts_to_true_[(_Bool)-1.0 ? 1 : -1]; // FIXME 20, 119
     34 
     35 int double_minus_0_5_converts_to_false[(_Bool)-0.5 ? -1 : 1]; // FIXME 119
     36 int double_minus_0_5_converts_to_true_[(_Bool)-0.5 ? 1 : -1]; // FIXME 20, 119
     37 
     38 int double_minus_0_0_converts_to_false[(_Bool)-0.0 ? -1 : 1];
     39 int double_minus_0_0_converts_to_true_[(_Bool)-0.0 ? 1 : -1];
     40 
     41 int double_0_0_converts_to_false[(_Bool)0.0 ? -1 : 1];
     42 int double_0_0_converts_to_true_[(_Bool)0.0 ? 1 : -1];
     43 
     44 /* The C99 rationale explains in 6.3.1.2 why (_Bool)0.5 is true. */
     45 int double_0_5_converts_to_false[(_Bool)0.5 ? -1 : 1]; // FIXME 20
     46 int double_0_5_converts_to_true_[(_Bool)0.5 ? 1 : -1]; // FIXME 20
     47 
     48 int double_1_0_converts_to_false[(_Bool)1.0 ? -1 : 1];
     49 int double_1_0_converts_to_true_[(_Bool)1.0 ? 1 : -1];
     50