Douglas Gregor | 263b47b | 2010-01-25 16:12:32 +0000 | [diff] [blame] | 1 | typedef int T; |
| 2 | struct X { int a, b; }; |
| 3 | void f(int x) { |
| 4 | for (T y = x; T z = x; ++x) { |
| 5 | } |
| 6 | if (T *z2 = &x) { } |
| 7 | while (T *z3 = &x) { } |
| 8 | switch (T z4 = x) { |
| 9 | case 17: break; |
| 10 | } |
| 11 | } |
| 12 | |
Ted Kremenek | 3064ef9 | 2010-08-27 21:34:58 +0000 | [diff] [blame] | 13 | // Test handling of C++ base specifiers. |
| 14 | class A { |
| 15 | void doA(); |
| 16 | }; |
| 17 | |
| 18 | class B { |
| 19 | void doB(); |
| 20 | }; |
| 21 | |
| 22 | class C : public A, private B { |
| 23 | void doC(); |
| 24 | }; |
| 25 | |
| 26 | class D : virtual public C, virtual private A {}; |
| 27 | |
Douglas Gregor | 9480229 | 2010-09-02 21:20:16 +0000 | [diff] [blame] | 28 | namespace std { |
| 29 | class type_info { }; |
| 30 | } |
| 31 | |
| 32 | void test_exprs(C *c) { |
| 33 | int typeid_marker; |
| 34 | typeid(C); |
| 35 | typeid(c); |
Douglas Gregor | 6f7198f | 2010-09-02 22:09:03 +0000 | [diff] [blame] | 36 | typedef int Integer; |
| 37 | Integer *int_ptr; |
| 38 | int_ptr->Integer::~Integer(); |
Douglas Gregor | 9480229 | 2010-09-02 21:20:16 +0000 | [diff] [blame] | 39 | } |
| 40 | |
Douglas Gregor | 8ab670e | 2010-09-02 22:19:24 +0000 | [diff] [blame] | 41 | namespace N { |
| 42 | int f(int); |
| 43 | float f(float); |
Douglas Gregor | 1f7b590 | 2010-09-02 22:29:21 +0000 | [diff] [blame] | 44 | |
| 45 | template<typename T> T g(T); |
| 46 | template<typename T> T g(T*); |
Douglas Gregor | 8ab670e | 2010-09-02 22:19:24 +0000 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | template<typename T> |
| 50 | void test_dependent_exprs(T t) { |
| 51 | N::f(t); |
Douglas Gregor | 1f7b590 | 2010-09-02 22:29:21 +0000 | [diff] [blame] | 52 | typedef T type; |
| 53 | N::g<type>(t); |
Douglas Gregor | bfebed2 | 2010-09-03 17:24:10 +0000 | [diff] [blame] | 54 | type::template f<type*>(t); |
Douglas Gregor | 25d6362 | 2010-09-03 17:35:34 +0000 | [diff] [blame] | 55 | t->type::template f<type*>(); |
Douglas Gregor | 8ab670e | 2010-09-02 22:19:24 +0000 | [diff] [blame] | 56 | } |
| 57 | |
Douglas Gregor | aaa80b2 | 2010-09-03 18:01:25 +0000 | [diff] [blame^] | 58 | struct Y { |
| 59 | int f(int); |
| 60 | float f(float); |
| 61 | |
| 62 | template<typename T> T g(T); |
| 63 | template<typename T> T g(T*); |
| 64 | }; |
| 65 | |
| 66 | template<typename T> |
| 67 | void test_more_dependent_exprs(T t, Y y) { |
| 68 | y.Y::f(t); |
| 69 | typedef T type; |
| 70 | y.g<type>(t); |
| 71 | } |
| 72 | |
Douglas Gregor | 263b47b | 2010-01-25 16:12:32 +0000 | [diff] [blame] | 73 | // RUN: c-index-test -test-load-source all %s | FileCheck %s |
Ted Kremenek | 9a700d2 | 2010-05-12 06:16:13 +0000 | [diff] [blame] | 74 | // CHECK: load-stmts.cpp:1:13: TypedefDecl=T:1:13 (Definition) Extent=[1:13 - 1:14] |
| 75 | // CHECK: load-stmts.cpp:2:8: StructDecl=X:2:8 (Definition) Extent=[2:1 - 2:23] |
| 76 | // CHECK: load-stmts.cpp:2:16: FieldDecl=a:2:16 (Definition) Extent=[2:16 - 2:17] |
| 77 | // CHECK: load-stmts.cpp:2:19: FieldDecl=b:2:19 (Definition) Extent=[2:19 - 2:20] |
| 78 | // CHECK: load-stmts.cpp:3:6: FunctionDecl=f:3:6 (Definition) Extent=[3:6 - 11:2] |
| 79 | // CHECK: load-stmts.cpp:3:12: ParmDecl=x:3:12 (Definition) Extent=[3:8 - 3:13] |
| 80 | // CHECK: <invalid loc>:0:0: UnexposedStmt= Extent=[3:15 - 11:2] |
| 81 | // CHECK: <invalid loc>:0:0: UnexposedStmt= Extent=[4:3 - 5:4] |
| 82 | // CHECK: <invalid loc>:0:0: UnexposedStmt= Extent=[4:8 - 4:16] |
Daniel Dunbar | 8f0bf81 | 2010-02-14 08:32:51 +0000 | [diff] [blame] | 83 | // CHECK: load-stmts.cpp:4:10: VarDecl=y:4:10 (Definition) Extent=[4:8 - 4:15] |
| 84 | // CHECK: load-stmts.cpp:4:8: TypeRef=T:1:13 Extent=[4:8 - 4:9] |
| 85 | // CHECK: load-stmts.cpp:4:14: DeclRefExpr=x:3:12 Extent=[4:14 - 4:15] |
| 86 | // CHECK: load-stmts.cpp:4:19: VarDecl=z:4:19 (Definition) Extent=[4:17 - 4:24] |
| 87 | // CHECK: load-stmts.cpp:4:17: TypeRef=T:1:13 Extent=[4:17 - 4:18] |
| 88 | // CHECK: load-stmts.cpp:4:23: DeclRefExpr=x:3:12 Extent=[4:23 - 4:24] |
| 89 | // CHECK: load-stmts.cpp:4:19: UnexposedExpr=z:4:19 Extent=[4:19 - 4:20] |
| 90 | // CHECK: load-stmts.cpp:4:19: DeclRefExpr=z:4:19 Extent=[4:19 - 4:20] |
| 91 | // CHECK: load-stmts.cpp:4:26: UnexposedExpr= Extent=[4:26 - 4:29] |
| 92 | // CHECK: load-stmts.cpp:4:28: DeclRefExpr=x:3:12 Extent=[4:28 - 4:29] |
Ted Kremenek | 9a700d2 | 2010-05-12 06:16:13 +0000 | [diff] [blame] | 93 | // CHECK: <invalid loc>:0:0: UnexposedStmt= Extent=[4:31 - 5:4] |
| 94 | // CHECK: <invalid loc>:0:0: UnexposedStmt= Extent=[6:3 - 6:22] |
Daniel Dunbar | 8f0bf81 | 2010-02-14 08:32:51 +0000 | [diff] [blame] | 95 | // CHECK: load-stmts.cpp:6:10: VarDecl=z2:6:10 (Definition) Extent=[6:7 - 6:17] |
| 96 | // CHECK: load-stmts.cpp:6:7: TypeRef=T:1:13 Extent=[6:7 - 6:8] |
| 97 | // CHECK: load-stmts.cpp:6:15: UnexposedExpr= Extent=[6:15 - 6:17] |
| 98 | // CHECK: load-stmts.cpp:6:16: DeclRefExpr=x:3:12 Extent=[6:16 - 6:17] |
| 99 | // CHECK: load-stmts.cpp:6:10: UnexposedExpr=z2:6:10 Extent=[6:10 - 6:12] |
| 100 | // CHECK: load-stmts.cpp:6:10: DeclRefExpr=z2:6:10 Extent=[6:10 - 6:12] |
Ted Kremenek | 9a700d2 | 2010-05-12 06:16:13 +0000 | [diff] [blame] | 101 | // CHECK: <invalid loc>:0:0: UnexposedStmt= Extent=[6:19 - 6:22] |
| 102 | // CHECK: <invalid loc>:0:0: UnexposedStmt= Extent=[7:3 - 7:25] |
Daniel Dunbar | 8f0bf81 | 2010-02-14 08:32:51 +0000 | [diff] [blame] | 103 | // CHECK: load-stmts.cpp:7:13: VarDecl=z3:7:13 (Definition) Extent=[7:10 - 7:20] |
| 104 | // CHECK: load-stmts.cpp:7:10: TypeRef=T:1:13 Extent=[7:10 - 7:11] |
| 105 | // CHECK: load-stmts.cpp:7:18: UnexposedExpr= Extent=[7:18 - 7:20] |
| 106 | // CHECK: load-stmts.cpp:7:19: DeclRefExpr=x:3:12 Extent=[7:19 - 7:20] |
| 107 | // CHECK: load-stmts.cpp:7:13: UnexposedExpr=z3:7:13 Extent=[7:13 - 7:15] |
| 108 | // CHECK: load-stmts.cpp:7:13: DeclRefExpr=z3:7:13 Extent=[7:13 - 7:15] |
Ted Kremenek | 9a700d2 | 2010-05-12 06:16:13 +0000 | [diff] [blame] | 109 | // CHECK: <invalid loc>:0:0: UnexposedStmt= Extent=[7:22 - 7:25] |
| 110 | // CHECK: <invalid loc>:0:0: UnexposedStmt= Extent=[8:3 - 10:4] |
Daniel Dunbar | 8f0bf81 | 2010-02-14 08:32:51 +0000 | [diff] [blame] | 111 | // CHECK: load-stmts.cpp:8:13: VarDecl=z4:8:13 (Definition) Extent=[8:11 - 8:19] |
| 112 | // CHECK: load-stmts.cpp:8:11: TypeRef=T:1:13 Extent=[8:11 - 8:12] |
| 113 | // CHECK: load-stmts.cpp:8:18: DeclRefExpr=x:3:12 Extent=[8:18 - 8:19] |
| 114 | // CHECK: load-stmts.cpp:8:13: DeclRefExpr=z4:8:13 Extent=[8:13 - 8:15] |
Ted Kremenek | 9a700d2 | 2010-05-12 06:16:13 +0000 | [diff] [blame] | 115 | // CHECK: <invalid loc>:0:0: UnexposedStmt= Extent=[8:21 - 10:4] |
| 116 | // CHECK: <invalid loc>:0:0: UnexposedStmt= Extent=[9:3 - 9:17] |
Daniel Dunbar | 8f0bf81 | 2010-02-14 08:32:51 +0000 | [diff] [blame] | 117 | // CHECK: load-stmts.cpp:9:8: UnexposedExpr= Extent=[9:8 - 9:10] |
Ted Kremenek | 0f91f6a | 2010-05-13 00:25:00 +0000 | [diff] [blame] | 118 | // CHECK: <invalid loc>:0:0: UnexposedStmt= Extent=[9:12 - 9:17] |
Ted Kremenek | 3064ef9 | 2010-08-27 21:34:58 +0000 | [diff] [blame] | 119 | // CHECK: load-stmts.cpp:14:7: ClassDecl=A:14:7 (Definition) Extent=[14:1 - 16:2] |
| 120 | // CHECK: load-stmts.cpp:15:8: CXXMethod=doA:15:8 Extent=[15:8 - 15:13] |
| 121 | // CHECK: load-stmts.cpp:18:7: ClassDecl=B:18:7 (Definition) Extent=[18:1 - 20:2] |
| 122 | // CHECK: load-stmts.cpp:19:8: CXXMethod=doB:19:8 Extent=[19:8 - 19:13] |
| 123 | // CHECK: load-stmts.cpp:22:7: ClassDecl=C:22:7 (Definition) Extent=[22:1 - 24:2] |
| 124 | // CHECK: <invalid loc>:0:0: C++ base class specifier=class A:14:7 [access=public isVirtual=false] |
| 125 | // CHECK: <invalid loc>:0:0: C++ base class specifier=class B:18:7 [access=private isVirtual=false] |
| 126 | // CHECK: load-stmts.cpp:23:8: CXXMethod=doC:23:8 Extent=[23:8 - 23:13] |
| 127 | // CHECK: load-stmts.cpp:26:7: ClassDecl=D:26:7 (Definition) Extent=[26:1 - 26:49] |
| 128 | // CHECK: <invalid loc>:0:0: C++ base class specifier=class C:22:7 [access=public isVirtual=true] |
| 129 | // CHECK: <invalid loc>:0:0: C++ base class specifier=class A:14:7 [access=private isVirtual=true] |
Douglas Gregor | 9480229 | 2010-09-02 21:20:16 +0000 | [diff] [blame] | 130 | // CHECK: load-stmts.cpp:33:7: VarDecl=typeid_marker:33:7 (Definition) |
| 131 | // CHECK: load-stmts.cpp:34:10: TypeRef=class C:22:7 Extent=[34:10 - 34:11] |
| 132 | // CHECK: load-stmts.cpp:35:10: DeclRefExpr=c:32:20 Extent=[35:10 - 35:11] |
Douglas Gregor | 6f7198f | 2010-09-02 22:09:03 +0000 | [diff] [blame] | 133 | // CHECK: load-stmts.cpp:37:12: VarDecl=int_ptr:37:12 (Definition) Extent=[37:3 - 37:19] |
| 134 | // CHECK: load-stmts.cpp:37:3: TypeRef=Integer:36:15 Extent=[37:3 - 37:10] |
| 135 | // CHECK: load-stmts.cpp:38:3: DeclRefExpr=int_ptr:37:12 Extent=[38:3 - 38:10] |
| 136 | // CHECK: load-stmts.cpp:38:12: TypeRef=Integer:36:15 Extent=[38:12 - 38:19] |
| 137 | // CHECK: load-stmts.cpp:38:22: TypeRef=Integer:36:15 Extent=[38:22 - 38:29] |
Douglas Gregor | 1f7b590 | 2010-09-02 22:29:21 +0000 | [diff] [blame] | 138 | // CHECK: load-stmts.cpp:50:6: FunctionTemplate=test_dependent_exprs:50:6 (Definition) |
| 139 | // CHECK: load-stmts.cpp:51:3: CallExpr= Extent=[51:3 - 51:10] |
| 140 | // CHECK: load-stmts.cpp:51:3: NamespaceRef=N:41:11 Extent=[51:3 - 51:4] |
| 141 | // CHECK: load-stmts.cpp:51:8: DeclRefExpr=t:50:29 Extent=[51:8 - 51:9] |
| 142 | // CHECK: load-stmts.cpp:52:13: TypedefDecl=type:52:13 (Definition) Extent=[52:13 - 52:17] |
| 143 | // CHECK: load-stmts.cpp:53:3: CallExpr= Extent=[53:3 - 53:16] |
| 144 | // CHECK: load-stmts.cpp:53:3: NamespaceRef=N:41:11 Extent=[53:3 - 53:4] |
| 145 | // CHECK: load-stmts.cpp:53:8: TypeRef=type:52:13 Extent=[53:8 - 53:12] |
| 146 | // CHECK: load-stmts.cpp:53:14: DeclRefExpr=t:50:29 Extent=[53:14 - 53:15] |
Douglas Gregor | bfebed2 | 2010-09-03 17:24:10 +0000 | [diff] [blame] | 147 | // CHECK: load-stmts.cpp:54:3: CallExpr= Extent=[54:3 - 54:29] |
| 148 | // CHECK: load-stmts.cpp:54:3: TypeRef=type:52:13 Extent=[54:3 - 54:7] |
| 149 | // CHECK: load-stmts.cpp:54:20: TypeRef=type:52:13 Extent=[54:20 - 54:24] |
| 150 | // CHECK: load-stmts.cpp:54:27: DeclRefExpr=t:50:29 Extent=[54:27 - 54:28] |
Douglas Gregor | 25d6362 | 2010-09-03 17:35:34 +0000 | [diff] [blame] | 151 | // CHECK: load-stmts.cpp:55:3: CallExpr= Extent=[55:3 - 55:31] |
| 152 | // CHECK: load-stmts.cpp:55:3: DeclRefExpr=t:50:29 Extent=[55:3 - 55:4] |
| 153 | // CHECK: load-stmts.cpp:55:23: TypeRef=type:52:13 Extent=[55:23 - 55:27] |
Douglas Gregor | aaa80b2 | 2010-09-03 18:01:25 +0000 | [diff] [blame^] | 154 | // CHECK: load-stmts.cpp:67:6: FunctionTemplate=test_more_dependent_exprs:67:6 (Definition) |
| 155 | // CHECK: load-stmts.cpp:68:3: CallExpr= Extent=[68:3 - 68:12] |
| 156 | // CHECK: load-stmts.cpp:68:3: DeclRefExpr=y:67:39 Extent=[68:3 - 68:4] |
| 157 | // CHECK: load-stmts.cpp:68:5: TypeRef=struct Y:58:8 Extent=[68:5 - 68:6] |
| 158 | // CHECK: load-stmts.cpp:68:10: DeclRefExpr=t:67:34 Extent=[68:10 - 68:11] |
| 159 | // CHECK: load-stmts.cpp:70:3: CallExpr= Extent=[70:3 - 70:15] |
| 160 | // CHECK: load-stmts.cpp:70:3: DeclRefExpr=y:67:39 Extent=[70:3 - 70:4] |
| 161 | // CHECK: load-stmts.cpp:70:7: TypeRef=type:69:13 Extent=[70:7 - 70:11] |
| 162 | // CHECK: load-stmts.cpp:70:13: DeclRefExpr=t:67:34 Extent=[70:13 - 70:14] |