xref: /llvm-project/clang/test/AST/loop-recovery.cpp (revision 7c1d9b15eee3a34678addab2bab66f3020ac0753)
1 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++17 %s
2 // RUN: not %clang_cc1 -ast-dump %s -std=c++17 | FileCheck %s
3 
test()4 void test() {
5   while(!!!) // expected-error {{expected expression}}
6     int whileBody;
7   // CHECK: WhileStmt
8   // CHECK: RecoveryExpr {{.*}} <line:{{.*}}:9, col:11> 'bool'
9   // CHECK: whileBody 'int'
10 
11   for(!!!) // expected-error {{expected expression}} expected-error {{expected ';'}}
12     int forBody;
13   // CHECK: ForStmt
14   // FIXME: the AST should have a RecoveryExpr to distinguish from for(;;)
15   // CHECK-NOT: RecoveryExpr
16   // CHECK: forBody 'int'
17 
18   for(auto c : !!!) // expected-error {{expected expression}}
19     int forEachBody;
20   // FIXME: parse the foreach body
21   // CHECK-NOT: CXXForRangeStmt
22   // CHECK-NOT: forEachBody 'int'
23 
24   do
25     int doBody;
26   while(!!!); // expected-error {{expected expression}}
27   // CHECK: DoStmt
28   // CHECK: doBody 'int'
29   // CHECK: RecoveryExpr {{.*}} <line:{{.*}}:9, col:11> 'bool'
30 
31   if(!!!) // expected-error {{expected expression}}
32     int ifBody;
33   else
34     int elseBody;
35   // CHECK: IfStmt
36   // CHECK: RecoveryExpr {{.*}} <line:{{.*}}:6, col:8> 'bool'
37   // CHECK: ifBody 'int'
38   // CHECK: elseBody 'int'
39 
40   switch(!!!) // expected-error {{expected expression}}
41     int switchBody;
42   // CHECK: SwitchStmt
43   // CHECK: RecoveryExpr {{.*}} <line:{{.*}}:10, col:12> 'int'
44   // CHECK: switchBody 'int'
45 
46   switch (;) // expected-error {{expected expression}}
47     int switchBody;
48   // CHECK: SwitchStmt
49   // CHECK: NullStmt
50   // CHECK: RecoveryExpr {{.*}} <col:11> 'int'
51   // CHECK: switchBody 'int'
52 
53   switch (;;) // expected-error {{expected expression}}
54     int switchBody;
55   // CHECK: SwitchStmt
56   // CHECK: NullStmt
57   // CHECK: RecoveryExpr {{.*}} <col:11, col:12> 'int'
58   // CHECK: switchBody 'int'
59 
60   switch (!!!;) // expected-error {{expected expression}}
61     int switchBody;
62   // CHECK: SwitchStmt
63   // CHECK: RecoveryExpr {{.*}} <line:{{.*}}:11, col:14> 'int'
64   // CHECK: switchBody 'int'
65 }
66