1 /* { dg-do compile } */
2 /* { dg-options "-O -fdiagnostics-show-caret" } */
3 
4 /* This is a collection of unittests for diagnostic_show_locus;
5    see the overview in diagnostic_plugin_test_show_locus.c.
6 
7    In particular, note the discussion of why we need a very long line here:
8 01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
9    and that we can't use macros in this file.  */
10 
test_simple(void)11 void test_simple (void)
12 {
13 #if 0
14   myvar = myvar.x; /* { dg-warning "test" } */
15 
16 /* { dg-begin-multiline-output "" }
17    myvar = myvar.x;
18            ~~~~~^~
19    { dg-end-multiline-output "" } */
20 #endif
21 }
22 
test_simple_2(void)23 void test_simple_2 (void)
24 {
25 #if 0
26   x = first_function () + second_function ();  /* { dg-warning "test" } */
27 
28 /* { dg-begin-multiline-output "" }
29    x = first_function () + second_function ();
30        ~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~
31    { dg-end-multiline-output "" } */
32 #endif
33 }
34 
35 
test_multiline(void)36 void test_multiline (void)
37 {
38 #if 0
39   x = (first_function ()
40        + second_function ()); /* { dg-warning "test" } */
41 
42 /* { dg-begin-multiline-output "" }
43    x = (first_function ()
44         ~~~~~~~~~~~~~~~~~
45         + second_function ());
46         ^ ~~~~~~~~~~~~~~~~~~
47         |
48         label
49    { dg-end-multiline-output "" } */
50 #endif
51 }
52 
test_many_lines(void)53 void test_many_lines (void)
54 {
55 #if 0
56   x = (first_function_with_a_very_long_name (lorem, ipsum, dolor, sit, amet,
57                                             consectetur, adipiscing, elit,
58                                             sed, eiusmod, tempor,
59                                             incididunt, ut, labore, et,
60                                             dolore, magna, aliqua)
61        + second_function_with_a_very_long_name (lorem, ipsum, dolor, sit, /* { dg-warning "test" } */
62                                                 amet, consectetur,
63                                                 adipiscing, elit, sed,
64                                                 eiusmod, tempor, incididunt,
65                                                 ut, labore, et, dolore,
66                                                 magna, aliqua));
67 
68 /* { dg-begin-multiline-output "" }
69    x = (first_function_with_a_very_long_name (lorem, ipsum, dolor, sit, amet,
70         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
71         |
72         label 1
73                                              consectetur, adipiscing, elit,
74                                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
75                                              sed, eiusmod, tempor,
76                                              ~~~~~~~~~~~~~~~~~~~~~
77                                              incididunt, ut, labore, et,
78                                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~
79                                              dolore, magna, aliqua)
80                                              ~~~~~~~~~~~~~~~~~~~~~~
81         + second_function_with_a_very_long_name (lorem, ipsum, dolor, sit,
82         ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
83         | |
84         | label 2
85         label 0
86                                                  amet, consectetur,
87                                                  ~~~~~~~~~~~~~~~~~~
88                                                  adipiscing, elit, sed,
89                                                  ~~~~~~~~~~~~~~~~~~~~~~
90                                                  eiusmod, tempor, incididunt,
91                                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
92                                                  ut, labore, et, dolore,
93                                                  ~~~~~~~~~~~~~~~~~~~~~~~
94                                                  magna, aliqua));
95                                                  ~~~~~~~~~~~~~~
96    { dg-end-multiline-output "" } */
97 #endif
98 }
99 
test_richloc_from_proper_range(void)100 void test_richloc_from_proper_range (void)
101 {
102 #if 0
103   float f = 98.6f; /* { dg-warning "test" } */
104 /* { dg-begin-multiline-output "" }
105    float f = 98.6f;
106              ^~~~~
107    { dg-end-multiline-output "" } */
108 #endif
109 }
110 
test_caret_within_proper_range(void)111 void test_caret_within_proper_range (void)
112 {
113 #if 0
114   float f = foo * bar; /* { dg-warning "17: test" } */
115 /* { dg-begin-multiline-output "" }
116    float f = foo * bar;
117              ~~~~^~~~~
118    { dg-end-multiline-output "" } */
119 #endif
120 }
121 
test_very_wide_line(void)122 void test_very_wide_line (void)
123 {
124 #if 0
125                              float x                                                    = foo * bar; /* { dg-warning "95: test" } */
126 /* { dg-begin-multiline-output "" }
127      0         0         0         0         0         0         1
128      4         5         6         7         8         9         0
129  6789012345678901234567890123456789012345678901234567890123456789012345
130  x                                                    = foo * bar;
131  ~                                                      ~~~~^~~~~
132  |                                                          |
133  label 1                                                    label 0
134                                                         bar * foo
135    { dg-end-multiline-output "" } */
136 #endif
137 }
138 
test_very_wide_line_2(void)139 void test_very_wide_line_2 (void)
140 {
141 #if 0
142                             float x                                                     = foo * bar; /* { dg-warning "95: test" } */
143 /* { dg-begin-multiline-output "" }
144      0         0         0         0         0         0         1
145      4         5         6         7         8         9         0
146  6789012345678901234567890123456789012345678901234567890123456789012345
147                                                       = foo * bar;
148                                                         ~~~~^~~~~
149                                                             |
150                                                             label 0
151                                                         bar * foo
152    { dg-end-multiline-output "" } */
153 #endif
154 }
155 
test_multiple_carets(void)156 void test_multiple_carets (void)
157 {
158 #if 0
159    x = x + y /* { dg-warning "8: test" } */
160 /* { dg-begin-multiline-output "" }
161     x = x + y
162         A   B
163    { dg-end-multiline-output "" } */
164 #endif
165 }
166 
test_caret_on_leading_whitespace(void)167 void test_caret_on_leading_whitespace (void)
168 {
169 #if 0
170     ASSOCIATE (y => x)
171       y = 5 /* { dg-warning "6: test" } */
172 /* { dg-begin-multiline-output "" }
173      ASSOCIATE (y => x)
174                     2
175        y = 5
176       1
177    { dg-end-multiline-output "" } */
178 #endif
179 }
180 
181 /* Unit test for rendering of insertion fixit hints
182    (example taken from PR 62316).  */
183 
test_fixit_insert(void)184 void test_fixit_insert (void)
185 {
186 #if 0
187    int a[2][2] = { 0, 1 , 2, 3 }; /* { dg-warning "insertion hints" } */
188 /* { dg-begin-multiline-output "" }
189     int a[2][2] = { 0, 1 , 2, 3 };
190                     ^~~~
191                     {   }
192    { dg-end-multiline-output "" } */
193 #endif
194 }
195 
196 /* Unit test for rendering of "remove" fixit hints.  */
197 
test_fixit_remove(void)198 void test_fixit_remove (void)
199 {
200 #if 0
201   int a;; /* { dg-warning "example of a removal hint" } */
202 /* { dg-begin-multiline-output "" }
203    int a;;
204          ^
205          -
206    { dg-end-multiline-output "" } */
207 #endif
208 }
209 
210 /* Unit test for rendering of "replace" fixit hints.  */
211 
test_fixit_replace(void)212 void test_fixit_replace (void)
213 {
214 #if 0
215   gtk_widget_showall (dlg); /* { dg-warning "example of a replacement hint" } */
216 /* { dg-begin-multiline-output "" }
217    gtk_widget_showall (dlg);
218    ^~~~~~~~~~~~~~~~~~
219    gtk_widget_show_all
220    { dg-end-multiline-output "" } */
221 #endif
222 }
223 
224 /* Test of "%q+D" format code.  */
225 
test_percent_q_plus_d(void)226 int test_percent_q_plus_d (void)
227 {
228   int local = 0; /* { dg-warning "example of plus in format code" } */
229 /* { dg-begin-multiline-output "" }
230    int local = 0;
231        ^~~~~
232    { dg-end-multiline-output "" } */
233   return local;
234 }
235 
236 /* Test of many nested locations and fixits.  */
237 
test_many_nested_locations(void)238 void test_many_nested_locations (void)
239 {
240   /* { dg-warning "test of 70 locations" }
241     Lorem ipsum dolor sit amet, consectetur adipiscing elit,
242     sed do eiusmod tempor incididunt ut labore et dolore magna
243     aliqua. Ut enim ad minim veniam, quis nostrud exercitation
244     ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis
245     aute irure dolor in reprehenderit in voluptate velit esse cillum
246     dolore eu fugiat nulla pariatur. Excepteur sint occaecat
247     cupidatat non proident, sunt in culpa qui officia deserunt
248     mollit anim id est laborum.
249   */
250 /* { dg-begin-multiline-output "" }
251    /*
252    ^
253      Lorem ipsum dolor sit amet, consectetur adipiscing elit,
254      ^~~~~ ^~~~~ ^~~~~ ^~~ ^~~~  ^~~~~~~~~~~ ^~~~~~~~~~ ^~~~
255      |     |     |     |   |     |           |          |
256      |     |     |     |   label label       label      label
257      label label label label
258      LOREM IPSUM DOLOR SIT AMET  CONSECTETUR ADIPISCING ELIT
259      sed do eiusmod tempor incididunt ut labore et dolore magna
260      ^~~ ^~ ^~~~~~~ ^~~~~~ ^~~~~~~~~~ ^~ ^~~~~~ ^~ ^~~~~~ ^~~~~
261      |   |  |       |      |          |  |      |  |      |
262      |   |  |       |      |          |  |      |  label  label
263      |   |  |       |      |          |  label  label
264      |   |  label   label  label      label
265      |   label
266      label
267      SED DO EIUSMOD TEMPOR INCIDIDUNT UT LABORE ET DOLORE MAGNA
268      aliqua. Ut enim ad minim veniam, quis nostrud exercitation
269      ^~~~~~  ^~ ^~~~ ^~ ^~~~~ ^~~~~~  ^~~~ ^~~~~~~ ^~~~~~~~~~~~
270      |       |  |    |  |     |       |    |       |
271      |       |  |    |  |     |       |    label   label
272      |       |  |    |  label label   label
273      |       |  |    label
274      |       |  label
275      label   label
276      ALIQUA  UT ENIM AD MINIM VENIAM  QUIS NOSTRUD EXERCITATION
277      ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis
278      ^~~~~~~ ^~~~~~~ ^~~~ ^~ ^~~~~~~ ^~ ^~ ^~~~~~~ ^~~~~~~~~  ^~~~
279      |       |       |    |  |       |  |  |       |          |
280      |       |       |    |  |       |  |  label   label      label
281      |       |       |    |  |       |  label
282      |       |       |    |  label   label
283      |       |       |    label
284      label   label   label
285      ULLAMCO LABORIS NISI UT ALIQUIP EX EA COMMODO CONSEQUAT  DUIS
286      aute irure dolor in reprehenderit in voluptate velit esse cillum
287      ^~~~ ^~~~~ ^~~~~ ^~ ^~~~~~~~~~~~~ ^~ ^~~~~~~~~ ^~~~~ ^~~~ ^~~~~~
288      |    |     |     |  |             |  |         |     |    |
289      |    |     |     |  |             |  |         |     |    label
290      |    |     |     |  |             |  label     label label
291      |    |     |     |  label         label
292      |    label label label
293      label
294      AUTE IRURE DOLOR IN REPREHENDERIT IN VOLUPTATE VELIT ESSE CILLUM
295      dolore eu fugiat nulla pariatur. Excepteur sint occaecat
296      ^~~~~~ ^~ ^~~~~~ ^~~~~ ^~~~~~~~  ^~~~~~~~~ ^~~~ ^~~~~~~~
297      |      |  |      |     |         |         |    |
298      |      |  |      |     |         |         |    label
299      |      |  label  label label     label     label
300      label  label
301      DOLORE EU FUGIAT NULLA PARIATUR  EXCEPTEUR SINT OCCAECAT
302      cupidatat non proident, sunt in culpa qui officia deserunt
303      ^~~~~~~~~ ^~~ ^~~~~~~~  ^~~~ ^~ ^~~~~ ^~~ ^~~~~~~ ^~~~~~~~
304      |         |   |         |    |  |     |   |       |
305      |         |   |         |    |  |     |   label   label
306      |         |   |         |    |  label label
307      |         |   |         |    label
308      |         |   label     label
309      label     label
310      CUPIDATAT NON PROIDENT  SUNT IN CULPA QUI OFFICIA DESERUNT
311      mollit anim id est laborum.
312      ^~~~~~ ^~~~ ^~ ^~~ ^~~~~~~
313      |      |    |  |   |
314      |      |    |  |   label
315      |      |    |  label
316      |      |    label
317      label  label
318      MOLLIT ANIM ID EST LABORUM
319    { dg-end-multiline-output "" } */
320 }
321 
322 /* Unit test for rendering of fix-it hints that add new lines.  */
323 
test_fixit_insert_newline(void)324 void test_fixit_insert_newline (void)
325 {
326 #if 0
327   switch (op)
328     {
329     case 'a':
330       x = a;
331     case 'b':  /* { dg-warning "newline insertion" } */
332       x = b;
333     }
334 /* { dg-begin-multiline-output "" }
335        x = a;
336 +      break;
337      case 'b':
338      ^~~~~~~~
339    { dg-end-multiline-output "" } */
340 #endif
341 }
342 
343 /* Unit test for mutually-exclusive suggestions.  */
344 
test_mutually_exclusive_suggestions(void)345 void test_mutually_exclusive_suggestions (void)
346 {
347 #if 0
348   original; /* { dg-warning "warning 1" } */
349 /* { dg-warning "warning 2" "" { target *-*-* } .-1 } */
350 /* { dg-begin-multiline-output "" }
351    original;
352    ^~~~~~~~
353    replacement_1
354    { dg-end-multiline-output "" } */
355 /* { dg-begin-multiline-output "" }
356    original;
357    ^~~~~~~~
358    replacement_2
359    { dg-end-multiline-output "" } */
360 #endif
361 }
362