]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/gcc.dg/plugin/diagnostic-test-show-locus-bw.c
513c0af772fa2c143d2c052c3b584516eb2f9caf
[thirdparty/gcc.git] / gcc / testsuite / gcc.dg / plugin / diagnostic-test-show-locus-bw.c
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
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
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
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 { dg-end-multiline-output "" } */
48 #endif
49 }
50
51 void test_many_lines (void)
52 {
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));
65
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
91 }
92
93 void test_richloc_from_proper_range (void)
94 {
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
102 }
103
104 void test_caret_within_proper_range (void)
105 {
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
113 }
114
115 void test_very_wide_line (void)
116 {
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 bar * foo
126 { dg-end-multiline-output "" } */
127 #endif
128 }
129
130 void test_multiple_carets (void)
131 {
132 #if 0
133 x = x + y /* { dg-warning "8: test" } */
134 /* { dg-begin-multiline-output "" }
135 x = x + y
136 A B
137 { dg-end-multiline-output "" } */
138 #endif
139 }
140
141 void test_caret_on_leading_whitespace (void)
142 {
143 #if 0
144 ASSOCIATE (y => x)
145 y = 5 /* { dg-warning "6: test" } */
146 /* { dg-begin-multiline-output "" }
147 ASSOCIATE (y => x)
148 2
149 y = 5
150 1
151 { dg-end-multiline-output "" } */
152 #endif
153 }
154
155 /* Unit test for rendering of insertion fixit hints
156 (example taken from PR 62316). */
157
158 void test_fixit_insert (void)
159 {
160 #if 0
161 int a[2][2] = { 0, 1 , 2, 3 }; /* { dg-warning "insertion hints" } */
162 /* { dg-begin-multiline-output "" }
163 int a[2][2] = { 0, 1 , 2, 3 };
164 ^~~~
165 { }
166 { dg-end-multiline-output "" } */
167 #endif
168 }
169
170 /* Unit test for rendering of "remove" fixit hints. */
171
172 void test_fixit_remove (void)
173 {
174 #if 0
175 int a;; /* { dg-warning "example of a removal hint" } */
176 /* { dg-begin-multiline-output "" }
177 int a;;
178 ^
179 -
180 { dg-end-multiline-output "" } */
181 #endif
182 }
183
184 /* Unit test for rendering of "replace" fixit hints. */
185
186 void test_fixit_replace (void)
187 {
188 #if 0
189 gtk_widget_showall (dlg); /* { dg-warning "example of a replacement hint" } */
190 /* { dg-begin-multiline-output "" }
191 gtk_widget_showall (dlg);
192 ^~~~~~~~~~~~~~~~~~
193 gtk_widget_show_all
194 { dg-end-multiline-output "" } */
195 #endif
196 }
197
198 /* Test of "%q+D" format code. */
199
200 int test_percent_q_plus_d (void)
201 {
202 int local = 0; /* { dg-warning "example of plus in format code" } */
203 /* { dg-begin-multiline-output "" }
204 int local = 0;
205 ^~~~~
206 { dg-end-multiline-output "" } */
207 return local;
208 }
209
210 /* Test of many nested locations and fixits. */
211
212 void test_many_nested_locations (void)
213 {
214 /* { dg-warning "test of 70 locations" }
215 Lorem ipsum dolor sit amet, consectetur adipiscing elit,
216 sed do eiusmod tempor incididunt ut labore et dolore magna
217 aliqua. Ut enim ad minim veniam, quis nostrud exercitation
218 ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis
219 aute irure dolor in reprehenderit in voluptate velit esse cillum
220 dolore eu fugiat nulla pariatur. Excepteur sint occaecat
221 cupidatat non proident, sunt in culpa qui officia deserunt
222 mollit anim id est laborum.
223 */
224 /* { dg-begin-multiline-output "" }
225 /*
226 ^
227 Lorem ipsum dolor sit amet, consectetur adipiscing elit,
228 ^~~~~ ^~~~~ ^~~~~ ^~~ ^~~~ ^~~~~~~~~~~ ^~~~~~~~~~ ^~~~
229 LOREM IPSUM DOLOR SIT AMET CONSECTETUR ADIPISCING ELIT
230 sed do eiusmod tempor incididunt ut labore et dolore magna
231 ^~~ ^~ ^~~~~~~ ^~~~~~ ^~~~~~~~~~ ^~ ^~~~~~ ^~ ^~~~~~ ^~~~~
232 SED DO EIUSMOD TEMPOR INCIDIDUNT UT LABORE ET DOLORE MAGNA
233 aliqua. Ut enim ad minim veniam, quis nostrud exercitation
234 ^~~~~~ ^~ ^~~~ ^~ ^~~~~ ^~~~~~ ^~~~ ^~~~~~~ ^~~~~~~~~~~~
235 ALIQUA UT ENIM AD MINIM VENIAM QUIS NOSTRUD EXERCITATION
236 ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis
237 ^~~~~~~ ^~~~~~~ ^~~~ ^~ ^~~~~~~ ^~ ^~ ^~~~~~~ ^~~~~~~~~ ^~~~
238 ULLAMCO LABORIS NISI UT ALIQUIP EX EA COMMODO CONSEQUAT DUIS
239 aute irure dolor in reprehenderit in voluptate velit esse cillum
240 ^~~~ ^~~~~ ^~~~~ ^~ ^~~~~~~~~~~~~ ^~ ^~~~~~~~~ ^~~~~ ^~~~ ^~~~~~
241 AUTE IRURE DOLOR IN REPREHENDERIT IN VOLUPTATE VELIT ESSE CILLUM
242 dolore eu fugiat nulla pariatur. Excepteur sint occaecat
243 ^~~~~~ ^~ ^~~~~~ ^~~~~ ^~~~~~~~ ^~~~~~~~~ ^~~~ ^~~~~~~~
244 DOLORE EU FUGIAT NULLA PARIATUR EXCEPTEUR SINT OCCAECAT
245 cupidatat non proident, sunt in culpa qui officia deserunt
246 ^~~~~~~~~ ^~~ ^~~~~~~~ ^~~~ ^~ ^~~~~ ^~~ ^~~~~~~ ^~~~~~~~
247 CUPIDATAT NON PROIDENT SUNT IN CULPA QUI OFFICIA DESERUNT
248 mollit anim id est laborum.
249 ^~~~~~ ^~~~ ^~ ^~~ ^~~~~~~
250 MOLLIT ANIM ID EST LABORUM
251 { dg-end-multiline-output "" } */
252 }
253
254 /* Unit test for rendering of fix-it hints that add new lines. */
255
256 void test_fixit_insert_newline (void)
257 {
258 #if 0
259 switch (op)
260 {
261 case 'a':
262 x = a;
263 case 'b': /* { dg-warning "newline insertion" } */
264 x = b;
265 }
266 /* { dg-begin-multiline-output "" }
267 + break;
268 case 'b':
269 ^~~~~~~~
270 { dg-end-multiline-output "" } */
271 #endif
272 }
273
274 /* Unit test for mutually-exclusive suggestions. */
275
276 void test_mutually_exclusive_suggestions (void)
277 {
278 #if 0
279 original; /* { dg-warning "warning 1" } */
280 /* { dg-warning "warning 2" "" { target *-*-* } .-1 } */
281 /* { dg-begin-multiline-output "" }
282 original;
283 ^~~~~~~~
284 replacement_1
285 { dg-end-multiline-output "" } */
286 /* { dg-begin-multiline-output "" }
287 original;
288 ^~~~~~~~
289 replacement_2
290 { dg-end-multiline-output "" } */
291 #endif
292 }