msg_259_c90.c revision 1.2 1 1.2 rillig /* $NetBSD: msg_259_c90.c,v 1.2 2021/08/31 19:26:23 rillig Exp $ */
2 1.1 rillig # 3 "msg_259_c90.c"
3 1.1 rillig
4 1.1 rillig /* Test for message: argument #%d is converted from '%s' to '%s' due to prototype [259] */
5 1.1 rillig
6 1.2 rillig /*
7 1.2 rillig * See also msg_297, but that requires the flags -a -p -P, which are not
8 1.2 rillig * enabled in the default NetBSD build.
9 1.2 rillig */
10 1.2 rillig
11 1.1 rillig /* lint1-only-if: lp64 */
12 1.1 rillig /* XXX: The flag '-s' suppresses all warnings. Why? */
13 1.1 rillig /* lint1-flags: -h -w */
14 1.1 rillig
15 1.1 rillig void plain_char(char);
16 1.1 rillig void signed_int(int);
17 1.1 rillig void unsigned_int(unsigned int);
18 1.1 rillig void signed_long(long);
19 1.1 rillig void unsigned_long(unsigned long);
20 1.1 rillig /* No 'long long' since it requires C99. */
21 1.1 rillig
22 1.1 rillig void
23 1.1 rillig change_in_type_width(char c, int i, long l)
24 1.1 rillig {
25 1.1 rillig plain_char(c);
26 1.1 rillig signed_int(c);
27 1.1 rillig /* No warning 259 on LP64, only on ILP32 */
28 1.1 rillig signed_long(c);
29 1.1 rillig
30 1.1 rillig plain_char(i); /* XXX: why no warning? */
31 1.1 rillig signed_int(i);
32 1.1 rillig /* No warning 259 on LP64, only on ILP32 */
33 1.1 rillig signed_long(i);
34 1.1 rillig
35 1.1 rillig plain_char(l); /* XXX: why no warning? */
36 1.1 rillig /* expect+1: from 'long' to 'int' due to prototype [259] */
37 1.1 rillig signed_int(l);
38 1.1 rillig signed_long(l);
39 1.1 rillig }
40 1.1 rillig
41 1.1 rillig /*
42 1.1 rillig * Converting a signed integer type to its corresponding unsigned integer
43 1.1 rillig * type (C99 6.2.5p6) is usually not a problem since the actual values of the
44 1.1 rillig * expressions are usually not anywhere near the maximum signed value. From
45 1.1 rillig * a technical standpoint, it is correct to warn here since even small
46 1.1 rillig * negative numbers may result in very large positive numbers.
47 1.1 rillig *
48 1.1 rillig * A common case where it occurs is when the difference of two pointers is
49 1.1 rillig * converted to size_t. The type ptrdiff_t is defined to be signed, but in
50 1.1 rillig * many practical cases, the expression is '(end - start)', which makes the
51 1.1 rillig * resulting value necessarily positive.
52 1.1 rillig */
53 1.1 rillig void
54 1.1 rillig signed_to_unsigned(int si, long sl)
55 1.1 rillig {
56 1.1 rillig /* expect+1: warning: argument #1 is converted from 'int' to 'unsigned int' due to prototype [259] */
57 1.1 rillig unsigned_int(si);
58 1.1 rillig
59 1.1 rillig /* expect+1: warning: argument #1 is converted from 'long' to 'unsigned int' due to prototype [259] */
60 1.1 rillig unsigned_int(sl);
61 1.1 rillig
62 1.1 rillig /*
63 1.1 rillig * XXX: Why no warning? Even though 'unsigned long' is 64 bits
64 1.1 rillig * wide, it cannot represent negative 32-bit values.
65 1.1 rillig */
66 1.1 rillig unsigned_long(si);
67 1.1 rillig
68 1.1 rillig /* expect+1: warning: argument #1 is converted from 'long' to 'unsigned long' due to prototype [259] */
69 1.1 rillig unsigned_long(sl);
70 1.1 rillig }
71 1.1 rillig
72 1.1 rillig void
73 1.1 rillig unsigned_to_signed(unsigned int ui, unsigned long ul)
74 1.1 rillig {
75 1.1 rillig /* expect+1: warning: argument #1 is converted from 'unsigned int' to 'int' due to prototype [259] */
76 1.1 rillig signed_int(ui);
77 1.1 rillig /* expect+1: warning: argument #1 is converted from 'unsigned long' to 'int' due to prototype [259] */
78 1.1 rillig signed_int(ul);
79 1.1 rillig signed_long(ui);
80 1.1 rillig /* expect+1: warning: argument #1 is converted from 'unsigned long' to 'long' due to prototype [259] */
81 1.1 rillig signed_long(ul);
82 1.1 rillig }
83 1.1 rillig
84 1.1 rillig void
85 1.1 rillig signed_to_signed(signed int si, signed long sl)
86 1.1 rillig {
87 1.1 rillig signed_int(si);
88 1.1 rillig /* expect+1: warning: argument #1 is converted from 'long' to 'int' due to prototype [259] */
89 1.1 rillig signed_int(sl);
90 1.1 rillig signed_long(si);
91 1.1 rillig signed_long(sl);
92 1.1 rillig }
93 1.1 rillig
94 1.1 rillig void
95 1.1 rillig unsigned_to_unsigned(unsigned int ui, unsigned long ul)
96 1.1 rillig {
97 1.1 rillig unsigned_int(ui);
98 1.1 rillig /* expect+1: warning: argument #1 is converted from 'unsigned long' to 'unsigned int' due to prototype [259] */
99 1.1 rillig unsigned_int(ul);
100 1.1 rillig unsigned_long(ui);
101 1.1 rillig unsigned_long(ul);
102 1.1 rillig }
103 1.1 rillig
104 1.1 rillig void
105 1.1 rillig pass_sizeof_as_smaller_type(void)
106 1.1 rillig {
107 1.1 rillig /*
108 1.1 rillig * XXX: Even though the expression has type size_t, it has a constant
109 1.1 rillig * value that fits effortless into an 'unsigned int', it's so small
110 1.1 rillig * that it would even fit into a 3-bit bit-field, so lint should not
111 1.1 rillig * warn here.
112 1.1 rillig */
113 1.1 rillig /* expect+1: warning: argument #1 is converted from 'unsigned long' to 'unsigned int' due to prototype [259] */
114 1.1 rillig unsigned_int(sizeof(int));
115 1.1 rillig }
116