Home | History | Annotate | Line # | Download | only in lint1
msg_162.c revision 1.5
      1  1.5  rillig /*	$NetBSD: msg_162.c,v 1.5 2021/09/05 16:47:24 rillig Exp $	*/
      2  1.1  rillig # 3 "msg_162.c"
      3  1.1  rillig 
      4  1.1  rillig // Test for message: comparison of %s with %s, op %s [162]
      5  1.1  rillig 
      6  1.3  rillig /* lint1-extra-flags: -hp */
      7  1.3  rillig 
      8  1.3  rillig void
      9  1.3  rillig left_unsigned(unsigned int ui)
     10  1.3  rillig {
     11  1.3  rillig 	if (ui < -5.0) {
     12  1.3  rillig 	}
     13  1.3  rillig 
     14  1.3  rillig 	/* expect+1: warning: comparison of unsigned int with negative constant, op < [162] */
     15  1.3  rillig 	if (ui < -5) {
     16  1.3  rillig 	}
     17  1.3  rillig 
     18  1.3  rillig 	/* expect+1: warning: comparison of unsigned int with 0, op < [162] */
     19  1.3  rillig 	if (ui < 0) {
     20  1.3  rillig 	}
     21  1.3  rillig 
     22  1.3  rillig 	/* expect+1: warning: comparison of unsigned int with 0, op >= [162] */
     23  1.3  rillig 	if (ui >= 0) {
     24  1.3  rillig 	}
     25  1.3  rillig 
     26  1.3  rillig 	/* expect+1: warning: comparison of unsigned int with 0, op <= [162] */
     27  1.3  rillig 	if (ui <= 0) {
     28  1.3  rillig 	}
     29  1.3  rillig }
     30  1.3  rillig 
     31  1.3  rillig void
     32  1.3  rillig right_unsigned(unsigned int ui)
     33  1.3  rillig {
     34  1.3  rillig 
     35  1.3  rillig 	if (-5.0 > ui) {
     36  1.3  rillig 	}
     37  1.3  rillig 
     38  1.3  rillig 	/* expect+1: warning: comparison of negative constant with unsigned int, op > [162] */
     39  1.3  rillig 	if (-5 > ui) {
     40  1.3  rillig 	}
     41  1.3  rillig 
     42  1.3  rillig 	/* expect+1: warning: comparison of 0 with unsigned int, op > [162] */
     43  1.3  rillig 	if (0 > ui) {
     44  1.3  rillig 	}
     45  1.3  rillig 
     46  1.3  rillig 	/* expect+1: warning: comparison of 0 with unsigned int, op <= [162] */
     47  1.3  rillig 	if (0 <= ui) {
     48  1.3  rillig 	}
     49  1.3  rillig 
     50  1.3  rillig 	/* expect+1: warning: comparison of 0 with unsigned int, op >= [162] */
     51  1.3  rillig 	if (0 >= ui) {
     52  1.3  rillig 	}
     53  1.3  rillig }
     54  1.4  rillig 
     55  1.4  rillig /*
     56  1.4  rillig  * Lint does not care about these comparisons, even though they are obviously
     57  1.4  rillig  * out of range.
     58  1.4  rillig  */
     59  1.4  rillig void
     60  1.4  rillig compare_signed_char(signed char sc)
     61  1.4  rillig {
     62  1.4  rillig 	if (sc == -129)
     63  1.4  rillig 		return;
     64  1.4  rillig 	if (sc == -128)
     65  1.4  rillig 		return;
     66  1.4  rillig 	if (sc == 127)
     67  1.4  rillig 		return;
     68  1.4  rillig 	if (sc == 128)
     69  1.4  rillig 		return;
     70  1.4  rillig }
     71  1.4  rillig 
     72  1.4  rillig void
     73  1.4  rillig compare_unsigned_char(unsigned char uc)
     74  1.4  rillig {
     75  1.4  rillig 	/* expect+1: warning: comparison of unsigned char with negative constant, op == [162] */
     76  1.4  rillig 	if (uc == -1)
     77  1.4  rillig 		return;
     78  1.4  rillig 	if (uc == 0)
     79  1.4  rillig 		return;
     80  1.4  rillig 	if (uc == 255)
     81  1.4  rillig 		return;
     82  1.4  rillig 	if (uc == 256)
     83  1.4  rillig 		return;
     84  1.4  rillig }
     85  1.5  rillig 
     86  1.5  rillig void take_bool(_Bool);
     87  1.5  rillig 
     88  1.5  rillig void
     89  1.5  rillig compare_operators(unsigned int x)
     90  1.5  rillig {
     91  1.5  rillig 	/* expect+1: warning: comparison of unsigned int with negative constant, op < [162] */
     92  1.5  rillig 	take_bool(x < -1);
     93  1.5  rillig 	/* expect+1: warning: comparison of unsigned int with 0, op < [162] */
     94  1.5  rillig 	take_bool(x < 0);
     95  1.5  rillig 	take_bool(x < 1);
     96  1.5  rillig 
     97  1.5  rillig 	/* expect+1: warning: comparison of unsigned int with negative constant, op <= [162] */
     98  1.5  rillig 	take_bool(x <= -1);
     99  1.5  rillig 	/*
    100  1.5  rillig 	 * XXX: The expression 'x <= 0' is equivalent to 'x < 1', so lint
    101  1.5  rillig 	 * should not warn about it, just as it doesn't warn about the
    102  1.5  rillig 	 * inverted condition, which is 'x > 0'.
    103  1.5  rillig 	 */
    104  1.5  rillig 	/* expect+1: warning: comparison of unsigned int with 0, op <= [162] */
    105  1.5  rillig 	take_bool(x <= 0);
    106  1.5  rillig 	take_bool(x <= 1);
    107  1.5  rillig 
    108  1.5  rillig 	/* expect+1: warning: comparison of unsigned int with negative constant, op > [162] */
    109  1.5  rillig 	take_bool(x > -1);
    110  1.5  rillig 	take_bool(x > 0);
    111  1.5  rillig 	take_bool(x > 1);
    112  1.5  rillig 
    113  1.5  rillig 	/* expect+1: warning: comparison of unsigned int with negative constant, op >= [162] */
    114  1.5  rillig 	take_bool(x >= -1);
    115  1.5  rillig 	/* expect+1: warning: comparison of unsigned int with 0, op >= [162] */
    116  1.5  rillig 	take_bool(x >= 0);
    117  1.5  rillig 	take_bool(x >= 1);
    118  1.5  rillig 
    119  1.5  rillig 	/* expect+1: warning: comparison of unsigned int with negative constant, op == [162] */
    120  1.5  rillig 	take_bool(x == -1);
    121  1.5  rillig 	take_bool(x == 0);
    122  1.5  rillig 	take_bool(x == 1);
    123  1.5  rillig 
    124  1.5  rillig 	/* expect+1: warning: comparison of unsigned int with negative constant, op != [162] */
    125  1.5  rillig 	take_bool(x != -1);
    126  1.5  rillig 	take_bool(x != 0);
    127  1.5  rillig 	take_bool(x != 1);
    128  1.5  rillig }
    129