Tue Mar 30 15:05:05 2021 UTC ()
tests/lint: remove outdated comments


(rillig)
diff -r1.24 -r1.25 src/tests/usr.bin/xlint/lint1/d_c99_init.c
diff -r1.17 -r1.18 src/tests/usr.bin/xlint/lint1/d_c99_init.exp
diff -r1.7 -r1.8 src/tests/usr.bin/xlint/lint1/msg_247.c

cvs diff -r1.24 -r1.25 src/tests/usr.bin/xlint/lint1/d_c99_init.c (switch to unified diff)

--- src/tests/usr.bin/xlint/lint1/d_c99_init.c 2021/03/30 14:25:28 1.24
+++ src/tests/usr.bin/xlint/lint1/d_c99_init.c 2021/03/30 15:05:05 1.25
@@ -1,384 +1,380 @@ @@ -1,384 +1,380 @@
1/* $NetBSD: d_c99_init.c,v 1.24 2021/03/30 14:25:28 rillig Exp $ */ 1/* $NetBSD: d_c99_init.c,v 1.25 2021/03/30 15:05:05 rillig Exp $ */
2# 3 "d_c99_init.c" 2# 3 "d_c99_init.c"
3 3
4/* 4/*
5 * Test C99 initializers. 5 * Test C99 initializers.
6 * 6 *
7 * See C99 6.7.8 "Initialization". 7 * See C99 6.7.8 "Initialization".
8*/ 8*/
9 9
10 10
11void use(const void *); 11void use(const void *);
12 12
13typedef struct any { 13typedef struct any {
14 const void *value; 14 const void *value;
15} any; 15} any;
16 16
17 17
18// C99 6.7.8p11 says "optionally enclosed in braces". There is no limitation 18// C99 6.7.8p11 says "optionally enclosed in braces". There is no limitation
19// on the number of brace pairs. 19// on the number of brace pairs.
20int scalar_without_braces = 3; 20int scalar_without_braces = 3;
21int scalar_with_optional_braces = { 3 }; 21int scalar_with_optional_braces = { 3 };
22int scalar_with_too_many_braces = {{ 3 }}; 22int scalar_with_too_many_braces = {{ 3 }};
23int scalar_with_too_many_initializers = { 3, 5 }; /* expect: 174 */ 23int scalar_with_too_many_initializers = { 3, 5 }; /* expect: 174 */
24 24
25 25
26// See init_expr, 'handing over to ASSIGN'. 26// See init_expr, 'handing over to ASSIGN'.
27void 27void
28struct_initialization_via_assignment(any arg) 28struct_initialization_via_assignment(any arg)
29{ 29{
30 any local = arg; 30 any local = arg;
31 use(&local); 31 use(&local);
32} 32}
33 33
34 34
35// See init_expr, initialization_init_array_using_string. 35// See init_expr, initialization_init_array_using_string.
36char static_duration[] = "static duration"; 36char static_duration[] = "static duration";
37signed char static_duration_signed[] = "static duration"; 37signed char static_duration_signed[] = "static duration";
38unsigned char static_duration_unsigned[] = "static duration"; 38unsigned char static_duration_unsigned[] = "static duration";
39int static_duration_wchar[] = L"static duration"; 39int static_duration_wchar[] = L"static duration";
40 40
41// See init_expr. 41// See init_expr.
42void 42void
43initialization_by_braced_string(void) 43initialization_by_braced_string(void)
44{ 44{
45 any local = { "hello" }; 45 any local = { "hello" };
46 use(&local); 46 use(&local);
47} 47}
48 48
49void 49void
50initialization_by_redundantly_braced_string(void) 50initialization_by_redundantly_braced_string(void)
51{ 51{
52 any local = {{{{ "hello" }}}}; 52 any local = {{{{ "hello" }}}};
53 use(&local); 53 use(&local);
54} 54}
55 55
56/* 56/*
57 * Only scalar expressions and string literals may be enclosed by additional 57 * Only scalar expressions and string literals may be enclosed by additional
58 * braces. Since 'arg' is a struct, this is a compile-time error. 58 * braces. Since 'arg' is a struct, this is a compile-time error.
59 */ 59 */
60void 60void
61initialization_with_too_many_braces(any arg) 61initialization_with_too_many_braces(any arg)
62{ 62{
63 any local = { arg }; /* expect: 185 */ 63 any local = { arg }; /* expect: 185 */
64 use(&arg); 64 use(&arg);
65} 65}
66 66
67// Some of the following examples are mentioned in the introduction comment 67// Some of the following examples are mentioned in the introduction comment
68// in init.c. 68// in init.c.
69 69
70int number = 12345; 70int number = 12345;
71 71
72int number_with_braces_and_comma = { 72int number_with_braces_and_comma = {
73 12345, 73 12345,
74}; 74};
75 75
76int array_with_fixed_size[3] = { 76int array_with_fixed_size[3] = {
77 111, 77 111,
78 222, 78 222,
79 333, 79 333,
80 444, /* expect: too many array initializers */ 80 444, /* expect: too many array initializers */
81}; 81};
82 82
83// See initialization_set_set_of_unknown_array. 83// See initialization_set_set_of_unknown_array.
84int array_of_unknown_size[] = { 84int array_of_unknown_size[] = {
85 111, 85 111,
86 222, 86 222,
87 333, 87 333,
88}; 88};
89 89
90int array_flat[2][2] = { 90int array_flat[2][2] = {
91 11, 91 11,
92 12, 92 12,
93 21, 93 21,
94 22 94 22
95}; 95};
96 96
97int array_nested[2][2] = { 97int array_nested[2][2] = {
98 { 98 {
99 11, 99 11,
100 12 100 12
101 }, 101 },
102 { 102 {
103 21, 103 21,
104 22 104 22
105 } 105 }
106}; 106};
107 107
108int array_with_designators[] = { 108int array_with_designators[] = {
109 ['1'] = 111, 109 ['1'] = 111,
110 ['5'] = 555, 110 ['5'] = 555,
111 ['9'] = 999 111 ['9'] = 999
112}; 112};
113 113
114int array_with_some_designators[] = { 114int array_with_some_designators[] = {
115 ['1'] = 111, 115 ['1'] = 111,
116 222, 116 222,
117 ['9'] = 999 117 ['9'] = 999
118}; 118};
119 119
120struct point { 120struct point {
121 int x; 121 int x;
122 int y; 122 int y;
123}; 123};
124 124
125struct point point = { 125struct point point = {
126 3, 126 3,
127 4 127 4
128}; 128};
129 129
130struct point point_with_designators = { 130struct point point_with_designators = {
131 .y = 4, 131 .y = 4,
132 .x = 3, 132 .x = 3,
133}; 133};
134 134
135struct point point_with_mixed_designators = { 135struct point point_with_mixed_designators = {
136 .x = 3, 136 .x = 3,
137 4, 137 4,
138 /* TODO: remove me */ 138 /* TODO: remove me */
139 5, /* expect: too many struct/union initializers */ 139 5, /* expect: too many struct/union initializers */
140 .x = 3, 140 .x = 3,
141}; 141};
142 142
143int array_with_designator[] = { 143int array_with_designator[] = {
144 111, 144 111,
145 .member = 222, /* expect: 249 */ 145 .member = 222, /* expect: 249 */
146 333, 146 333,
147}; 147};
148 148
149/* 149/*
150 * C99 6.7.8p11 says that the initializer of a scalar can be "optionally 150 * C99 6.7.8p11 says that the initializer of a scalar can be "optionally
151 * enclosed in braces". It does not explicitly set an upper limit on the 151 * enclosed in braces". It does not explicitly set an upper limit on the
152 * number of braces. It also doesn't restrict the term "initializer" to only 152 * number of braces. It also doesn't restrict the term "initializer" to only
153 * mean the "outermost initializer". Both GCC 10 and Clang 8 already warn 153 * mean the "outermost initializer". Both GCC 10 and Clang 8 already warn
154 * about this, so there is no extra work for lint to do. 154 * about this, so there is no extra work for lint to do.
155 */ 155 */
156struct point scalar_with_several_braces = { 156struct point scalar_with_several_braces = {
157 {{{3}}}, 157 {{{3}}},
158 {{{{4}}}}, 158 {{{{4}}}},
159}; 159};
160 160
161struct rectangle { 161struct rectangle {
162 struct point top_left; 162 struct point top_left;
163 struct point bottom_right; 163 struct point bottom_right;
164}; 164};
165 165
166/* C99 6.7.8p18 */ 166/* C99 6.7.8p18 */
167struct rectangle screen = { 167struct rectangle screen = {
168 .bottom_right = { 168 .bottom_right = {
169 1920, 169 1920,
170 1080, 170 1080,
171 } 171 }
172}; 172};
173 173
174/* 174/*
175 * C99 6.7.8p22 says: At the _end_ of its initializer list, the array no 175 * C99 6.7.8p22 says: At the _end_ of its initializer list, the array no
176 * longer has incomplete type. 176 * longer has incomplete type.
177 */ 177 */
178struct point points[] = { 178struct point points[] = {
179 { 179 {
180 /* 180 /*
181 * At this point, the size of the object 'points' is not known 181 * At this point, the size of the object 'points' is not known
182 * yet since its type is still incomplete. Lint could warn 182 * yet since its type is still incomplete. Lint could warn
183 * about this, but GCC and Clang already do. 183 * about this, but GCC and Clang already do.
184 * 184 *
185 * This test case demonstrates that in 185 * This test case demonstrates that in
186 * extend_if_array_of_unknown_size, setcomplete is called too 186 * extend_if_array_of_unknown_size, setcomplete is called too
187 * early. 187 * early.
188 */ 188 */
189 sizeof points, 189 sizeof points,
190 4 190 4
191 } 191 }
192}; 192};
193 193
194 194
195struct triangle { 195struct triangle {
196 struct point points[3]; 196 struct point points[3];
197}; 197};
198 198
199struct pentagon { 199struct pentagon {
200 struct point points[5]; 200 struct point points[5];
201}; 201};
202 202
203struct geometry { 203struct geometry {
204 struct pentagon pentagons[6]; 204 struct pentagon pentagons[6];
205 struct triangle triangles[10]; 205 struct triangle triangles[10];
206 struct point points[3][5][2]; 206 struct point points[3][5][2];
207}; 207};
208 208
209/* 209/*
210 * Initialization of a complex struct containing nested arrays and nested 210 * Initialization of a complex struct containing nested arrays and nested
211 * structs. 211 * structs.
212 */ 212 */
213struct geometry geometry = { 213struct geometry geometry = {
214 /* TODO: remove me */ 214 /* TODO: remove me */
215 .pentagons[0].points[4].x = 1, 215 .pentagons[0].points[4].x = 1,
216 .points[0][0][0] = { 0, 0 }, 216 .points[0][0][0] = { 0, 0 },
217 .points[2][4][1] = {301, 302 }, 217 .points[2][4][1] = {301, 302 },
218 /* TODO: expect+1: array index 3 must be between 0 and 2 */ 218 /* TODO: expect+1: array index 3 must be between 0 and 2 */
219 .points[3][0][0] = {3001, 3002 }, 219 .points[3][0][0] = {3001, 3002 },
220 /* TODO: expect+1: array index 5 must be between 0 and 4 */ 220 /* TODO: expect+1: array index 5 must be between 0 and 4 */
221 .points[0][5][0] = {501, 502 }, 221 .points[0][5][0] = {501, 502 },
222 /* TODO: expect+1: array index 2 must be between 0 and 1 */ 222 /* TODO: expect+1: array index 2 must be between 0 and 1 */
223 .points[0][0][2] = {21, 22 }, 223 .points[0][0][2] = {21, 22 },
224}; 224};
225 225
226struct ends_with_unnamed_bit_field { 226struct ends_with_unnamed_bit_field {
227 int member; 227 int member;
228 int : 0; 228 int : 0;
229} ends_with_unnamed_bit_field = { 229} ends_with_unnamed_bit_field = {
230 12345, 230 12345,
231 /* expect+1: too many struct/union initializers */ 231 /* expect+1: too many struct/union initializers */
232 23456, 232 23456,
233}; 233};
234 234
235char prefixed_message[] = { 235char prefixed_message[] = {
236 'E', ':', ' ', 236 'E', ':', ' ',
237 /* expect+1: illegal combination of integer (char) and pointer */ 237 /* expect+1: illegal combination of integer (char) and pointer */
238 "message\n", 238 "message\n",
239}; 239};
240 240
241char message_with_suffix[] = { 241char message_with_suffix[] = {
242 "message", /* expect: illegal combination */ 242 "message", /* expect: illegal combination */
243 /* */ 243 /* */
244 '\n', 244 '\n',
245}; 245};
246 246
247struct ten { 247struct ten {
248 int i0; 248 int i0;
249 int i1; 249 int i1;
250 int i2; 250 int i2;
251 int i3; 251 int i3;
252 int i4; 252 int i4;
253 int i5; 253 int i5;
254 int i6; 254 int i6;
255 int i7; 255 int i7;
256 int i8; 256 int i8;
257 int i9; 257 int i9;
258}; 258};
259 259
260struct ten ten = { 260struct ten ten = {
261 .i3 = 3, 261 .i3 = 3,
262 4, 262 4,
263 // FIXME: assertion "level->bl_type->t_tspec == ARRAY" failed in brace_level_extend_if_array_of_unknown_size 263 5,
264 // 5, 264 6,
265 // 6, 
266}; 265};
267 266
268int c99_6_7_8_p26_example3[4][3] = { 267int c99_6_7_8_p26_example3[4][3] = {
269 { 1, 3, 5 }, 268 { 1, 3, 5 },
270 { 2, 4, 6 }, 269 { 2, 4, 6 },
271 { 3, 5, 7 }, 270 { 3, 5, 7 },
272}; 271};
273 272
274int c99_6_7_8_p27_example4[4][3] = { 273int c99_6_7_8_p27_example4[4][3] = {
275 { 1 }, { 2 }, { 3 }, { 4 } 274 { 1 }, { 2 }, { 3 }, { 4 }
276}; 275};
277 276
278struct { 277struct {
279 int a[3], b; 278 int a[3], b;
280} c99_6_7_8_p28_example5[] = { 279} c99_6_7_8_p28_example5[] = {
281 { 1 }, 280 { 1 },
282 2, /* XXX *//* expect: cannot initialize */ 281 2, /* XXX *//* expect: cannot initialize */
283}; 282};
284 283
285short c99_6_7_8_p29_example6a[4][3][2] = { 284short c99_6_7_8_p29_example6a[4][3][2] = {
286 { 1 }, 285 { 1 },
287 { 2, 3 }, 286 { 2, 3 },
288 { 4, 5, 6 }, 287 { 4, 5, 6 },
289}; 288};
290 289
291short c99_6_7_8_p29_example6b[4][3][2] = { 290short c99_6_7_8_p29_example6b[4][3][2] = {
292 1, 0, 0, 0, 0, 0, 291 1, 0, 0, 0, 0, 0,
293 2, 3, 0, 0, 0, 0, 292 2, 3, 0, 0, 0, 0,
294 4, 5, 6, 0, 0, 0, 293 4, 5, 6, 0, 0, 0,
295}; 294};
296 295
297short c99_6_7_8_p29_example6c[4][3][2] = { 296short c99_6_7_8_p29_example6c[4][3][2] = {
298 { 297 {
299 { 1 }, 298 { 1 },
300 }, 299 },
301 { 300 {
302 { 2, 3 }, 301 { 2, 3 },
303 }, 302 },
304 { 303 {
305 { 4, 5 }, 304 { 4, 5 },
306 { 6 }, 305 { 6 },
307 } 306 }
308}; 307};
309 308
310/* 309/*
311 * During initialization of an object of type array of unknown size, the type 310 * During initialization of an object of type array of unknown size, the type
312 * information on the symbol is updated in-place. Ensure that this happens on 311 * information on the symbol is updated in-place. Ensure that this happens on
313 * a copy of the type. 312 * a copy of the type.
314 */ 313 */
315void 314void
316ensure_array_type_is_not_modified_during_initialization(void) 315ensure_array_type_is_not_modified_during_initialization(void)
317{ 316{
318 typedef int array_of_unknown_size[]; 317 typedef int array_of_unknown_size[];
319 318
320 array_of_unknown_size a1 = { 1, 2, 3}; 319 array_of_unknown_size a1 = { 1, 2, 3};
321 320
322 switch (4) { 321 switch (4) {
323 case sizeof(array_of_unknown_size): 322 case sizeof(array_of_unknown_size):
324 case 0: /* expect: duplicate case in switch: 0 */ 323 case 0: /* expect: duplicate case in switch: 0 */
325 case 3: 324 case 3:
326 case 4: 325 case 4:
327 case 12: 326 case 12:
328 break; 327 break;
329 } 328 }
330} 329}
331 330
332struct point unknown_member_name_beginning = { 331struct point unknown_member_name_beginning = {
333 /* TODO: remove me */ 
334 .r = 5, /* expect: undefined struct/union member: r */ 332 .r = 5, /* expect: undefined struct/union member: r */
335 .x = 4, 333 .x = 4,
336 .y = 3, 334 .y = 3,
337}; 335};
338 336
339struct point unknown_member_name_middle = { 337struct point unknown_member_name_middle = {
340 .x = 4, 338 .x = 4,
341 .r = 5, /* expect: undefined struct/union member: r */ 339 .r = 5, /* expect: undefined struct/union member: r */
342 .y = 3, 340 .y = 3,
343}; 341};
344 342
345struct point unknown_member_name_end = { 343struct point unknown_member_name_end = {
346 .x = 4, 344 .x = 4,
347 .y = 3, 345 .y = 3,
348 .r = 5, /* expect: undefined struct/union member: r */ 346 .r = 5, /* expect: undefined struct/union member: r */
349}; 347};
350 348
351union value { 349union value {
352 int int_value; 350 int int_value;
353 void *pointer_value; 351 void *pointer_value;
354}; 352};
355 353
356union value unknown_union_member_name_first = { 354union value unknown_union_member_name_first = {
357 /* TODO: remove me */ 
358 .unknown_value = 4, /* expect: undefined struct/union member */ 355 .unknown_value = 4, /* expect: undefined struct/union member */
359 .int_value = 3, 356 .int_value = 3,
360}; 357};
361 358
362union value unknown_union_member_name_second = { 359union value unknown_union_member_name_second = {
363 .int_value = 3, 360 .int_value = 3,
364 /* TODO: remove me */ 
365 .unknown_value = 4, /* expect: undefined struct/union member */ 361 .unknown_value = 4, /* expect: undefined struct/union member */
366}; 362};
367 363
368struct point designators_with_subscript = { 364struct point designators_with_subscript = {
369 [0] = 3, /* expect: only for arrays */ 365 [0] = 3, /* expect: only for arrays */
370 .member[0][0].member = 4, /* expect: undefined struct/union member */ 366 .member[0][0].member = 4, /* expect: undefined struct/union member */
371 .x.y.z = 5, /* intentionally not caught, see designator_look_up */ 367 .x.y.z = 5, /* intentionally not caught, see designator_look_up */
372}; 368};
373 369
374struct { 370struct {
375 int : 16; 371 int : 16;
376} struct_with_only_unnamed_members = { /* expect: has no named members */ 372} struct_with_only_unnamed_members = { /* expect: has no named members */
377 123, /* expect: too many struct/union initializers */ 373 123, /* expect: too many struct/union initializers */
378}; 374};
379 375
380union { 376union {
381 int : 16; 377 int : 16;
382} union_with_only_unnamed_members = { /* expect: has no named members */ 378} union_with_only_unnamed_members = { /* expect: has no named members */
383 123, /* expect: too many struct/union initializers */ 379 123, /* expect: too many struct/union initializers */
384}; 380};

