Add support for mutually-incompatible fix-it hints
[official-gcc.git] / gcc / testsuite / gcc.dg / plugin / diagnostic-test-show-locus-bw.c
blob100fa380cd70df22ae4e9d5a715f4102f5758e22
1 /* { dg-do compile } */
2 /* { dg-options "-O -fdiagnostics-show-caret" } */
4 /* This is a collection of unittests for diagnostic_show_locus;
5 see the overview in diagnostic_plugin_test_show_locus.c.
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. */
11 void test_simple (void)
13 #if 0
14 myvar = myvar.x; /* { dg-warning "test" } */
16 /* { dg-begin-multiline-output "" }
17 myvar = myvar.x;
18 ~~~~~^~
19 { dg-end-multiline-output "" } */
20 #endif
23 void test_simple_2 (void)
25 #if 0
26 x = first_function () + second_function (); /* { dg-warning "test" } */
28 /* { dg-begin-multiline-output "" }
29 x = first_function () + second_function ();
30 ~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~
31 { dg-end-multiline-output "" } */
32 #endif
36 void test_multiline (void)
38 #if 0
39 x = (first_function ()
40 + second_function ()); /* { dg-warning "test" } */
42 /* { dg-begin-multiline-output "" }
43 x = (first_function ()
44 ~~~~~~~~~~~~~~~~~
45 + second_function ());
46 ^ ~~~~~~~~~~~~~~~~~~
47 { dg-end-multiline-output "" } */
48 #endif
51 void test_many_lines (void)
53 #if 0
54 x = (first_function_with_a_very_long_name (lorem, ipsum, dolor, sit, amet,
55 consectetur, adipiscing, elit,
56 sed, eiusmod, tempor,
57 incididunt, ut, labore, et,
58 dolore, magna, aliqua)
59 + second_function_with_a_very_long_name (lorem, ipsum, dolor, sit, /* { dg-warning "test" } */
60 amet, consectetur,
61 adipiscing, elit, sed,
62 eiusmod, tempor, incididunt,
63 ut, labore, et, dolore,
64 magna, aliqua));
66 /* { dg-begin-multiline-output "" }
67 x = (first_function_with_a_very_long_name (lorem, ipsum, dolor, sit, amet,
68 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
69 consectetur, adipiscing, elit,
70 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
71 sed, eiusmod, tempor,
72 ~~~~~~~~~~~~~~~~~~~~~
73 incididunt, ut, labore, et,
74 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
75 dolore, magna, aliqua)
76 ~~~~~~~~~~~~~~~~~~~~~~
77 + second_function_with_a_very_long_name (lorem, ipsum, dolor, sit,
78 ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
79 amet, consectetur,
80 ~~~~~~~~~~~~~~~~~~
81 adipiscing, elit, sed,
82 ~~~~~~~~~~~~~~~~~~~~~~
83 eiusmod, tempor, incididunt,
84 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
85 ut, labore, et, dolore,
86 ~~~~~~~~~~~~~~~~~~~~~~~
87 magna, aliqua));
88 ~~~~~~~~~~~~~~
89 { dg-end-multiline-output "" } */
90 #endif
93 void test_richloc_from_proper_range (void)
95 #if 0
96 float f = 98.6f; /* { dg-warning "test" } */
97 /* { dg-begin-multiline-output "" }
98 float f = 98.6f;
99 ^~~~~
100 { dg-end-multiline-output "" } */
101 #endif
104 void test_caret_within_proper_range (void)
106 #if 0
107 float f = foo * bar; /* { dg-warning "17: test" } */
108 /* { dg-begin-multiline-output "" }
109 float f = foo * bar;
110 ~~~~^~~~~
111 { dg-end-multiline-output "" } */
112 #endif
115 void test_very_wide_line (void)
117 #if 0
118 float f = foo * bar; /* { dg-warning "95: test" } */
119 /* { dg-begin-multiline-output "" }
120 0 0 0 0 0 0 1
121 4 5 6 7 8 9 0
122 6789012345678901234567890123456789012345678901234567890123456789012345
123 float f = foo * bar;
124 ~~~~^~~~~
125 { dg-end-multiline-output "" } */
126 #endif
129 void test_multiple_carets (void)
131 #if 0
132 x = x + y /* { dg-warning "8: test" } */
133 /* { dg-begin-multiline-output "" }
134 x = x + y
136 { dg-end-multiline-output "" } */
137 #endif
140 void test_caret_on_leading_whitespace (void)
142 #if 0
143 ASSOCIATE (y => x)
144 y = 5 /* { dg-warning "6: test" } */
145 /* { dg-begin-multiline-output "" }
146 ASSOCIATE (y => x)
148 y = 5
150 { dg-end-multiline-output "" } */
151 #endif
154 /* Unit test for rendering of insertion fixit hints
155 (example taken from PR 62316). */
157 void test_fixit_insert (void)
159 #if 0
160 int a[2][2] = { 0, 1 , 2, 3 }; /* { dg-warning "insertion hints" } */
161 /* { dg-begin-multiline-output "" }
162 int a[2][2] = { 0, 1 , 2, 3 };
163 ^~~~
165 { dg-end-multiline-output "" } */
166 #endif
169 /* Unit test for rendering of "remove" fixit hints. */
171 void test_fixit_remove (void)
173 #if 0
174 int a;; /* { dg-warning "example of a removal hint" } */
175 /* { dg-begin-multiline-output "" }
176 int a;;
179 { dg-end-multiline-output "" } */
180 #endif
183 /* Unit test for rendering of "replace" fixit hints. */
185 void test_fixit_replace (void)
187 #if 0
188 gtk_widget_showall (dlg); /* { dg-warning "example of a replacement hint" } */
189 /* { dg-begin-multiline-output "" }
190 gtk_widget_showall (dlg);
191 ^~~~~~~~~~~~~~~~~~
192 gtk_widget_show_all
193 { dg-end-multiline-output "" } */
194 #endif
197 /* Test of "%q+D" format code. */
199 int test_percent_q_plus_d (void)
201 int local = 0; /* { dg-warning "example of plus in format code" } */
202 /* { dg-begin-multiline-output "" }
203 int local = 0;
204 ^~~~~
205 { dg-end-multiline-output "" } */
206 return local;
209 /* Test of many nested locations and fixits. */
211 void test_many_nested_locations (void)
213 /* { dg-warning "test of 70 locations" }
214 Lorem ipsum dolor sit amet, consectetur adipiscing elit,
215 sed do eiusmod tempor incididunt ut labore et dolore magna
216 aliqua. Ut enim ad minim veniam, quis nostrud exercitation
217 ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis
218 aute irure dolor in reprehenderit in voluptate velit esse cillum
219 dolore eu fugiat nulla pariatur. Excepteur sint occaecat
220 cupidatat non proident, sunt in culpa qui officia deserunt
221 mollit anim id est laborum.
223 /* { dg-begin-multiline-output "" }
226 Lorem ipsum dolor sit amet, consectetur adipiscing elit,
227 ^~~~~ ^~~~~ ^~~~~ ^~~ ^~~~ ^~~~~~~~~~~ ^~~~~~~~~~ ^~~~
228 LOREM IPSUM DOLOR SIT AMET CONSECTETUR ADIPISCING ELIT
229 sed do eiusmod tempor incididunt ut labore et dolore magna
230 ^~~ ^~ ^~~~~~~ ^~~~~~ ^~~~~~~~~~ ^~ ^~~~~~ ^~ ^~~~~~ ^~~~~
231 SED DO EIUSMOD TEMPOR INCIDIDUNT UT LABORE ET DOLORE MAGNA
232 aliqua. Ut enim ad minim veniam, quis nostrud exercitation
233 ^~~~~~ ^~ ^~~~ ^~ ^~~~~ ^~~~~~ ^~~~ ^~~~~~~ ^~~~~~~~~~~~
234 ALIQUA UT ENIM AD MINIM VENIAM QUIS NOSTRUD EXERCITATION
235 ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis
236 ^~~~~~~ ^~~~~~~ ^~~~ ^~ ^~~~~~~ ^~ ^~ ^~~~~~~ ^~~~~~~~~ ^~~~
237 ULLAMCO LABORIS NISI UT ALIQUIP EX EA COMMODO CONSEQUAT DUIS
238 aute irure dolor in reprehenderit in voluptate velit esse cillum
239 ^~~~ ^~~~~ ^~~~~ ^~ ^~~~~~~~~~~~~ ^~ ^~~~~~~~~ ^~~~~ ^~~~ ^~~~~~
240 AUTE IRURE DOLOR IN REPREHENDERIT IN VOLUPTATE VELIT ESSE CILLUM
241 dolore eu fugiat nulla pariatur. Excepteur sint occaecat
242 ^~~~~~ ^~ ^~~~~~ ^~~~~ ^~~~~~~~ ^~~~~~~~~ ^~~~ ^~~~~~~~
243 DOLORE EU FUGIAT NULLA PARIATUR EXCEPTEUR SINT OCCAECAT
244 cupidatat non proident, sunt in culpa qui officia deserunt
245 ^~~~~~~~~ ^~~ ^~~~~~~~ ^~~~ ^~ ^~~~~ ^~~ ^~~~~~~ ^~~~~~~~
246 CUPIDATAT NON PROIDENT SUNT IN CULPA QUI OFFICIA DESERUNT
247 mollit anim id est laborum.
248 ^~~~~~ ^~~~ ^~ ^~~ ^~~~~~~
249 MOLLIT ANIM ID EST LABORUM
250 { dg-end-multiline-output "" } */
253 /* Unit test for rendering of fix-it hints that add new lines. */
255 void test_fixit_insert_newline (void)
257 #if 0
258 switch (op)
260 case 'a':
261 x = a;
262 case 'b': /* { dg-warning "newline insertion" } */
263 x = b;
265 /* { dg-begin-multiline-output "" }
266 + break;
267 case 'b':
268 ^~~~~~~~
269 { dg-end-multiline-output "" } */
270 #endif
273 /* Unit test for mutually-exclusive suggestions. */
275 void test_mutually_exclusive_suggestions (void)
277 #if 0
278 original; /* { dg-warning "warning 1" } */
279 /* { dg-warning "warning 2" "" { target *-*-* } .-1 } */
280 /* { dg-begin-multiline-output "" }
281 original;
282 ^~~~~~~~
283 replacement_1
284 { dg-end-multiline-output "" } */
285 /* { dg-begin-multiline-output "" }
286 original;
287 ^~~~~~~~
288 replacement_2
289 { dg-end-multiline-output "" } */
290 #endif