xref: /netbsd-src/tests/usr.bin/xlint/lint1/msg_218.c (revision d16b7486a53dcb8072b60ec6fcb4373a2d0c27b7)
1 /*	$NetBSD: msg_218.c,v 1.8 2023/07/08 11:03:00 rillig Exp $	*/
2 # 3 "msg_218.c"
3 
4 /* Test for message: ANSI C treats constant as unsigned, op '%s' [218] */
5 
6 /* lint1-only-if: ilp32 */
7 /* lint1-flags: -w -X 351 */
8 
9 int cond;
10 signed int s32;
11 unsigned int u32;
12 /* expect+1: warning: C90 does not support 'long long' [265] */
13 signed long long s64;
14 /* expect+1: warning: C90 does not support 'long long' [265] */
15 unsigned long long u64;
16 
17 void sink_int(int);
18 
19 /* All platforms supported by lint have 32-bit int in two's complement. */
20 void
21 test_signed_int(void)
22 {
23 	/* expect+2: warning: ANSI C treats constant as unsigned, op '-' [218] */
24 	/* expect+1: warning: conversion of 'unsigned long' to 'int' is out of range, arg #1 [295] */
25 	sink_int(-2147483648);
26 }
27 
28 /*
29  * In traditional C, integer constants with an 'L' suffix that didn't fit
30  * into 'long' were promoted to the next larger integer type, if that existed
31  * at all, as the suffix 'LL' was introduced by C90.
32  *
33  * Starting with C90, integer constants with an 'L' suffix that didn't fit
34  * into 'long' were promoted to 'unsigned long' first, before trying 'long
35  * long'.
36  *
37  * In C99 mode, this distinction is no longer necessary since it is far
38  * enough from traditional C.
39  */
40 void
41 compare_large_constant(void)
42 {
43 	/* expect+1: warning: ANSI C treats constant as unsigned, op '<' [218] */
44 	cond = s32 < 3000000000L;
45 	/* expect+1: warning: ANSI C treats constant as unsigned, op '<' [218] */
46 	cond = 3000000000L < s32;
47 	/* expect+1: warning: ANSI C treats constant as unsigned, op '<' [218] */
48 	cond = u32 < 3000000000L;
49 	/* expect+1: warning: ANSI C treats constant as unsigned, op '<' [218] */
50 	cond = 3000000000L < u32;
51 	/* expect+1: warning: ANSI C treats constant as unsigned, op '<' [218] */
52 	cond = s64 < 3000000000L;
53 	/* expect+1: warning: ANSI C treats constant as unsigned, op '<' [218] */
54 	cond = 3000000000L < s64;
55 	/* expect+1: warning: ANSI C treats constant as unsigned, op '<' [218] */
56 	cond = u64 < 3000000000L;
57 	/* expect+1: warning: ANSI C treats constant as unsigned, op '<' [218] */
58 	cond = 3000000000L < u64;
59 }
60