Debian Codegraph @

gcc/testsuite/gcc.dg/param-type-mismatch-2.c

raw
1 /* { dg-options "-fdiagnostics-show-caret -Wpointer-sign" } */
2
3 /* A collection of calls where argument 2 is of the wrong type.
4 Like param-type-mismatch.c, but expecting errors. */
5
6 /* decl, with argname. */
7
8 extern int callee_1 (int one, const char *two, float three); /* { dg-line callee_1 } */
9
10 int test_1 (int first, int second, float third)
11 {
12 return callee_1 (first, second, third); /* { dg-error "passing argument 2 of 'callee_1' makes pointer from integer without a cast" } */
13 /* { dg-begin-multiline-output "" }
14 return callee_1 (first, second, third);
15 ^~~~~~
16 |
17 int
18 { dg-end-multiline-output "" } */
19 /* { dg-message "expected 'const char \\*' but argument is of type 'int'" "" { target *-*-* } callee_1 } */
20 /* { dg-begin-multiline-output "" }
21 extern int callee_1 (int one, const char *two, float three);
22 ~~~~~~~~~~~~^~~
23 { dg-end-multiline-output "" } */
24 }
25
26 /* decl, without argname. */
27
28 extern int callee_2 (int, const char *, float); /* { dg-line callee_2 } */
29
30 int test_2 (int first, int second, float third)
31 {
32 return callee_2 (first, second, third); /* { dg-error "passing argument 2 of 'callee_2' makes pointer from integer without a cast" } */
33 /* { dg-begin-multiline-output "" }
34 return callee_2 (first, second, third);
35 ^~~~~~
36 |
37 int
38 { dg-end-multiline-output "" } */
39 /* { dg-message "expected 'const char \\*' but argument is of type 'int'" "" { target *-*-* } callee_2 } */
40 /* { dg-begin-multiline-output "" }
41 extern int callee_2 (int, const char *, float);
42 ^~~~~~~~~~~~
43 { dg-end-multiline-output "" } */
44 }
45
46 /* defn, with argname. */
47
48 static int callee_3 (int one, const char *two, float three) /* { dg-line callee_3 } */
49 {
50 return callee_2 (one, two, three);
51 }
52
53 int test_3 (int first, int second, float third)
54 {
55 return callee_3 (first, second, third); // { dg-error "passing argument 2 of 'callee_3' makes pointer from integer without a cast" }
56 /* { dg-begin-multiline-output "" }
57 return callee_3 (first, second, third);
58 ^~~~~~
59 |
60 int
61 { dg-end-multiline-output "" } */
62 /* { dg-message "expected 'const char \\*' but argument is of type 'int'" "" { target *-*-* } callee_3 } */
63 /* { dg-begin-multiline-output "" }
64 static int callee_3 (int one, const char *two, float three)
65 ~~~~~~~~~~~~^~~
66 { dg-end-multiline-output "" } */
67 }
68
69 /* Trivial decl, with argname. */
70
71 extern int callee_4 (int one, float two, float three); /* { dg-line callee_4 } */
72
73 int test_4 (int first, const char *second, float third)
74 {
75 return callee_4 (first, second, third); /* { dg-error "incompatible type for argument 2 of 'callee_4'" } */
76 /* { dg-begin-multiline-output "" }
77 return callee_4 (first, second, third);
78 ^~~~~~
79 |
80 const char *
81 { dg-end-multiline-output "" } */
82 /* { dg-message "expected 'float' but argument is of type 'const char \\*'" "" { target *-*-* } callee_4 } */
83 /* { dg-begin-multiline-output "" }
84 extern int callee_4 (int one, float two, float three);
85 ~~~~~~^~~
86 { dg-end-multiline-output "" } */
87 }
88
89 /* Trivial decl, without argname. */
90
91 extern int callee_5 (int, float, float); /* { dg-line callee_5 } */
92
93 int test_5 (int first, const char *second, float third)
94 {
95 return callee_5 (first, second, third); /* { dg-error "incompatible type for argument 2 of 'callee_5'" } */
96 /* { dg-begin-multiline-output "" }
97 return callee_5 (first, second, third);
98 ^~~~~~
99 |
100 const char *
101 { dg-end-multiline-output "" } */
102 /* { dg-message "expected 'float' but argument is of type 'const char \\*'" "" { target *-*-* } callee_5 } */
103 /* { dg-begin-multiline-output "" }
104 extern int callee_5 (int, float, float);
105 ^~~~~
106 { dg-end-multiline-output "" } */
107 }
108
109 /* Callback with name. */
110
111 extern int callee_6 (int one, int (*two)(int, int), float three); /* { dg-line callee_6 } */
112
113 int test_6 (int first, int second, float third)
114 {
115 return callee_6 (first, second, third); /* { dg-error "passing argument 2 of 'callee_6' makes pointer from integer without a cast" } */
116 /* { dg-begin-multiline-output "" }
117 return callee_6 (first, second, third);
118 ^~~~~~
119 |
120 int
121 { dg-end-multiline-output "" } */
122 /* { dg-message " expected 'int \\(\\*\\)\\(int, int\\)' but argument is of type 'int'" "" { target *-*-* } callee_6 } */
123 /* { dg-begin-multiline-output "" }
124 extern int callee_6 (int one, int (*two)(int, int), float three);
125 ~~~~~~^~~~~~~~~~~~~~
126 { dg-end-multiline-output "" } */
127 }
128
129 /* Callback without name. */
130
131 extern int callee_7 (int one, int (*)(int, int), float three); /* { dg-line callee_7 } */
132
133 int test_7 (int first, int second, float third)
134 {
135 return callee_7 (first, second, third); /* { dg-error "passing argument 2 of 'callee_7' makes pointer from integer without a cast" } */
136 /* { dg-begin-multiline-output "" }
137 return callee_7 (first, second, third);
138 ^~~~~~
139 |
140 int
141 { dg-end-multiline-output "" } */
142 /* { dg-message " expected 'int \\(\\*\\)\\(int, int\\)' but argument is of type 'int'" "" { target *-*-* } callee_7 } */
143 /* { dg-begin-multiline-output "" }
144 extern int callee_7 (int one, int (*)(int, int), float three);
145 ^~~~~~~~~~~~~~~~~
146 { dg-end-multiline-output "" } */
147 }
148
149 /* -Wincompatible-pointer-types for a parameter. */
150
151 extern int callee_8 (int one, float *two, float (three)); /* { dg-line callee_8 } */
152
153 int test_8 (int first, int *second, float third)
154 {
155 return callee_8 (first, second, third); /* { dg-error "passing argument 2 of 'callee_8' from incompatible pointer type" } */
156 /* { dg-begin-multiline-output "" }
157 return callee_8 (first, second, third);
158 ^~~~~~
159 |
160 int *
161 { dg-end-multiline-output "" } */
162 /* { dg-message "expected 'float \\*' but argument is of type 'int \\*'" "" { target *-*-* } callee_8 } */
163 /* { dg-begin-multiline-output "" }
164 extern int callee_8 (int one, float *two, float (three));
165 ~~~~~~~^~~
166 { dg-end-multiline-output "" } */
167 }
168
169 /* -Wpointer-sign for a parameter. */
170
171 extern int callee_9 (int one, int *two, float (three)); /* { dg-line callee_9 } */
172
173 int test_9 (int first, unsigned int *second, float third)
174 {
175 return callee_9 (first, second, third); /* { dg-warning "pointer targets in passing argument 2 of 'callee_9' differ in signedness" } */
176 /* { dg-begin-multiline-output "" }
177 return callee_9 (first, second, third);
178 ^~~~~~
179 |
180 unsigned int *
181 { dg-end-multiline-output "" } */
182 /* { dg-message "expected 'int \\*' but argument is of type 'unsigned int \\*'" "" { target *-*-* } callee_9 } */
183 /* { dg-begin-multiline-output "" }
184 extern int callee_9 (int one, int *two, float (three));
185 ~~~~~^~~
186 { dg-end-multiline-output "" } */
187 }