llvm-project
314 строк · 5.3 Кб
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_WARN9// expected-no-diagnostics
10#endif11
12void f0(int i) {13if (i)14#ifdef WITH_WARN15// expected-note@-2 {{here}}
16#endif17i = i + 1;18int x = 0;19#ifdef WITH_WARN20// expected-warning@-2 {{misleading indentation; statement is not part of the previous 'if'}}
21#endif22return;23#ifdef CXX1724if constexpr (false)25#ifdef WITH_WARN26// expected-note@-2 {{here}}
27#endif28i = 0;29i += 1;30#ifdef WITH_WARN31// expected-warning@-2 {{misleading indentation; statement is not part of the previous 'if'}}
32#endif33#endif34}
35
36void f1(int i) {37for (;i;)38#ifdef WITH_WARN39// expected-note@-2 {{here}}
40#endif41i = i + 1;42i *= 2;43#ifdef WITH_WARN44// expected-warning@-2 {{misleading indentation; statement is not part of the previous 'for'}}
45#endif46return;47}
48
49void f2(int i) {50while (i)51#ifdef WITH_WARN52// expected-note@-2 {{here}}
53#endif54i = i + 1; i *= 2;55#ifdef WITH_WARN56// expected-warning@-2 {{misleading indentation; statement is not part of the previous 'while'}}
57#endif58return;59}
60
61void f3(int i) {62if (i)63i = i + 1;64else65#ifdef WITH_WARN66// expected-note@-2 {{here}}
67#endif68i *= 2;69const int x = 0;70#ifdef WITH_WARN71// expected-warning@-2 {{misleading indentation; statement is not part of the previous 'else'}}
72#endif73}
74
75#ifdef CXX1776struct Range {77int *begin() {return nullptr;}78int *end() {return nullptr;}79};80#endif81
82void f4(int i) {83if (i)84i *= 2;85return;86if (i)87i *= 2;88;89if (i)90#ifdef WITH_WARN91// expected-note@-2 {{here}}
92#endif93i *= 2;94typedef int Int;95#ifdef WITH_WARN96// expected-warning@-2 {{misleading indentation; statement is not part of the previous 'if'}}
97#endif98#ifdef CXX1799Range R;100for (auto e : R)101#ifdef WITH_WARN102// expected-note@-2 {{here}}
103#endif104i *= 2;105using Int2 = int;106#ifdef WITH_WARN107// expected-warning@-2 {{misleading indentation; statement is not part of the previous 'for'}}
108#endif109#endif110}
111
112int bar(void);113
114int foo(int* dst)115{116if (dst)117return118bar();119if (dst)120dst = dst + \121bar();122return 0;123}
124
125void g(int i) {126if (1)127i = 2;128else129if (i == 3)130#ifdef WITH_WARN131// expected-note@-3 {{here}}
132#endif133i = 4;134i = 5;135#ifdef WITH_WARN136// expected-warning@-2 {{misleading indentation; statement is not part of the previous 'if'}}
137#endif138}
139
140// Or this
141#define TEST i = 5142void g0(int i) {143if (1)144i = 2;145else146i = 5;147TEST;148}
149
150void g1(int i) {151if (1)152i = 2;153else if (i == 3)154#ifdef WITH_WARN155// expected-note@-2 {{here}}
156#endif157i = 4;158i = 5;159#ifdef WITH_WARN160// expected-warning@-2 {{misleading indentation; statement is not part of the previous 'if'}}
161#endif162}
163
164void g2(int i) {165if (1)166i = 2;167else168if (i == 3)169{i = 4;}170i = 5;171}
172
173void g6(int i) {174if (1)175if (i == 3)176#ifdef WITH_WARN177// expected-note@-2 {{here}}
178#endif179i = 4;180i = 5;181#ifdef WITH_WARN182// expected-warning@-2 {{misleading indentation; statement is not part of the previous 'if'}}
183#endif184}
185
186void g7(int i) {187if (1)188i = 4;189#ifdef TEST1190#endif191i = 5;192}
193
194void a1(int i) { if (1) i = 4; return; }195
196void a2(int i) {197{198if (1)199i = 4;200}201return;202}
203
204void a3(int i) {205if (1)206{207i = 4;208}209return;210}
211
212void s(int num) {213{214if (1)215return;216else217return;218return;219}220if (0)221#ifdef WITH_WARN222// expected-note@-2 {{here}}
223#endif224return;225return;226#ifdef WITH_WARN227// expected-warning@-2 {{misleading indentation; statement is not part of the previous 'if'}}
228#endif229}
230int a4(void)231{
232if (0)233return 1;234return 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#endif239}
240
241int a5(void)242{
243if (0)244return 1;245return 0;246#if WITH_WARN247// expected-warning@-2 {{misleading indentation; statement is not part of the previous 'if'}}
248// expected-note@-5 {{here}}
249#endif250}
251
252int a6(void)253{
254if (0)255return 1;256return 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#endif261}
262
263#define FOO \264goto fail265
266int main(int argc, char* argv[]) {267if (5 != 0)268goto fail;269else270goto fail;271
272if (1) {273if (1)274goto fail;275else if (1)276goto fail;277else if (1)278goto fail;279else280goto fail;281} else if (1) {282if (1)283goto fail;284}285
286if (1) {287if (1)288goto fail;289} else if (1)290goto fail;291
292
293if (1) goto fail; goto fail;294
295if (0)296goto fail;297
298goto fail;299
300if (0)301FOO;302
303goto fail;304
305fail:;306}
307
308void f_label(int b) {309if (b)310return;311a:312return;313goto a;314}
315