1 /* { dg-options "-fdiagnostics-show-caret" } */
2
3 /* Various versions of the same C error, with a variety of line spacing,
4 and of columns, to exercise the line-span handling in
5 diagnostic-show-locus.c (PR other/69554). */
6
7 /* All on one line. */
8
test_1(const char * p,const char * q)9 int test_1 (const char *p, const char *q)
10 {
11 return (p + 1) + (q + 1); /* { dg-error "invalid operands" } */
12 /* { dg-begin-multiline-output "" }
13 return (p + 1) + (q + 1);
14 ~~~~~~~ ^ ~~~~~~~
15 | |
16 | const char *
17 const char *
18 { dg-end-multiline-output "" } */
19 }
20
21 /* On separate lines, but without intervening lines.
22 This can be printed as a single span of lines. */
23
test_2(const char * p,const char * q)24 int test_2 (const char *p, const char *q)
25 {
26 return (p + 1)
27 + /* { dg-error "invalid operands" } */
28 (q + 1);
29 /* { dg-begin-multiline-output "" }
30 return (p + 1)
31 ~~~~~~~
32 |
33 const char *
34 +
35 ^
36 (q + 1);
37 ~~~~~~~
38 |
39 const char *
40 { dg-end-multiline-output "" } */
41 }
42
43 /* On separate lines, with an intervening line between lines 1 and 2.
44 This is printed as 2 "spans" of lines, broken up by the intervening
45 line. */
46
test_3(const char * p,const char * q)47 int test_3 (const char *p, const char *q)
48 {
49 return (p + 1) /* { dg-locus "10" } */
50
51 + /* { dg-error "invalid operands" } */
52 (q + 1);
53 /* { dg-locus "12" "" { target *-*-* } "51" } */
54 /* { dg-begin-multiline-output "" }
55 return (p + 1)
56 ~~~~~~~
57 |
58 const char *
59 { dg-end-multiline-output "" } */
60 /* { dg-begin-multiline-output "" }
61 +
62 ^
63 (q + 1);
64 ~~~~~~~
65 |
66 const char *
67 { dg-end-multiline-output "" } */
68 }
69
70 /* As above, but the intervening line is between lines 2 and 3,
71 so that the 2 spans are grouped the other way. */
72
test_4(const char * p,const char * q)73 int test_4 (const char *p, const char *q)
74 {
75 return (p + 1)
76 + /* { dg-error "invalid operands" } */
77
78 (q + 1); /* { dg-locus "14" } */
79 /* { dg-begin-multiline-output "" }
80 return (p + 1)
81 ~~~~~~~
82 |
83 const char *
84 +
85 ^
86 { dg-end-multiline-output "" } */
87 /* { dg-begin-multiline-output "" }
88 (q + 1);
89 ~~~~~~~
90 |
91 const char *
92 { dg-end-multiline-output "" } */
93 }
94
95 /* On separate lines, with intervening lines.
96 This is printed as 3 "spans" of lines, each span being an
97 individual line. */
98
test_5(const char * p,const char * q)99 int test_5 (const char *p, const char *q)
100 {
101 return (p + 1) /* { dg-locus "10" } */
102
103 + /* { dg-error "invalid operands" } */
104
105 (q + 1); /* { dg-locus "14" } */
106 /* { dg-locus "12" "" { target *-*-* } "103" } */
107 /* { dg-begin-multiline-output "" }
108 return (p + 1)
109 ~~~~~~~
110 |
111 const char *
112 { dg-end-multiline-output "" } */
113 /* { dg-begin-multiline-output "" }
114 +
115 ^
116 { dg-end-multiline-output "" } */
117 /* { dg-begin-multiline-output "" }
118 (q + 1);
119 ~~~~~~~
120 |
121 const char *
122 { dg-end-multiline-output "" } */
123 }
124
125 /* On separate lines, with numerous intervening lines.
126 This is printed as 3 "spans" of lines, each span being an
127 individual line. */
128
test_6(const char * p,const char * q)129 int test_6 (const char *p, const char *q)
130 {
131 return (p + 1) /* { dg-locus "10" } */
132 /* Lorem ipsum dolor sit amet, consectetur adipiscing elit.
133 Maecenas nisl sapien, rutrum non euismod et, rutrum ac felis.
134 Morbi nec nisi ipsum. Quisque pulvinar ante nec urna rhoncus,
135 a cursus nisi commodo. Praesent euismod neque lectus, at
136 dapibus ipsum gravida in. Pellentesque tempor massa eu viverra
137 feugiat. Proin eleifend pulvinar urna, ut dapibus metus vehicula
138 ac. Suspendisse rutrum finibus quam, ac dignissim diam blandit
139 maximus. In blandit viverra pulvinar. Praesent vel tellus
140 elementum, placerat lacus quis, ornare lectus. Donec ac
141 eleifend nulla, sit amet condimentum risus. Vestibulum aliquam
142 maximus ante non pellentesque. Praesent mollis ante in risus
143 feugiat hendrerit. Praesent feugiat maximus urna nec blandit. */
144 + /* { dg-error "invalid operands" } */
145 /* Vestibulum ac nunc eget enim tempor tristique. Suspendisse
146 potenti. Nam et sollicitudin enim. Morbi sed tincidunt lectus.
147 Sed facilisis velit at ante maximus feugiat. Sed vestibulum mi
148 id leo tempor, sed ullamcorper sapien efficitur. Vestibulum purus
149 lacus, dignissim non magna at, tincidunt luctus nisl. Cum sociis
150 natoque penatibus et magnis dis parturient montes, nascetur
151 ridiculus mus. Donec elit elit, laoreet a dolor quis, eleifend
152 dapibus metus. Proin lectus turpis, eleifend nec pharetra eu,
153 fermentum in lacus. Morbi sit amet mauris orci. Nam sagittis,
154 nibh vel fermentum dictum, purus ex hendrerit odio, feugiat
155 fringilla sapien elit vitae nisl. Fusce mattis commodo risus
156 nec convallis. */
157 (q + 1); /* { dg-locus "14" } */
158 /* { dg-locus "12" "" { target *-*-* } "144" } */
159 /* { dg-begin-multiline-output "" }
160 return (p + 1)
161 ~~~~~~~
162 |
163 const char *
164 { dg-end-multiline-output "" } */
165 /* { dg-begin-multiline-output "" }
166 +
167 ^
168 { dg-end-multiline-output "" } */
169 /* { dg-begin-multiline-output "" }
170 (q + 1);
171 ~~~~~~~
172 |
173 const char *
174 { dg-end-multiline-output "" } */
175 }
176