cvs diff -r1.17 -r1.18 src/tests/usr.bin/xlint/lint1/Attic/d_c99_init.exp (switch to unified diff)

--- src/tests/usr.bin/xlint/lint1/Attic/d_c99_init.exp 2021/03/30 14:25:28 1.17
+++ src/tests/usr.bin/xlint/lint1/Attic/d_c99_init.exp 2021/03/30 15:05:05 1.18
@@ -1,21 +1,21 @@ @@ -1,21 +1,21 @@
1d_c99_init.c(23): error: too many initializers [174] 1d_c99_init.c(23): error: too many initializers [174]
2d_c99_init.c(63): error: cannot initialize 'pointer to const void' from 'struct any' [185] 2d_c99_init.c(63): error: cannot initialize 'pointer to const void' from 'struct any' [185]
3d_c99_init.c(80): error: too many array initializers, expected 3 [173] 3d_c99_init.c(80): error: too many array initializers, expected 3 [173]
4d_c99_init.c(139): error: too many struct/union initializers [172] 4d_c99_init.c(139): error: too many struct/union initializers [172]
5d_c99_init.c(145): error: syntax error 'named member must only be used with struct/union' [249] 5d_c99_init.c(145): error: syntax error 'named member must only be used with struct/union' [249]
6d_c99_init.c(232): error: too many struct/union initializers [172] 6d_c99_init.c(232): error: too many struct/union initializers [172]
7d_c99_init.c(238): warning: illegal combination of integer (char) and pointer (pointer to char) [183] 7d_c99_init.c(238): warning: illegal combination of integer (char) and pointer (pointer to char) [183]
8d_c99_init.c(242): warning: illegal combination of integer (char) and pointer (pointer to char) [183] 8d_c99_init.c(242): warning: illegal combination of integer (char) and pointer (pointer to char) [183]
9d_c99_init.c(282): error: cannot initialize 'struct <unnamed>' from 'int' [185] 9d_c99_init.c(281): error: cannot initialize 'struct <unnamed>' from 'int' [185]
10d_c99_init.c(324): error: duplicate case in switch: 0 [199] 10d_c99_init.c(323): error: duplicate case in switch: 0 [199]
11d_c99_init.c(334): error: undefined struct/union member: r [101] 11d_c99_init.c(332): error: undefined struct/union member: r [101]
12d_c99_init.c(341): error: undefined struct/union member: r [101] 12d_c99_init.c(339): error: undefined struct/union member: r [101]
13d_c99_init.c(348): error: undefined struct/union member: r [101] 13d_c99_init.c(346): error: undefined struct/union member: r [101]
14d_c99_init.c(358): error: undefined struct/union member: unknown_value [101] 14d_c99_init.c(355): error: undefined struct/union member: unknown_value [101]
15d_c99_init.c(365): error: undefined struct/union member: unknown_value [101] 15d_c99_init.c(361): error: undefined struct/union member: unknown_value [101]
16d_c99_init.c(369): error: syntax error 'designator '[...]' is only for arrays' [249] 16d_c99_init.c(365): error: syntax error 'designator '[...]' is only for arrays' [249]
17d_c99_init.c(370): error: undefined struct/union member: member [101] 17d_c99_init.c(366): error: undefined struct/union member: member [101]
18d_c99_init.c(376): warning: structure has no named members [65] 18d_c99_init.c(372): warning: structure has no named members [65]
19d_c99_init.c(377): error: too many struct/union initializers [172] 19d_c99_init.c(373): error: too many struct/union initializers [172]
20d_c99_init.c(382): warning: union has no named members [65] 20d_c99_init.c(378): warning: union has no named members [65]
21d_c99_init.c(383): error: too many struct/union initializers [172] 21d_c99_init.c(379): error: too many struct/union initializers [172]

