msg_341.c revision 1.2 1 /* $NetBSD: msg_341.c,v 1.2 2022/06/17 18:54:53 rillig Exp $ */
2 # 3 "msg_341.c"
3
4 // Test for message: argument to '%s' must be 'unsigned char' or EOF, not '%s' [341]
5
6 /*
7 * Ensure that the functions from <ctype.h> are called with the correct
8 * argument.
9 */
10
11 /* NetBSD 9.99.81, <ctype.h> */
12 extern const unsigned short *_ctype_tab_;
13 extern const short *_tolower_tab_;
14 extern const short *_toupper_tab_;
15 int isspace(int);
16
17 void sink(int);
18
19 void
20 function_call_char(char c)
21 {
22
23 /* expect+1: warning: argument to 'isspace' must be 'unsigned char' or EOF, not 'char' [341] */
24 (isspace)(c);
25
26 /* This is the only allowed form. */
27 isspace((unsigned char)c);
28
29 /* The cast to 'int' is redundant, it doesn't hurt though. */
30 isspace((int)(unsigned char)c);
31
32 /* expect+1: warning: argument to 'isspace' must be cast to 'unsigned char', not to 'int' [342] */
33 isspace((int)c);
34
35 /* expect+1: warning: argument to 'isspace' must be cast to 'unsigned char', not to 'unsigned int' [342] */
36 isspace((unsigned int)c);
37 }
38
39 /*
40 * If the expression starts with type 'unsigned char', it can be cast to any
41 * other type. Chances are low enough that the cast is to 'char', which would
42 * be the only bad type.
43 */
44 void
45 function_call_unsigned_char(unsigned char c)
46 {
47
48 (isspace)(c);
49 isspace((unsigned char)c);
50 isspace((int)c);
51 isspace((unsigned int)c);
52 }
53
54 /* When used in a loop of fgetc, the type is already 'int'. That's fine. */
55 void
56 function_call_int(int c)
57 {
58
59 isspace(c);
60 }
61
62 void
63 macro_invocation_NetBSD(char c)
64 {
65
66 /* expect+1: warning: argument to 'function from <ctype.h>' must be 'unsigned char' or EOF, not 'char' [341] */
67 sink(((int)((_ctype_tab_ + 1)[(c)] & 0x0040)));
68
69 /* This is the only allowed form. */
70 sink(((int)((_ctype_tab_ + 1)[((unsigned char)c)] & 0x0040)));
71
72 /* expect+1: warning: argument to 'function from <ctype.h>' must be cast to 'unsigned char', not to 'int' [342] */
73 sink(((int)((_ctype_tab_ + 1)[((int)c)] & 0x0040)));
74
75 /* expect+1: warning: argument to 'function from <ctype.h>' must be cast to 'unsigned char', not to 'unsigned int' [342] */
76 sink(((int)((_ctype_tab_ + 1)[((unsigned int)c)] & 0x0040)));
77 }
78