Home | History | Annotate | Line # | Download | only in lint1
      1  1.8  rillig /*	$NetBSD: msg_222.c,v 1.8 2024/12/15 07:43:53 rillig Exp $	*/
      2  1.1  rillig # 3 "msg_222.c"
      3  1.1  rillig 
      4  1.6  rillig // Test for message: conversion of negative constant %lld to unsigned type '%s' [222]
      5  1.8  rillig //
      6  1.8  rillig // See also:
      7  1.8  rillig //	msg_162.c: comparison of unsigned type with negative constant
      8  1.8  rillig //	msg_164.c: assignment of negative constant to unsigned type
      9  1.8  rillig //	msg_221.c: initialization of unsigned type with negative constant
     10  1.8  rillig //	msg_296.c: conversion of negative constant to unsigned type in call
     11  1.1  rillig 
     12  1.5  rillig /* lint1-extra-flags: -X 351 */
     13  1.5  rillig 
     14  1.8  rillig unsigned int u32;
     15  1.8  rillig signed char sc;
     16  1.8  rillig unsigned char uc;
     17  1.8  rillig _Bool b;
     18  1.3  rillig 
     19  1.3  rillig 
     20  1.3  rillig void
     21  1.8  rillig convert_negative_constant(void)
     22  1.3  rillig {
     23  1.8  rillig 	u32 = !-8;
     24  1.8  rillig 	u32 = ~-8;
     25  1.8  rillig 	/* expect+1: warning: assignment of negative constant -8 to unsigned type 'unsigned int' [164] */
     26  1.8  rillig 	u32 = +-8;
     27  1.8  rillig 	u32 = - -8;
     28  1.8  rillig 
     29  1.8  rillig 	/* expect+1: warning: conversion of negative constant -8 to unsigned type 'unsigned int' [222] */
     30  1.8  rillig 	u32 = u32 * -8;
     31  1.8  rillig 	/* expect+1: warning: conversion of negative constant -8 to unsigned type 'unsigned int' [222] */
     32  1.8  rillig 	u32 = -8 * u32;
     33  1.8  rillig 	/* expect+1: warning: conversion of negative constant -8 to unsigned type 'unsigned int' [222] */
     34  1.8  rillig 	u32 = u32 / -8;
     35  1.8  rillig 	/* expect+1: warning: conversion of negative constant -8 to unsigned type 'unsigned int' [222] */
     36  1.8  rillig 	u32 = -8 / u32;
     37  1.8  rillig 	/* expect+1: warning: conversion of negative constant -8 to unsigned type 'unsigned int' [222] */
     38  1.8  rillig 	u32 = u32 % -8;
     39  1.8  rillig 	/* expect+1: warning: conversion of negative constant -8 to unsigned type 'unsigned int' [222] */
     40  1.8  rillig 	u32 = -8 / u32;
     41  1.8  rillig 	/* expect+1: warning: conversion of negative constant -8 to unsigned type 'unsigned int' [222] */
     42  1.8  rillig 	u32 = u32 + -8;
     43  1.8  rillig 	/* expect+1: warning: conversion of negative constant -8 to unsigned type 'unsigned int' [222] */
     44  1.8  rillig 	u32 = -8 + u32;
     45  1.8  rillig 	/* expect+1: warning: conversion of negative constant -8 to unsigned type 'unsigned int' [222] */
     46  1.8  rillig 	u32 = u32 - -8;
     47  1.8  rillig 	/* expect+1: warning: conversion of negative constant -8 to unsigned type 'unsigned int' [222] */
     48  1.8  rillig 	u32 = -8 - u32;
     49  1.8  rillig 	/* expect+1: warning: negative shift [121] */
     50  1.8  rillig 	u32 = u32 << -8;
     51  1.8  rillig 	u32 = -8 << u32;
     52  1.8  rillig 	/* expect+1: warning: negative shift [121] */
     53  1.8  rillig 	u32 = u32 >> -8;
     54  1.8  rillig 	u32 = -8 >> u32;
     55  1.3  rillig 
     56  1.4  rillig 	/* expect+1: warning: operator '<' compares 'unsigned int' with 'negative constant' [162] */
     57  1.8  rillig 	b = u32 < -8;
     58  1.8  rillig 	/* expect+1: warning: operator '<=' compares 'unsigned int' with 'negative constant' [162] */
     59  1.8  rillig 	b = u32 <= -8;
     60  1.8  rillig 	/* expect+1: warning: operator '>' compares 'unsigned int' with 'negative constant' [162] */
     61  1.8  rillig 	b = u32 > -8;
     62  1.8  rillig 	/* expect+1: warning: operator '>=' compares 'unsigned int' with 'negative constant' [162] */
     63  1.8  rillig 	b = u32 >= -8;
     64  1.8  rillig 	/* expect+1: warning: operator '==' compares 'unsigned int' with 'negative constant' [162] */
     65  1.8  rillig 	b = u32 == -8;
     66  1.8  rillig 	/* expect+1: warning: operator '!=' compares 'unsigned int' with 'negative constant' [162] */
     67  1.8  rillig 	b = u32 != -8;
     68  1.8  rillig 
     69  1.8  rillig 	u32 = u32 & -8;
     70  1.8  rillig 	u32 = u32 ^ -8;
     71  1.8  rillig 	u32 = u32 | -8;
     72  1.8  rillig 	b = u32 && -8;
     73  1.8  rillig 	b = u32 || -8;
     74  1.8  rillig 
     75  1.8  rillig 	/* expect+1: warning: assignment of negative constant -8 to unsigned type 'unsigned int' [164] */
     76  1.8  rillig 	u32 = -8;
     77  1.8  rillig 	/* expect+1: warning: conversion of negative constant -8 to unsigned type 'unsigned int' [222] */
     78  1.8  rillig 	u32 *= -8;
     79  1.8  rillig 	/* expect+1: warning: conversion of negative constant -8 to unsigned type 'unsigned int' [222] */
     80  1.8  rillig 	u32 /= -8;
     81  1.8  rillig 	/* expect+1: warning: conversion of negative constant -8 to unsigned type 'unsigned int' [222] */
     82  1.8  rillig 	u32 %= -8;
     83  1.8  rillig 	/* expect+1: warning: conversion of negative constant -8 to unsigned type 'unsigned int' [222] */
     84  1.8  rillig 	u32 += -8;
     85  1.8  rillig 	/* expect+1: warning: conversion of negative constant -8 to unsigned type 'unsigned int' [222] */
     86  1.8  rillig 	u32 -= -8;
     87  1.8  rillig 	// XXX: missing 'negative shift' warning
     88  1.8  rillig 	u32 <<= -8;
     89  1.8  rillig 	// XXX: missing 'negative shift' warning
     90  1.8  rillig 	u32 >>= -8;
     91  1.8  rillig 	u32 &= -8;
     92  1.8  rillig 	/* expect+1: warning: conversion of negative constant -8 to unsigned type 'unsigned int' [222] */
     93  1.8  rillig 	u32 ^= -8;
     94  1.8  rillig 	u32 |= -8;
     95  1.7  rillig 
     96  1.8  rillig 	sc += 'A' - 'a';
     97  1.8  rillig 	sc -= 'A' - 'a';
     98  1.7  rillig 
     99  1.7  rillig 	// XXX: It's perfectly fine to effectively subtract a constant from
    100  1.7  rillig 	// XXX: an unsigned type.
    101  1.7  rillig 	/* expect+1: warning: conversion of negative constant -32 to unsigned type 'unsigned char' [222] */
    102  1.8  rillig 	uc += 'A' - 'a';
    103  1.7  rillig 	/* expect+1: warning: conversion of negative constant -32 to unsigned type 'unsigned char' [222] */
    104  1.8  rillig 	uc -= 'A' - 'a';
    105  1.3  rillig }
    106