xref: /netbsd-src/tests/usr.bin/xlint/lint1/msg_218.c (revision 7d62b00eb9ad855ffcd7da46b41e23feb5476fac)
1 /*	$NetBSD: msg_218.c,v 1.6 2023/02/19 12:00:15 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 
8 _Bool cond;
9 signed int s32;
10 unsigned int u32;
11 signed long long s64;
12 unsigned long long u64;
13 
14 void sink_int(int);
15 
16 /* All platforms supported by lint have 32-bit int in two's complement. */
17 void
18 test_signed_int(void)
19 {
20 	/* expect+1: warning: conversion of 'unsigned long' to 'int' is out of range, arg #1 [295] */
21 	sink_int(-2147483648);
22 }
23 
24 /*
25  * In traditional C, integer constants with an 'L' suffix that didn't fit
26  * into 'long' were promoted to the next larger integer type, if that existed
27  * at all, as the suffix 'LL' was introduced by C90.
28  *
29  * Starting with C90, integer constants with an 'L' suffix that didn't fit
30  * into 'long' were promoted to 'unsigned long' first, before trying 'long
31  * long'.
32  *
33  * In C99 mode, this distinction is no longer necessary since it is far
34  * enough from traditional C.
35  */
36 void
37 compare_large_constant(void)
38 {
39 	cond = s32 < 3000000000L;
40 	cond = 3000000000L < s32;
41 	cond = u32 < 3000000000L;
42 	cond = 3000000000L < u32;
43 	cond = s64 < 3000000000L;
44 	cond = 3000000000L < s64;
45 	cond = u64 < 3000000000L;
46 	cond = 3000000000L < u64;
47 }
48