Mercurial > hg > CbC > CbC_gcc
comparison gcc/testsuite/gcc.dg/format/diagnostic-ranges.c @ 131:84e7813d76e9
gcc-8.2
author | mir3636 |
---|---|
date | Thu, 25 Oct 2018 07:37:49 +0900 |
parents | 04ced10e8804 |
children |
comparison
equal
deleted
inserted
replaced
111:04ced10e8804 | 131:84e7813d76e9 |
---|---|
9 printf("hello %i", msg); /* { dg-warning "format '%i' expects argument of type 'int', but argument 2 has type 'const char \\*' " } */ | 9 printf("hello %i", msg); /* { dg-warning "format '%i' expects argument of type 'int', but argument 2 has type 'const char \\*' " } */ |
10 | 10 |
11 /* { dg-begin-multiline-output "" } | 11 /* { dg-begin-multiline-output "" } |
12 printf("hello %i", msg); | 12 printf("hello %i", msg); |
13 ~^ ~~~ | 13 ~^ ~~~ |
14 | | | |
15 int const char * | |
14 %s | 16 %s |
15 { dg-end-multiline-output "" } */ | 17 { dg-end-multiline-output "" } */ |
16 | 18 |
17 | 19 |
18 printf("hello %s", 42); /* { dg-warning "format '%s' expects argument of type 'char \\*', but argument 2 has type 'int'" } */ | 20 printf("hello %s", 42); /* { dg-warning "format '%s' expects argument of type 'char \\*', but argument 2 has type 'int'" } */ |
19 /* { dg-begin-multiline-output "" } | 21 /* { dg-begin-multiline-output "" } |
20 printf("hello %s", 42); | 22 printf("hello %s", 42); |
21 ~^ ~~ | 23 ~^ ~~ |
24 | | | |
25 | int | |
26 char * | |
22 %d | 27 %d |
23 { dg-end-multiline-output "" } */ | 28 { dg-end-multiline-output "" } */ |
24 | 29 |
25 printf("hello %i", (long)0); /* { dg-warning "format '%i' expects argument of type 'int', but argument 2 has type 'long int' " } */ | 30 printf("hello %i", (long)0); /* { dg-warning "format '%i' expects argument of type 'int', but argument 2 has type 'long int' " } */ |
26 /* { dg-begin-multiline-output "" } | 31 /* { dg-begin-multiline-output "" } |
27 printf("hello %i", (long)0); | 32 printf("hello %i", (long)0); |
28 ~^ ~~~~~~~ | 33 ~^ ~~~~~~~ |
34 | | | |
35 int long int | |
29 %li | 36 %li |
30 { dg-end-multiline-output "" } */ | 37 { dg-end-multiline-output "" } */ |
31 } | 38 } |
32 | 39 |
33 void test_multiple_arguments (void) | 40 void test_multiple_arguments (void) |
35 printf ("arg0: %i arg1: %s arg 2: %i", /* { dg-warning "29: format '%s'" } */ | 42 printf ("arg0: %i arg1: %s arg 2: %i", /* { dg-warning "29: format '%s'" } */ |
36 100, 101, 102); | 43 100, 101, 102); |
37 /* { dg-begin-multiline-output "" } | 44 /* { dg-begin-multiline-output "" } |
38 printf ("arg0: %i arg1: %s arg 2: %i", | 45 printf ("arg0: %i arg1: %s arg 2: %i", |
39 ~^ | 46 ~^ |
47 | | |
48 char * | |
40 %d | 49 %d |
41 100, 101, 102); | 50 100, 101, 102); |
42 ~~~ | 51 ~~~ |
52 | | |
53 int | |
43 { dg-end-multiline-output "" } */ | 54 { dg-end-multiline-output "" } */ |
44 } | 55 } |
45 | 56 |
46 void test_multiple_arguments_2 (int i, int j) | 57 void test_multiple_arguments_2 (int i, int j) |
47 { | 58 { |
48 printf ("arg0: %i arg1: %s arg 2: %i", /* { dg-warning "29: format '%s'" } */ | 59 printf ("arg0: %i arg1: %s arg 2: %i", /* { dg-warning "29: format '%s'" } */ |
49 100, i + j, 102); | 60 100, i + j, 102); |
50 /* { dg-begin-multiline-output "" } | 61 /* { dg-begin-multiline-output "" } |
51 printf ("arg0: %i arg1: %s arg 2: %i", | 62 printf ("arg0: %i arg1: %s arg 2: %i", |
52 ~^ | 63 ~^ |
64 | | |
65 char * | |
53 %d | 66 %d |
54 100, i + j, 102); | 67 100, i + j, 102); |
55 ~~~~~ | 68 ~~~~~ |
69 | | |
70 int | |
56 { dg-end-multiline-output "" } */ | 71 { dg-end-multiline-output "" } */ |
57 } | 72 } |
58 | 73 |
59 void multiline_format_string (void) { | 74 void multiline_format_string (void) { |
60 printf ("before the fmt specifier" /* { dg-warning "11: format '%d' expects a matching 'int' argument" } */ | 75 printf ("before the fmt specifier" /* { dg-warning "11: format '%d' expects a matching 'int' argument" } */ |
70 /* { dg-begin-multiline-output "" } | 85 /* { dg-begin-multiline-output "" } |
71 "%" | 86 "%" |
72 ~~ | 87 ~~ |
73 "d" | 88 "d" |
74 ~^ | 89 ~^ |
90 | | |
91 int | |
75 { dg-end-multiline-output "" } */ | 92 { dg-end-multiline-output "" } */ |
76 } | 93 } |
77 | 94 |
78 void test_hex (const char *msg) | 95 void test_hex (const char *msg) |
79 { | 96 { |
82 printf("hello \x25\x69", msg); /* { dg-warning "format '%i' expects argument of type 'int', but argument 2 has type 'const char \\*' " } */ | 99 printf("hello \x25\x69", msg); /* { dg-warning "format '%i' expects argument of type 'int', but argument 2 has type 'const char \\*' " } */ |
83 | 100 |
84 /* { dg-begin-multiline-output "" } | 101 /* { dg-begin-multiline-output "" } |
85 printf("hello \x25\x69", msg); | 102 printf("hello \x25\x69", msg); |
86 ~~~~^~~~ ~~~ | 103 ~~~~^~~~ ~~~ |
104 | | | |
105 int const char * | |
87 \x25s | 106 \x25s |
88 { dg-end-multiline-output "" } */ | 107 { dg-end-multiline-output "" } */ |
89 } | 108 } |
90 | 109 |
91 void test_oct (const char *msg) | 110 void test_oct (const char *msg) |
95 printf("hello \045\151", msg); /* { dg-warning "format '%i' expects argument of type 'int', but argument 2 has type 'const char \\*' " } */ | 114 printf("hello \045\151", msg); /* { dg-warning "format '%i' expects argument of type 'int', but argument 2 has type 'const char \\*' " } */ |
96 | 115 |
97 /* { dg-begin-multiline-output "" } | 116 /* { dg-begin-multiline-output "" } |
98 printf("hello \045\151", msg); | 117 printf("hello \045\151", msg); |
99 ~~~~^~~~ ~~~ | 118 ~~~~^~~~ ~~~ |
119 | | | |
120 int const char * | |
100 \045s | 121 \045s |
101 { dg-end-multiline-output "" } */ | 122 { dg-end-multiline-output "" } */ |
102 } | 123 } |
103 | 124 |
104 void test_multiple (const char *msg) | 125 void test_multiple (const char *msg) |
110 /* { dg-begin-multiline-output "" } | 131 /* { dg-begin-multiline-output "" } |
111 printf("prefix" "\x25" "\151" "suffix", | 132 printf("prefix" "\x25" "\151" "suffix", |
112 ^~~~~~~~ | 133 ^~~~~~~~ |
113 msg); | 134 msg); |
114 ~~~ | 135 ~~~ |
136 | | |
137 const char * | |
115 { dg-end-multiline-output "" } */ | 138 { dg-end-multiline-output "" } */ |
116 | 139 |
117 /* { dg-begin-multiline-output "" } | 140 /* { dg-begin-multiline-output "" } |
118 printf("prefix" "\x25" "\151" "suffix", | 141 printf("prefix" "\x25" "\151" "suffix", |
119 ~~~~~~~~^~~~ | 142 ~~~~~~~~^~~~ |
143 | | |
144 int | |
120 \x25" "s | 145 \x25" "s |
121 { dg-end-multiline-output "" } */ | 146 { dg-end-multiline-output "" } */ |
122 } | 147 } |
123 | 148 |
124 void test_u8 (const char *msg) | 149 void test_u8 (const char *msg) |
125 { | 150 { |
126 printf(u8"hello %i", msg);/* { dg-warning "format '%i' expects argument of type 'int', but argument 2 has type 'const char \\*' " } */ | 151 printf(u8"hello %i", msg);/* { dg-warning "format '%i' expects argument of type 'int', but argument 2 has type 'const char \\*' " } */ |
127 /* { dg-begin-multiline-output "" } | 152 /* { dg-begin-multiline-output "" } |
128 printf(u8"hello %i", msg); | 153 printf(u8"hello %i", msg); |
129 ~^ ~~~ | 154 ~^ ~~~ |
155 | | | |
156 int const char * | |
130 %s | 157 %s |
131 { dg-end-multiline-output "" } */ | 158 { dg-end-multiline-output "" } */ |
132 } | 159 } |
133 | 160 |
134 void test_param (long long_i, long long_j) | 161 void test_param (long long_i, long long_j) |
135 { | 162 { |
136 printf ("foo %s bar", long_i + long_j); /* { dg-warning "17: format '%s' expects argument of type 'char \\*', but argument 2 has type 'long int'" } */ | 163 printf ("foo %s bar", long_i + long_j); /* { dg-warning "17: format '%s' expects argument of type 'char \\*', but argument 2 has type 'long int'" } */ |
137 /* { dg-begin-multiline-output "" } | 164 /* { dg-begin-multiline-output "" } |
138 printf ("foo %s bar", long_i + long_j); | 165 printf ("foo %s bar", long_i + long_j); |
139 ~^ ~~~~~~~~~~~~~~~ | 166 ~^ ~~~~~~~~~~~~~~~ |
167 | | | |
168 char * long int | |
140 %ld | 169 %ld |
141 { dg-end-multiline-output "" } */ | 170 { dg-end-multiline-output "" } */ |
142 } | 171 } |
143 | 172 |
144 void test_field_width_specifier (long l, int i1, int i2) | 173 void test_field_width_specifier (long l, int i1, int i2) |
145 { | 174 { |
146 printf (" %*.*d ", l, i1, i2); /* { dg-warning "14: field width specifier '\\*' expects argument of type 'int', but argument 2 has type 'long int'" } */ | 175 printf (" %*.*d ", l, i1, i2); /* { dg-warning "14: field width specifier '\\*' expects argument of type 'int', but argument 2 has type 'long int'" } */ |
147 /* { dg-begin-multiline-output "" } | 176 /* { dg-begin-multiline-output "" } |
148 printf (" %*.*d ", l, i1, i2); | 177 printf (" %*.*d ", l, i1, i2); |
149 ~^~~~ ~ | 178 ~^~~~ ~ |
179 | | | |
180 int long int | |
150 { dg-end-multiline-output "" } */ | 181 { dg-end-multiline-output "" } */ |
151 } | 182 } |
152 | 183 |
153 /* PR c/72857. */ | 184 /* PR c/72857. */ |
154 | 185 |
156 { | 187 { |
157 __builtin_sprintf (d, " %*ld ", foo, foo); /* { dg-warning "28: field width specifier '\\*' expects argument of type 'int', but argument 3 has type 'long int'" } */ | 188 __builtin_sprintf (d, " %*ld ", foo, foo); /* { dg-warning "28: field width specifier '\\*' expects argument of type 'int', but argument 3 has type 'long int'" } */ |
158 /* { dg-begin-multiline-output "" } | 189 /* { dg-begin-multiline-output "" } |
159 __builtin_sprintf (d, " %*ld ", foo, foo); | 190 __builtin_sprintf (d, " %*ld ", foo, foo); |
160 ~^~~ ~~~ | 191 ~^~~ ~~~ |
192 | | | |
193 int long int | |
161 { dg-end-multiline-output "" } */ | 194 { dg-end-multiline-output "" } */ |
162 | 195 |
163 __builtin_sprintf (d, " %*ld ", foo + bar, foo); /* { dg-warning "28: field width specifier '\\*' expects argument of type 'int', but argument 3 has type 'long int'" } */ | 196 __builtin_sprintf (d, " %*ld ", foo + bar, foo); /* { dg-warning "28: field width specifier '\\*' expects argument of type 'int', but argument 3 has type 'long int'" } */ |
164 /* { dg-begin-multiline-output "" } | 197 /* { dg-begin-multiline-output "" } |
165 __builtin_sprintf (d, " %*ld ", foo + bar, foo); | 198 __builtin_sprintf (d, " %*ld ", foo + bar, foo); |
166 ~^~~ ~~~~~~~~~ | 199 ~^~~ ~~~~~~~~~ |
200 | | | |
201 int long int | |
167 { dg-end-multiline-output "" } */ | 202 { dg-end-multiline-output "" } */ |
168 } | 203 } |
169 | 204 |
170 void test_field_precision_specifier (char *d, long foo, long bar) | 205 void test_field_precision_specifier (char *d, long foo, long bar) |
171 { | 206 { |
172 __builtin_sprintf (d, " %.*ld ", foo, foo); /* { dg-warning "29: field precision specifier '\\.\\*' expects argument of type 'int', but argument 3 has type 'long int'" } */ | 207 __builtin_sprintf (d, " %.*ld ", foo, foo); /* { dg-warning "29: field precision specifier '\\.\\*' expects argument of type 'int', but argument 3 has type 'long int'" } */ |
173 /* { dg-begin-multiline-output "" } | 208 /* { dg-begin-multiline-output "" } |
174 __builtin_sprintf (d, " %.*ld ", foo, foo); | 209 __builtin_sprintf (d, " %.*ld ", foo, foo); |
175 ~~^~~ ~~~ | 210 ~~^~~ ~~~ |
211 | | | |
212 int long int | |
176 { dg-end-multiline-output "" } */ | 213 { dg-end-multiline-output "" } */ |
177 | 214 |
178 __builtin_sprintf (d, " %.*ld ", foo + bar, foo); /* { dg-warning "29: field precision specifier '\\.\\*' expects argument of type 'int', but argument 3 has type 'long int'" } */ | 215 __builtin_sprintf (d, " %.*ld ", foo + bar, foo); /* { dg-warning "29: field precision specifier '\\.\\*' expects argument of type 'int', but argument 3 has type 'long int'" } */ |
179 /* { dg-begin-multiline-output "" } | 216 /* { dg-begin-multiline-output "" } |
180 __builtin_sprintf (d, " %.*ld ", foo + bar, foo); | 217 __builtin_sprintf (d, " %.*ld ", foo + bar, foo); |
181 ~~^~~ ~~~~~~~~~ | 218 ~~^~~ ~~~~~~~~~ |
219 | | | |
220 int long int | |
182 { dg-end-multiline-output "" } */ | 221 { dg-end-multiline-output "" } */ |
183 } | 222 } |
184 | 223 |
185 void test_spurious_percent (void) | 224 void test_spurious_percent (void) |
186 { | 225 { |
239 #define INT_FMT "%i" /* { dg-message "19: format string is defined here" } */ | 278 #define INT_FMT "%i" /* { dg-message "19: format string is defined here" } */ |
240 printf("hello " INT_FMT " world", msg); /* { dg-warning "10: format '%i' expects argument of type 'int', but argument 2 has type 'const char \\*' " } */ | 279 printf("hello " INT_FMT " world", msg); /* { dg-warning "10: format '%i' expects argument of type 'int', but argument 2 has type 'const char \\*' " } */ |
241 /* { dg-begin-multiline-output "" } | 280 /* { dg-begin-multiline-output "" } |
242 printf("hello " INT_FMT " world", msg); | 281 printf("hello " INT_FMT " world", msg); |
243 ^~~~~~~~ ~~~ | 282 ^~~~~~~~ ~~~ |
283 | | |
284 const char * | |
244 { dg-end-multiline-output "" } */ | 285 { dg-end-multiline-output "" } */ |
245 /* { dg-begin-multiline-output "" } | 286 /* { dg-begin-multiline-output "" } |
246 #define INT_FMT "%i" | 287 #define INT_FMT "%i" |
247 ~^ | 288 ~^ |
289 | | |
290 int | |
248 %s | 291 %s |
249 { dg-end-multiline-output "" } */ | 292 { dg-end-multiline-output "" } */ |
250 #undef INT_FMT | 293 #undef INT_FMT |
251 } | 294 } |
252 | 295 |
255 #define PRIu32 "u" /* { dg-message "17: format string is defined here" } */ | 298 #define PRIu32 "u" /* { dg-message "17: format string is defined here" } */ |
256 printf("hello %" PRIu32 " world", msg); /* { dg-warning "10: format '%u' expects argument of type 'unsigned int', but argument 2 has type 'const char \\*' " } */ | 299 printf("hello %" PRIu32 " world", msg); /* { dg-warning "10: format '%u' expects argument of type 'unsigned int', but argument 2 has type 'const char \\*' " } */ |
257 /* { dg-begin-multiline-output "" } | 300 /* { dg-begin-multiline-output "" } |
258 printf("hello %" PRIu32 " world", msg); | 301 printf("hello %" PRIu32 " world", msg); |
259 ^~~~~~~~~ ~~~ | 302 ^~~~~~~~~ ~~~ |
303 | | |
304 const char * | |
260 { dg-end-multiline-output "" } */ | 305 { dg-end-multiline-output "" } */ |
261 /* { dg-begin-multiline-output "" } | 306 /* { dg-begin-multiline-output "" } |
262 #define PRIu32 "u" | 307 #define PRIu32 "u" |
263 ^ | 308 ^ |
309 | | |
310 unsigned int | |
264 { dg-end-multiline-output "" } */ | 311 { dg-end-multiline-output "" } */ |
265 #undef PRIu32 | 312 #undef PRIu32 |
266 } | 313 } |
267 | 314 |
268 void test_macro_3 (const char *msg) | 315 void test_macro_3 (const char *msg) |
269 { | 316 { |
270 #define FMT_STRING "hello %i world" /* { dg-warning "20: format '%i' expects argument of type 'int', but argument 2 has type 'const char \\*' " } */ | 317 #define FMT_STRING "hello %i world" /* { dg-line test_macro_3_macro_line } */ |
318 /* { dg-warning "20: format '%i' expects argument of type 'int', but argument 2 has type 'const char \\*'" "" { target *-*-*} .-1 } */ | |
271 printf(FMT_STRING, msg); /* { dg-message "10: in expansion of macro 'FMT_STRING" } */ | 319 printf(FMT_STRING, msg); /* { dg-message "10: in expansion of macro 'FMT_STRING" } */ |
272 /* { dg-begin-multiline-output "" } | 320 /* { dg-begin-multiline-output "" } |
273 #define FMT_STRING "hello %i world" | 321 #define FMT_STRING "hello %i world" |
274 ^~~~~~~~~~~~~~~~ | 322 ^~~~~~~~~~~~~~~~ |
275 { dg-end-multiline-output "" } */ | 323 { dg-end-multiline-output "" } */ |
276 /* { dg-begin-multiline-output "" } | 324 /* { dg-begin-multiline-output "" } |
277 printf(FMT_STRING, msg); | 325 printf(FMT_STRING, msg); |
278 ^~~~~~~~~~ | 326 ^~~~~~~~~~ |
279 { dg-end-multiline-output "" } */ | 327 { dg-end-multiline-output "" } */ |
328 /* { dg-message "28: format string is defined here" "" { target *-*-* } test_macro_3_macro_line } */ | |
329 /* { dg-begin-multiline-output "" } | |
330 #define FMT_STRING "hello %i world" | |
331 ~^ | |
332 | | |
333 int | |
334 %s | |
335 { dg-end-multiline-output "" } */ | |
280 #undef FMT_STRING | 336 #undef FMT_STRING |
281 } | 337 } |
282 | 338 |
283 void test_macro_4 (const char *msg) | 339 void test_macro_4 (const char *msg) |
284 { | 340 { |
293 ^~~~~~~~~~ | 349 ^~~~~~~~~~ |
294 { dg-end-multiline-output "" } */ | 350 { dg-end-multiline-output "" } */ |
295 /* { dg-begin-multiline-output "" } | 351 /* { dg-begin-multiline-output "" } |
296 #define FMT_STRING "hello %i world" | 352 #define FMT_STRING "hello %i world" |
297 ~^ | 353 ~^ |
354 | | |
355 int | |
298 %s | 356 %s |
299 { dg-end-multiline-output "" } */ | 357 { dg-end-multiline-output "" } */ |
300 #undef FMT_STRING | 358 #undef FMT_STRING |
301 } | 359 } |
302 | 360 |
305 __builtin_printf(" %" "d ", 0.5); /* { dg-warning "20: format .%d. expects argument of type .int., but argument 2 has type .double." } */ | 363 __builtin_printf(" %" "d ", 0.5); /* { dg-warning "20: format .%d. expects argument of type .int., but argument 2 has type .double." } */ |
306 /* { dg-message "26: format string is defined here" "" { target *-*-* } .-1 } */ | 364 /* { dg-message "26: format string is defined here" "" { target *-*-* } .-1 } */ |
307 /* { dg-begin-multiline-output "" } | 365 /* { dg-begin-multiline-output "" } |
308 __builtin_printf(" %" "d ", 0.5); | 366 __builtin_printf(" %" "d ", 0.5); |
309 ^~~~ ~~~ | 367 ^~~~ ~~~ |
368 | | |
369 double | |
310 { dg-end-multiline-output "" } */ | 370 { dg-end-multiline-output "" } */ |
311 /* { dg-begin-multiline-output "" } | 371 /* { dg-begin-multiline-output "" } |
312 __builtin_printf(" %" "d ", 0.5); | 372 __builtin_printf(" %" "d ", 0.5); |
313 ~~~~^ | 373 ~~~~^ |
374 | | |
375 int | |
314 %" "f | 376 %" "f |
315 { dg-end-multiline-output "" } */ | 377 { dg-end-multiline-output "" } */ |
316 } | 378 } |
317 | 379 |
318 void test_const_arrays (void) | 380 void test_const_arrays (void) |
322 const char a[] = " %d "; | 384 const char a[] = " %d "; |
323 __builtin_printf(a, 0.5); /* { dg-warning "20: format .%d. expects argument of type .int., but argument 2 has type .double." } */ | 385 __builtin_printf(a, 0.5); /* { dg-warning "20: format .%d. expects argument of type .int., but argument 2 has type .double." } */ |
324 /* { dg-begin-multiline-output "" } | 386 /* { dg-begin-multiline-output "" } |
325 __builtin_printf(a, 0.5); | 387 __builtin_printf(a, 0.5); |
326 ^ ~~~ | 388 ^ ~~~ |
327 { dg-end-multiline-output "" } */ | 389 | |
328 } | 390 double |
391 { dg-end-multiline-output "" } */ | |
392 } |