annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* { dg-options "-Wformat -fdiagnostics-show-caret" } */
kono
parents:
diff changeset
2
kono
parents:
diff changeset
3 /* See PR 52952. */
kono
parents:
diff changeset
4
kono
parents:
diff changeset
5 #include "format.h"
kono
parents:
diff changeset
6
kono
parents:
diff changeset
7 void test_mismatching_types (const char *msg)
kono
parents:
diff changeset
8 {
kono
parents:
diff changeset
9 printf("hello %i", msg); /* { dg-warning "format '%i' expects argument of type 'int', but argument 2 has type 'const char \\*' " } */
kono
parents:
diff changeset
10
kono
parents:
diff changeset
11 /* { dg-begin-multiline-output "" }
kono
parents:
diff changeset
12 printf("hello %i", msg);
kono
parents:
diff changeset
13 ~^ ~~~
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
14 | |
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
15 int const char *
111
kono
parents:
diff changeset
16 %s
kono
parents:
diff changeset
17 { dg-end-multiline-output "" } */
kono
parents:
diff changeset
18
kono
parents:
diff changeset
19
kono
parents:
diff changeset
20 printf("hello %s", 42); /* { dg-warning "format '%s' expects argument of type 'char \\*', but argument 2 has type 'int'" } */
kono
parents:
diff changeset
21 /* { dg-begin-multiline-output "" }
kono
parents:
diff changeset
22 printf("hello %s", 42);
kono
parents:
diff changeset
23 ~^ ~~
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
24 | |
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
25 | int
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
26 char *
111
kono
parents:
diff changeset
27 %d
kono
parents:
diff changeset
28 { dg-end-multiline-output "" } */
kono
parents:
diff changeset
29
kono
parents:
diff changeset
30 printf("hello %i", (long)0); /* { dg-warning "format '%i' expects argument of type 'int', but argument 2 has type 'long int' " } */
kono
parents:
diff changeset
31 /* { dg-begin-multiline-output "" }
kono
parents:
diff changeset
32 printf("hello %i", (long)0);
kono
parents:
diff changeset
33 ~^ ~~~~~~~
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
34 | |
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
35 int long int
111
kono
parents:
diff changeset
36 %li
kono
parents:
diff changeset
37 { dg-end-multiline-output "" } */
kono
parents:
diff changeset
38 }
kono
parents:
diff changeset
39
kono
parents:
diff changeset
40 void test_multiple_arguments (void)
kono
parents:
diff changeset
41 {
kono
parents:
diff changeset
42 printf ("arg0: %i arg1: %s arg 2: %i", /* { dg-warning "29: format '%s'" } */
kono
parents:
diff changeset
43 100, 101, 102);
kono
parents:
diff changeset
44 /* { dg-begin-multiline-output "" }
kono
parents:
diff changeset
45 printf ("arg0: %i arg1: %s arg 2: %i",
kono
parents:
diff changeset
46 ~^
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
47 |
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
48 char *
111
kono
parents:
diff changeset
49 %d
kono
parents:
diff changeset
50 100, 101, 102);
kono
parents:
diff changeset
51 ~~~
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
52 |
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
53 int
111
kono
parents:
diff changeset
54 { dg-end-multiline-output "" } */
kono
parents:
diff changeset
55 }
kono
parents:
diff changeset
56
kono
parents:
diff changeset
57 void test_multiple_arguments_2 (int i, int j)
kono
parents:
diff changeset
58 {
kono
parents:
diff changeset
59 printf ("arg0: %i arg1: %s arg 2: %i", /* { dg-warning "29: format '%s'" } */
kono
parents:
diff changeset
60 100, i + j, 102);
kono
parents:
diff changeset
61 /* { dg-begin-multiline-output "" }
kono
parents:
diff changeset
62 printf ("arg0: %i arg1: %s arg 2: %i",
kono
parents:
diff changeset
63 ~^
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
64 |
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
65 char *
111
kono
parents:
diff changeset
66 %d
kono
parents:
diff changeset
67 100, i + j, 102);
kono
parents:
diff changeset
68 ~~~~~
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
69 |
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
70 int
111
kono
parents:
diff changeset
71 { dg-end-multiline-output "" } */
kono
parents:
diff changeset
72 }
kono
parents:
diff changeset
73
kono
parents:
diff changeset
74 void multiline_format_string (void) {
kono
parents:
diff changeset
75 printf ("before the fmt specifier" /* { dg-warning "11: format '%d' expects a matching 'int' argument" } */
kono
parents:
diff changeset
76 /* { dg-begin-multiline-output "" }
kono
parents:
diff changeset
77 printf ("before the fmt specifier"
kono
parents:
diff changeset
78 ^~~~~~~~~~~~~~~~~~~~~~~~~~
kono
parents:
diff changeset
79 { dg-end-multiline-output "" } */
kono
parents:
diff changeset
80
kono
parents:
diff changeset
81 "%"
kono
parents:
diff changeset
82 "d" /* { dg-message "12: format string is defined here" } */
kono
parents:
diff changeset
83 "after the fmt specifier");
kono
parents:
diff changeset
84
kono
parents:
diff changeset
85 /* { dg-begin-multiline-output "" }
kono
parents:
diff changeset
86 "%"
kono
parents:
diff changeset
87 ~~
kono
parents:
diff changeset
88 "d"
kono
parents:
diff changeset
89 ~^
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
90 |
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
91 int
111
kono
parents:
diff changeset
92 { dg-end-multiline-output "" } */
kono
parents:
diff changeset
93 }
kono
parents:
diff changeset
94
kono
parents:
diff changeset
95 void test_hex (const char *msg)
kono
parents:
diff changeset
96 {
kono
parents:
diff changeset
97 /* "%" is \x25
kono
parents:
diff changeset
98 "i" is \x69 */
kono
parents:
diff changeset
99 printf("hello \x25\x69", msg); /* { dg-warning "format '%i' expects argument of type 'int', but argument 2 has type 'const char \\*' " } */
kono
parents:
diff changeset
100
kono
parents:
diff changeset
101 /* { dg-begin-multiline-output "" }
kono
parents:
diff changeset
102 printf("hello \x25\x69", msg);
kono
parents:
diff changeset
103 ~~~~^~~~ ~~~
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
104 | |
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
105 int const char *
111
kono
parents:
diff changeset
106 \x25s
kono
parents:
diff changeset
107 { dg-end-multiline-output "" } */
kono
parents:
diff changeset
108 }
kono
parents:
diff changeset
109
kono
parents:
diff changeset
110 void test_oct (const char *msg)
kono
parents:
diff changeset
111 {
kono
parents:
diff changeset
112 /* "%" is octal 045
kono
parents:
diff changeset
113 "i" is octal 151. */
kono
parents:
diff changeset
114 printf("hello \045\151", msg); /* { dg-warning "format '%i' expects argument of type 'int', but argument 2 has type 'const char \\*' " } */
kono
parents:
diff changeset
115
kono
parents:
diff changeset
116 /* { dg-begin-multiline-output "" }
kono
parents:
diff changeset
117 printf("hello \045\151", msg);
kono
parents:
diff changeset
118 ~~~~^~~~ ~~~
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
119 | |
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
120 int const char *
111
kono
parents:
diff changeset
121 \045s
kono
parents:
diff changeset
122 { dg-end-multiline-output "" } */
kono
parents:
diff changeset
123 }
kono
parents:
diff changeset
124
kono
parents:
diff changeset
125 void test_multiple (const char *msg)
kono
parents:
diff changeset
126 {
kono
parents:
diff changeset
127 /* "%" is \x25 in hex
kono
parents:
diff changeset
128 "i" is \151 in octal. */
kono
parents:
diff changeset
129 printf("prefix" "\x25" "\151" "suffix", /* { dg-warning "format '%i'" } */
kono
parents:
diff changeset
130 msg);
kono
parents:
diff changeset
131 /* { dg-begin-multiline-output "" }
kono
parents:
diff changeset
132 printf("prefix" "\x25" "\151" "suffix",
kono
parents:
diff changeset
133 ^~~~~~~~
kono
parents:
diff changeset
134 msg);
kono
parents:
diff changeset
135 ~~~
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
136 |
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
137 const char *
111
kono
parents:
diff changeset
138 { dg-end-multiline-output "" } */
kono
parents:
diff changeset
139
kono
parents:
diff changeset
140 /* { dg-begin-multiline-output "" }
kono
parents:
diff changeset
141 printf("prefix" "\x25" "\151" "suffix",
kono
parents:
diff changeset
142 ~~~~~~~~^~~~
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
143 |
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
144 int
111
kono
parents:
diff changeset
145 \x25" "s
kono
parents:
diff changeset
146 { dg-end-multiline-output "" } */
kono
parents:
diff changeset
147 }
kono
parents:
diff changeset
148
kono
parents:
diff changeset
149 void test_u8 (const char *msg)
kono
parents:
diff changeset
150 {
kono
parents:
diff changeset
151 printf(u8"hello %i", msg);/* { dg-warning "format '%i' expects argument of type 'int', but argument 2 has type 'const char \\*' " } */
kono
parents:
diff changeset
152 /* { dg-begin-multiline-output "" }
kono
parents:
diff changeset
153 printf(u8"hello %i", msg);
kono
parents:
diff changeset
154 ~^ ~~~
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
155 | |
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
156 int const char *
111
kono
parents:
diff changeset
157 %s
kono
parents:
diff changeset
158 { dg-end-multiline-output "" } */
kono
parents:
diff changeset
159 }
kono
parents:
diff changeset
160
kono
parents:
diff changeset
161 void test_param (long long_i, long long_j)
kono
parents:
diff changeset
162 {
kono
parents:
diff changeset
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'" } */
kono
parents:
diff changeset
164 /* { dg-begin-multiline-output "" }
kono
parents:
diff changeset
165 printf ("foo %s bar", long_i + long_j);
kono
parents:
diff changeset
166 ~^ ~~~~~~~~~~~~~~~
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
167 | |
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
168 char * long int
111
kono
parents:
diff changeset
169 %ld
kono
parents:
diff changeset
170 { dg-end-multiline-output "" } */
kono
parents:
diff changeset
171 }
kono
parents:
diff changeset
172
kono
parents:
diff changeset
173 void test_field_width_specifier (long l, int i1, int i2)
kono
parents:
diff changeset
174 {
kono
parents:
diff changeset
175 printf (" %*.*d ", l, i1, i2); /* { dg-warning "14: field width specifier '\\*' expects argument of type 'int', but argument 2 has type 'long int'" } */
kono
parents:
diff changeset
176 /* { dg-begin-multiline-output "" }
kono
parents:
diff changeset
177 printf (" %*.*d ", l, i1, i2);
kono
parents:
diff changeset
178 ~^~~~ ~
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
179 | |
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
180 int long int
111
kono
parents:
diff changeset
181 { dg-end-multiline-output "" } */
kono
parents:
diff changeset
182 }
kono
parents:
diff changeset
183
kono
parents:
diff changeset
184 /* PR c/72857. */
kono
parents:
diff changeset
185
kono
parents:
diff changeset
186 void test_field_width_specifier_2 (char *d, long foo, long bar)
kono
parents:
diff changeset
187 {
kono
parents:
diff changeset
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'" } */
kono
parents:
diff changeset
189 /* { dg-begin-multiline-output "" }
kono
parents:
diff changeset
190 __builtin_sprintf (d, " %*ld ", foo, foo);
kono
parents:
diff changeset
191 ~^~~ ~~~
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
192 | |
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
193 int long int
111
kono
parents:
diff changeset
194 { dg-end-multiline-output "" } */
kono
parents:
diff changeset
195
kono
parents:
diff changeset
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'" } */
kono
parents:
diff changeset
197 /* { dg-begin-multiline-output "" }
kono
parents:
diff changeset
198 __builtin_sprintf (d, " %*ld ", foo + bar, foo);
kono
parents:
diff changeset
199 ~^~~ ~~~~~~~~~
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
200 | |
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
201 int long int
111
kono
parents:
diff changeset
202 { dg-end-multiline-output "" } */
kono
parents:
diff changeset
203 }
kono
parents:
diff changeset
204
kono
parents:
diff changeset
205 void test_field_precision_specifier (char *d, long foo, long bar)
kono
parents:
diff changeset
206 {
kono
parents:
diff changeset
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'" } */
kono
parents:
diff changeset
208 /* { dg-begin-multiline-output "" }
kono
parents:
diff changeset
209 __builtin_sprintf (d, " %.*ld ", foo, foo);
kono
parents:
diff changeset
210 ~~^~~ ~~~
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
211 | |
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
212 int long int
111
kono
parents:
diff changeset
213 { dg-end-multiline-output "" } */
kono
parents:
diff changeset
214
kono
parents:
diff changeset
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'" } */
kono
parents:
diff changeset
216 /* { dg-begin-multiline-output "" }
kono
parents:
diff changeset
217 __builtin_sprintf (d, " %.*ld ", foo + bar, foo);
kono
parents:
diff changeset
218 ~~^~~ ~~~~~~~~~
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
219 | |
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
220 int long int
111
kono
parents:
diff changeset
221 { dg-end-multiline-output "" } */
kono
parents:
diff changeset
222 }
kono
parents:
diff changeset
223
kono
parents:
diff changeset
224 void test_spurious_percent (void)
kono
parents:
diff changeset
225 {
kono
parents:
diff changeset
226 printf("hello world %"); /* { dg-warning "23: spurious trailing" } */
kono
parents:
diff changeset
227
kono
parents:
diff changeset
228 /* { dg-begin-multiline-output "" }
kono
parents:
diff changeset
229 printf("hello world %");
kono
parents:
diff changeset
230 ^
kono
parents:
diff changeset
231 { dg-end-multiline-output "" } */
kono
parents:
diff changeset
232 }
kono
parents:
diff changeset
233
kono
parents:
diff changeset
234 void test_empty_precision (char *s, size_t m, double d)
kono
parents:
diff changeset
235 {
kono
parents:
diff changeset
236 strfmon (s, m, "%#.5n", d); /* { dg-warning "20: empty left precision in gnu_strfmon format" } */
kono
parents:
diff changeset
237 /* { dg-begin-multiline-output "" }
kono
parents:
diff changeset
238 strfmon (s, m, "%#.5n", d);
kono
parents:
diff changeset
239 ^
kono
parents:
diff changeset
240 { dg-end-multiline-output "" } */
kono
parents:
diff changeset
241
kono
parents:
diff changeset
242 strfmon (s, m, "%#5.n", d); /* { dg-warning "22: empty precision in gnu_strfmon format" } */
kono
parents:
diff changeset
243 /* { dg-begin-multiline-output "" }
kono
parents:
diff changeset
244 strfmon (s, m, "%#5.n", d);
kono
parents:
diff changeset
245 ^
kono
parents:
diff changeset
246 { dg-end-multiline-output "" } */
kono
parents:
diff changeset
247 }
kono
parents:
diff changeset
248
kono
parents:
diff changeset
249 void test_repeated (int i)
kono
parents:
diff changeset
250 {
kono
parents:
diff changeset
251 printf ("%++d", i); /* { dg-warning "14: repeated '\\+' flag in format" } */
kono
parents:
diff changeset
252 /* { dg-begin-multiline-output "" }
kono
parents:
diff changeset
253 printf ("%++d", i);
kono
parents:
diff changeset
254 ^
kono
parents:
diff changeset
255 { dg-end-multiline-output "" } */
kono
parents:
diff changeset
256 }
kono
parents:
diff changeset
257
kono
parents:
diff changeset
258 void test_conversion_lacks_type (void)
kono
parents:
diff changeset
259 {
kono
parents:
diff changeset
260 printf (" %h"); /* { dg-warning "14:conversion lacks type at end of format" } */
kono
parents:
diff changeset
261 /* { dg-begin-multiline-output "" }
kono
parents:
diff changeset
262 printf (" %h");
kono
parents:
diff changeset
263 ^
kono
parents:
diff changeset
264 { dg-end-multiline-output "" } */
kono
parents:
diff changeset
265 }
kono
parents:
diff changeset
266
kono
parents:
diff changeset
267 void test_embedded_nul (void)
kono
parents:
diff changeset
268 {
kono
parents:
diff changeset
269 printf (" \0 "); /* { dg-warning "13:embedded" "warning for embedded NUL" } */
kono
parents:
diff changeset
270 /* { dg-begin-multiline-output "" }
kono
parents:
diff changeset
271 printf (" \0 ");
kono
parents:
diff changeset
272 ^~
kono
parents:
diff changeset
273 { dg-end-multiline-output "" } */
kono
parents:
diff changeset
274 }
kono
parents:
diff changeset
275
kono
parents:
diff changeset
276 void test_macro (const char *msg)
kono
parents:
diff changeset
277 {
kono
parents:
diff changeset
278 #define INT_FMT "%i" /* { dg-message "19: format string is defined here" } */
kono
parents:
diff changeset
279 printf("hello " INT_FMT " world", msg); /* { dg-warning "10: format '%i' expects argument of type 'int', but argument 2 has type 'const char \\*' " } */
kono
parents:
diff changeset
280 /* { dg-begin-multiline-output "" }
kono
parents:
diff changeset
281 printf("hello " INT_FMT " world", msg);
kono
parents:
diff changeset
282 ^~~~~~~~ ~~~
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
283 |
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
284 const char *
111
kono
parents:
diff changeset
285 { dg-end-multiline-output "" } */
kono
parents:
diff changeset
286 /* { dg-begin-multiline-output "" }
kono
parents:
diff changeset
287 #define INT_FMT "%i"
kono
parents:
diff changeset
288 ~^
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
289 |
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
290 int
111
kono
parents:
diff changeset
291 %s
kono
parents:
diff changeset
292 { dg-end-multiline-output "" } */
kono
parents:
diff changeset
293 #undef INT_FMT
kono
parents:
diff changeset
294 }
kono
parents:
diff changeset
295
kono
parents:
diff changeset
296 void test_macro_2 (const char *msg)
kono
parents:
diff changeset
297 {
kono
parents:
diff changeset
298 #define PRIu32 "u" /* { dg-message "17: format string is defined here" } */
kono
parents:
diff changeset
299 printf("hello %" PRIu32 " world", msg); /* { dg-warning "10: format '%u' expects argument of type 'unsigned int', but argument 2 has type 'const char \\*' " } */
kono
parents:
diff changeset
300 /* { dg-begin-multiline-output "" }
kono
parents:
diff changeset
301 printf("hello %" PRIu32 " world", msg);
kono
parents:
diff changeset
302 ^~~~~~~~~ ~~~
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
303 |
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
304 const char *
111
kono
parents:
diff changeset
305 { dg-end-multiline-output "" } */
kono
parents:
diff changeset
306 /* { dg-begin-multiline-output "" }
kono
parents:
diff changeset
307 #define PRIu32 "u"
kono
parents:
diff changeset
308 ^
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
309 |
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
310 unsigned int
111
kono
parents:
diff changeset
311 { dg-end-multiline-output "" } */
kono
parents:
diff changeset
312 #undef PRIu32
kono
parents:
diff changeset
313 }
kono
parents:
diff changeset
314
kono
parents:
diff changeset
315 void test_macro_3 (const char *msg)
kono
parents:
diff changeset
316 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
317 #define FMT_STRING "hello %i world" /* { dg-line test_macro_3_macro_line } */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
318 /* { dg-warning "20: format '%i' expects argument of type 'int', but argument 2 has type 'const char \\*'" "" { target *-*-*} .-1 } */
111
kono
parents:
diff changeset
319 printf(FMT_STRING, msg); /* { dg-message "10: in expansion of macro 'FMT_STRING" } */
kono
parents:
diff changeset
320 /* { dg-begin-multiline-output "" }
kono
parents:
diff changeset
321 #define FMT_STRING "hello %i world"
kono
parents:
diff changeset
322 ^~~~~~~~~~~~~~~~
kono
parents:
diff changeset
323 { dg-end-multiline-output "" } */
kono
parents:
diff changeset
324 /* { dg-begin-multiline-output "" }
kono
parents:
diff changeset
325 printf(FMT_STRING, msg);
kono
parents:
diff changeset
326 ^~~~~~~~~~
kono
parents:
diff changeset
327 { dg-end-multiline-output "" } */
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
328 /* { dg-message "28: format string is defined here" "" { target *-*-* } test_macro_3_macro_line } */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
329 /* { dg-begin-multiline-output "" }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
330 #define FMT_STRING "hello %i world"
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
331 ~^
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
332 |
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
333 int
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
334 %s
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
335 { dg-end-multiline-output "" } */
111
kono
parents:
diff changeset
336 #undef FMT_STRING
kono
parents:
diff changeset
337 }
kono
parents:
diff changeset
338
kono
parents:
diff changeset
339 void test_macro_4 (const char *msg)
kono
parents:
diff changeset
340 {
kono
parents:
diff changeset
341 #define FMT_STRING "hello %i world" /* { dg-warning "20: format '%i' expects argument of type 'int', but argument 2 has type 'const char \\*' " } */
kono
parents:
diff changeset
342 printf(FMT_STRING "\n", msg); /* { dg-message "10: in expansion of macro 'FMT_STRING" } */
kono
parents:
diff changeset
343 /* { dg-begin-multiline-output "" }
kono
parents:
diff changeset
344 #define FMT_STRING "hello %i world"
kono
parents:
diff changeset
345 ^~~~~~~~~~~~~~~~
kono
parents:
diff changeset
346 { dg-end-multiline-output "" } */
kono
parents:
diff changeset
347 /* { dg-begin-multiline-output "" }
kono
parents:
diff changeset
348 printf(FMT_STRING "\n", msg);
kono
parents:
diff changeset
349 ^~~~~~~~~~
kono
parents:
diff changeset
350 { dg-end-multiline-output "" } */
kono
parents:
diff changeset
351 /* { dg-begin-multiline-output "" }
kono
parents:
diff changeset
352 #define FMT_STRING "hello %i world"
kono
parents:
diff changeset
353 ~^
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
354 |
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
355 int
111
kono
parents:
diff changeset
356 %s
kono
parents:
diff changeset
357 { dg-end-multiline-output "" } */
kono
parents:
diff changeset
358 #undef FMT_STRING
kono
parents:
diff changeset
359 }
kono
parents:
diff changeset
360
kono
parents:
diff changeset
361 void test_non_contiguous_strings (void)
kono
parents:
diff changeset
362 {
kono
parents:
diff changeset
363 __builtin_printf(" %" "d ", 0.5); /* { dg-warning "20: format .%d. expects argument of type .int., but argument 2 has type .double." } */
kono
parents:
diff changeset
364 /* { dg-message "26: format string is defined here" "" { target *-*-* } .-1 } */
kono
parents:
diff changeset
365 /* { dg-begin-multiline-output "" }
kono
parents:
diff changeset
366 __builtin_printf(" %" "d ", 0.5);
kono
parents:
diff changeset
367 ^~~~ ~~~
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
368 |
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
369 double
111
kono
parents:
diff changeset
370 { dg-end-multiline-output "" } */
kono
parents:
diff changeset
371 /* { dg-begin-multiline-output "" }
kono
parents:
diff changeset
372 __builtin_printf(" %" "d ", 0.5);
kono
parents:
diff changeset
373 ~~~~^
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
374 |
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
375 int
111
kono
parents:
diff changeset
376 %" "f
kono
parents:
diff changeset
377 { dg-end-multiline-output "" } */
kono
parents:
diff changeset
378 }
kono
parents:
diff changeset
379
kono
parents:
diff changeset
380 void test_const_arrays (void)
kono
parents:
diff changeset
381 {
kono
parents:
diff changeset
382 /* TODO: ideally we'd highlight both the format string *and* the use of
kono
parents:
diff changeset
383 it here. For now, just verify that we gracefully handle this case. */
kono
parents:
diff changeset
384 const char a[] = " %d ";
kono
parents:
diff changeset
385 __builtin_printf(a, 0.5); /* { dg-warning "20: format .%d. expects argument of type .int., but argument 2 has type .double." } */
kono
parents:
diff changeset
386 /* { dg-begin-multiline-output "" }
kono
parents:
diff changeset
387 __builtin_printf(a, 0.5);
kono
parents:
diff changeset
388 ^ ~~~
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
389 |
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
390 double
111
kono
parents:
diff changeset
391 { dg-end-multiline-output "" } */
kono
parents:
diff changeset
392 }