• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // RUN: %clang_cc1 -x c -fsyntax-only -verify %s
2 // RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify -Wall -Wno-unused -Wno-misleading-indentation -DCXX17 %s
3 // RUN: %clang_cc1 -x c -fsyntax-only -verify -Wmisleading-indentation -DWITH_WARN -ftabstop 8 -DTAB_SIZE=8 %s
4 // RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify -Wall -Wno-unused -DWITH_WARN  -ftabstop 4 -DTAB_SIZE=4 -DCXX17 %s
5 // RUN: %clang_cc1 -x c -fsyntax-only -verify -Wall -Wno-unused -DWITH_WARN -ftabstop 1 -DTAB_SIZE=1 %s
6 // RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify -Wall -Wno-unused -Wmisleading-indentation -DCXX17 -DWITH_WARN -ftabstop 2 -DTAB_SIZE=2 %s
7 
8 #ifndef WITH_WARN
9 // expected-no-diagnostics
10 #endif
11 
f0(int i)12 void f0(int i) {
13   if (i)
14 #ifdef WITH_WARN
15 // expected-note@-2 {{here}}
16 #endif
17     i = i + 1;
18     int x = 0;
19 #ifdef WITH_WARN
20 // expected-warning@-2 {{misleading indentation; statement is not part of the previous 'if'}}
21 #endif
22   return;
23 #ifdef CXX17
24   if constexpr (false)
25 #ifdef WITH_WARN
26 // expected-note@-2 {{here}}
27 #endif
28     i = 0;
29     i += 1;
30 #ifdef WITH_WARN
31 // expected-warning@-2 {{misleading indentation; statement is not part of the previous 'if'}}
32 #endif
33 #endif
34 }
35 
f1(int i)36 void f1(int i) {
37   for (;i;)
38 #ifdef WITH_WARN
39 // expected-note@-2 {{here}}
40 #endif
41     i = i + 1;
42     i *= 2;
43 #ifdef WITH_WARN
44 // expected-warning@-2 {{misleading indentation; statement is not part of the previous 'for'}}
45 #endif
46   return;
47 }
48 
f2(int i)49 void f2(int i) {
50   while (i)
51 #ifdef WITH_WARN
52 // expected-note@-2 {{here}}
53 #endif
54     i = i + 1; i *= 2;
55 #ifdef WITH_WARN
56 // expected-warning@-2 {{misleading indentation; statement is not part of the previous 'while'}}
57 #endif
58   return;
59 }
60 
f3(int i)61 void f3(int i) {
62   if (i)
63     i = i + 1;
64   else
65 #ifdef WITH_WARN
66 // expected-note@-2 {{here}}
67 #endif
68     i *= 2;
69     const int x = 0;
70 #ifdef WITH_WARN
71 // expected-warning@-2 {{misleading indentation; statement is not part of the previous 'else'}}
72 #endif
73 }
74 
75 #ifdef CXX17
76 struct Range {
beginRange77   int *begin() {return nullptr;}
endRange78   int *end() {return nullptr;}
79 };
80 #endif
81 
f4(int i)82 void f4(int i) {
83   if (i)
84   i *= 2;
85   return;
86   if (i)
87     i *= 2;
88     ;
89   if (i)
90 #ifdef WITH_WARN
91 // expected-note@-2 {{here}}
92 #endif
93     i *= 2;
94     typedef int Int;
95 #ifdef WITH_WARN
96 // expected-warning@-2 {{misleading indentation; statement is not part of the previous 'if'}}
97 #endif
98 #ifdef CXX17
99   Range R;
100   for (auto e : R)
101 #ifdef WITH_WARN
102 // expected-note@-2 {{here}}
103 #endif
104     i *= 2;
105     using Int2 = int;
106 #ifdef WITH_WARN
107 // expected-warning@-2 {{misleading indentation; statement is not part of the previous 'for'}}
108 #endif
109 #endif
110 }
111 
112 int bar(void);
113 
foo(int * dst)114 int foo(int* dst)
115 {
116     if (dst)
117        return
118     bar();
119   if (dst)
120     dst = dst + \
121     bar();
122   return 0;
123 }
124 
g(int i)125 void g(int i) {
126   if (1)
127     i = 2;
128   else
129          if (i == 3)
130 #ifdef WITH_WARN
131 // expected-note@-3 {{here}}
132 #endif
133     i = 4;
134     i = 5;
135 #ifdef WITH_WARN
136 // expected-warning@-2 {{misleading indentation; statement is not part of the previous 'if'}}
137 #endif
138 }
139 
140 // Or this
141 #define TEST i = 5
g0(int i)142 void g0(int i) {
143   if (1)
144     i = 2;
145   else
146     i = 5;
147     TEST;
148 }
149 
g1(int i)150 void g1(int i) {
151   if (1)
152     i = 2;
153   else if (i == 3)
154 #ifdef WITH_WARN
155 // expected-note@-2 {{here}}
156 #endif
157       i = 4;
158       i = 5;
159 #ifdef WITH_WARN
160 // expected-warning@-2 {{misleading indentation; statement is not part of the previous 'if'}}
161 #endif
162 }
163 
g2(int i)164 void g2(int i) {
165   if (1)
166     i = 2;
167   else
168     if (i == 3)
169     {i = 4;}
170     i = 5;
171 }
172 
g6(int i)173 void g6(int i) {
174         if (1)
175                 if (i == 3)
176 #ifdef WITH_WARN
177 // expected-note@-2 {{here}}
178 #endif
179                         i = 4;
180                         i = 5;
181 #ifdef WITH_WARN
182 // expected-warning@-2 {{misleading indentation; statement is not part of the previous 'if'}}
183 #endif
184 }
185 
g7(int i)186 void g7(int i) {
187   if (1)
188     i = 4;
189 #ifdef TEST1
190 #endif
191     i = 5;
192 }
193 
a1(int i)194 void a1(int i) { if (1) i = 4; return; }
195 
a2(int i)196 void a2(int i) {
197   {
198     if (1)
199       i = 4;
200       }
201   return;
202 }
203 
a3(int i)204 void a3(int i) {
205   if (1)
206     {
207     i = 4;
208     }
209     return;
210 }
211 
s(int num)212 void s(int num) {
213     {
214         if (1)
215             return;
216         else
217             return;
218         return;
219     }
220     if (0)
221 #ifdef WITH_WARN
222 // expected-note@-2 {{here}}
223 #endif
224         return;
225         return;
226 #ifdef WITH_WARN
227 // expected-warning@-2 {{misleading indentation; statement is not part of the previous 'if'}}
228 #endif
229 }
a4()230 int a4()
231 {
232 	if (0)
233 		return 1;
234  	return 0;
235 #if (TAB_SIZE == 1)
236 // expected-warning@-2 {{misleading indentation; statement is not part of the previous 'if'}}
237 // expected-note@-5 {{here}}
238 #endif
239 }
240 
a5()241 int a5()
242 {
243 	if (0)
244 		return 1;
245 		return 0;
246 #if WITH_WARN
247 // expected-warning@-2 {{misleading indentation; statement is not part of the previous 'if'}}
248 // expected-note@-5 {{here}}
249 #endif
250 }
251 
a6()252 int a6()
253 {
254 	if (0)
255 		return 1;
256       		return 0;
257 #if (TAB_SIZE == 8)
258 // expected-warning@-2 {{misleading indentation; statement is not part of the previous 'if'}}
259 // expected-note@-5 {{here}}
260 #endif
261 }
262 
263 #define FOO \
264  goto fail
265 
main(int argc,char * argv[])266 int main(int argc, char* argv[]) {
267   if (5 != 0)
268     goto fail;
269   else
270     goto fail;
271 
272   if (1) {
273     if (1)
274       goto fail;
275     else if (1)
276       goto fail;
277     else if (1)
278       goto fail;
279     else
280       goto fail;
281   } else if (1) {
282     if (1)
283       goto fail;
284   }
285 
286   if (1) {
287     if (1)
288       goto fail;
289   } else if (1)
290     goto fail;
291 
292 
293   if (1) goto fail; goto fail;
294 
295     if (0)
296         goto fail;
297 
298     goto fail;
299 
300     if (0)
301         FOO;
302 
303     goto fail;
304 
305 fail:;
306 }
307 
f_label(int b)308 void f_label(int b) {
309   if (b)
310     return;
311     a:
312   return;
313   goto a;
314 }
315