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