cvs diff -r1.7 -r1.8 src/tests/usr.bin/xlint/lint1/msg_247.c (switch to unified diff)

--- src/tests/usr.bin/xlint/lint1/msg_247.c 2021/03/26 16:59:19 1.7
+++ src/tests/usr.bin/xlint/lint1/msg_247.c 2021/03/30 15:05:05 1.8
@@ -1,77 +1,77 @@ @@ -1,77 +1,77 @@
1/* $NetBSD: msg_247.c,v 1.7 2021/03/26 16:59:19 rillig Exp $ */ 1/* $NetBSD: msg_247.c,v 1.8 2021/03/30 15:05:05 rillig Exp $ */
2# 3 "msg_247.c" 2# 3 "msg_247.c"
3 3
4// Test for message: pointer cast from '%s' to '%s' may be troublesome [247] 4// Test for message: pointer cast from '%s' to '%s' may be troublesome [247]
5 5
6/* lint1-extra-flags: -c */ 6/* lint1-extra-flags: -c */
7 7
8/* example taken from Xlib.h */ 8/* example taken from Xlib.h */
9typedef struct { 9typedef struct {
10 int id; 10 int id;
11} *PDisplay; 11} *PDisplay;
12 12
13struct Other { 13struct Other {
14 int id; 14 int id;
15}; 15};
16 16
17void 17void
18example(struct Other *arg) 18example(struct Other *arg)
19{ 19{
20 PDisplay display; 20 PDisplay display;
21 21
22 /* 22 /*
23 * XXX: The target type is reported as 'struct <unnamed>'. In cases 23 * XXX: The target type is reported as 'struct <unnamed>'. In cases
24 * like these, it would be helpful to print at least the type name 24 * like these, it would be helpful to print at least the type name
25 * of the pointer. This type name though is discarded immediately 25 * of the pointer. This type name though is discarded immediately
26 * when the parser reduces 'T_TYPENAME clrtyp' to 'clrtyp_typespec'. 26 * when the parser reduces 'T_TYPENAME clrtyp' to 'clrtyp_typespec'.
27 * After that, the target type of the cast is just an unnamed struct, 27 * After that, the target type of the cast is just an unnamed struct,
28 * with no hint at all that there is a typedef for a pointer to the 28 * with no hint at all that there is a typedef for a pointer to the
29 * struct. 29 * struct.
30 */ 30 */
31 display = (PDisplay)arg; /* expect: 247 */ 31 display = (PDisplay)arg; /* expect: 247 */
32} 32}
33 33
34/* 34/*
35 * C code with a long history that has existed in pre-C90 times already often 35 * C code with a long history that has existed in pre-C90 times already often
36 * uses 'pointer to char' where modern code would use 'pointer to void'. 36 * uses 'pointer to char' where modern code would use 'pointer to void'.
37 * Since 'char' is the most general underlying type, there is nothing wrong 37 * Since 'char' is the most general underlying type, there is nothing wrong
38 * with casting to it. An example for this type of code is X11. 38 * with casting to it. An example for this type of code is X11.
39 * 39 *
40 * Casting to 'pointer to char' may also be used by programmers who don't know 40 * Casting to 'pointer to char' may also be used by programmers who don't know
41 * about endianness, but that's not something lint can do anything about. The 41 * about endianness, but that's not something lint can do anything about. The
42 * code for these two use cases looks exactly the same, so lint errs on the 42 * code for these two use cases looks exactly the same, so lint errs on the
43 * side of fewer false positive warnings here. (after fixing the FIXME below) 43 * side of fewer false positive warnings here.
44 */ 44 */
45char * 45char *
46cast_to_char_pointer(struct Other *arg) 46cast_to_char_pointer(struct Other *arg)
47{ 47{
48 return (char *)arg; 48 return (char *)arg;
49} 49}
50 50
51/* 51/*
52 * In traditional C there was 'unsigned char' as well, so the same reasoning 52 * In traditional C there was 'unsigned char' as well, so the same reasoning
53 * as for plain 'char' applies here. 53 * as for plain 'char' applies here.
54 */ 54 */
55unsigned char * 55unsigned char *
56cast_to_unsigned_char_pointer(struct Other *arg) 56cast_to_unsigned_char_pointer(struct Other *arg)
57{ 57{
58 return (unsigned char *)arg; 58 return (unsigned char *)arg;
59} 59}
60 60
61/* 61/*
62 * Traditional C does not have the type specifier 'signed', which means that 62 * Traditional C does not have the type specifier 'signed', which means that
63 * this type cannot be used by old code. Therefore warn about this. All code 63 * this type cannot be used by old code. Therefore warn about this. All code
64 * that triggers this warning should do the intermediate cast via 'void 64 * that triggers this warning should do the intermediate cast via 'void
65 * pointer'. 65 * pointer'.
66 */ 66 */
67signed char * 67signed char *
68cast_to_signed_char_pointer(struct Other *arg) 68cast_to_signed_char_pointer(struct Other *arg)
69{ 69{
70 return (signed char *)arg; /* expect: 247 */ 70 return (signed char *)arg; /* expect: 247 */
71} 71}
72 72
73char * 73char *
74cast_to_void_pointer_then_to_char_pointer(struct Other *arg) 74cast_to_void_pointer_then_to_char_pointer(struct Other *arg)
75{ 75{
76 return (char *)(void *)arg; 76 return (char *)(void *)arg;
77} 77}