1 // Test is line- and column-sensitive. Run lines are below.
2
3 struct X {
4 X();
5 X(int);
6 X(int, int);
7 X(const X&);
8 };
9
getX(int value)10 X getX(int value) {
11 switch (value) {
12 case 1: return X(value);
13 case 2: return X(value, value);
14 case 3: return (X)value;
15 default: break;
16 }
17 return X();
18 }
19
20 struct Y {
21 int member;
22
23 X getX();
24 };
25
getX()26 X Y::getX() {
27 return member;
28 }
29
30 struct YDerived : Y {
getAnotherXYDerived31 X getAnotherX() { return member; }
32 };
33
test()34 void test() {
35 X foo;
36
37 try {
38 } catch (X e) {
39 X x;
40 }
41
42 struct LocalS {
43 void meth() {
44 int x;
45 ++x;
46 }
47 };
48 }
49
50 template <bool (*tfn)(X*)>
51 struct TS {
52 void foo();
53 };
54
55 template <bool (*tfn)(X*)>
foo()56 void TS<tfn>::foo() {}
57
58 template <typename T>
59 class TC {
60 void init();
61 };
62
63 template<> void TC<char>::init();
64
65 #define EXTERN_TEMPLATE(...) extern template __VA_ARGS__;
66 EXTERN_TEMPLATE(class TC<char>)
67
68 // RUN: c-index-test -cursor-at=%s:6:4 %s | FileCheck -check-prefix=CHECK-COMPLETION-1 %s
69 // CHECK-COMPLETION-1: CXXConstructor=X:6:3
70 // CHECK-COMPLETION-1-NEXT: Completion string: {TypedText X}{LeftParen (}{Placeholder int}{Comma , }{Placeholder int}{RightParen )}
71
72 // RUN: c-index-test -cursor-at=%s:31:16 %s | FileCheck -check-prefix=CHECK-COMPLETION-2 %s
73 // CHECK-COMPLETION-2: CXXMethod=getAnotherX:31:5 (Definition)
74 // CHECK-COMPLETION-2-NEXT: Completion string: {ResultType X}{TypedText getAnotherX}{LeftParen (}{RightParen )}
75
76 // RUN: c-index-test -cursor-at=%s:12:20 %s | FileCheck -check-prefix=CHECK-VALUE-REF %s
77 // RUN: c-index-test -cursor-at=%s:13:21 %s | FileCheck -check-prefix=CHECK-VALUE-REF %s
78 // RUN: c-index-test -cursor-at=%s:13:28 %s | FileCheck -check-prefix=CHECK-VALUE-REF %s
79 // RUN: c-index-test -cursor-at=%s:14:23 %s | FileCheck -check-prefix=CHECK-VALUE-REF %s
80 // CHECK-VALUE-REF: DeclRefExpr=value:10:12
81
82 // RUN: c-index-test -cursor-at=%s:12:18 %s | FileCheck -check-prefix=CHECK-CONSTRUCTOR1 %s
83 // RUN: c-index-test -cursor-at=%s:13:18 %s | FileCheck -check-prefix=CHECK-CONSTRUCTOR2 %s
84 // RUN: c-index-test -cursor-at=%s:14:19 %s | FileCheck -check-prefix=CHECK-CONSTRUCTOR1 %s
85 // RUN: c-index-test -cursor-at=%s:17:10 %s | FileCheck -check-prefix=CHECK-CONSTRUCTOR3 %s
86 // CHECK-TYPE-REF: TypeRef=struct X:3:8
87 // CHECK-CONSTRUCTOR1: CallExpr=X:5:3
88 // CHECK-CONSTRUCTOR2: CallExpr=X:6:3
89 // CHECK-CONSTRUCTOR3: CallExpr=X:4:3
90
91 // RUN: c-index-test -cursor-at=%s:23:3 %s | FileCheck -check-prefix=CHECK-RETTYPE %s
92 // RUN: c-index-test -cursor-at=%s:26:1 %s | FileCheck -check-prefix=CHECK-RETTYPE %s
93 // CHECK-RETTYPE: TypeRef=struct X:3:8
94
95 // RUN: c-index-test -cursor-at=%s:23:7 %s | FileCheck -check-prefix=CHECK-MEMFUNC-DECL %s
96 // CHECK-MEMFUNC-DECL: CXXMethod=getX:23:5
97 // RUN: c-index-test -cursor-at=%s:26:7 %s | FileCheck -check-prefix=CHECK-MEMFUNC-DEF %s
98 // CHECK-MEMFUNC-DEF: CXXMethod=getX:26:6
99
100 // RUN: c-index-test -cursor-at=%s:26:3 %s | FileCheck -check-prefix=CHECK-TYPEREF-Y %s
101 // CHECK-TYPEREF-Y: TypeRef=struct Y:20:8
102
103 // RUN: c-index-test -cursor-at=%s:27:10 %s | FileCheck -check-prefix=CHECK-IMPLICIT-MEMREF %s
104 // RUN: c-index-test -cursor-at=%s:31:28 %s | FileCheck -check-prefix=CHECK-IMPLICIT-MEMREF %s
105 // CHECK-IMPLICIT-MEMREF: MemberRefExpr=member:21:7
106
107 // RUN: c-index-test -cursor-at=%s:35:5 %s | FileCheck -check-prefix=CHECK-DECL %s
108 // CHECK-DECL: VarDecl=foo:35:5
109
110 // RUN: c-index-test -cursor-at=%s:21:3 %s | FileCheck -check-prefix=CHECK-MEMBER %s
111 // CHECK-MEMBER: FieldDecl=member:21:7 (Definition)
112 // CHECK-MEMBER-NEXT: Completion string: {ResultType int}{TypedText member}
113
114 // RUN: c-index-test -cursor-at=%s:38:12 -cursor-at=%s:39:5 %s | FileCheck -check-prefix=CHECK-CXXCATCH %s
115 // CHECK-CXXCATCH: TypeRef=struct X:3:8
116 // CHECK-CXXCATCH-NEXT: TypeRef=struct X:3:8
117
118 // RUN: c-index-test -test-load-source-usrs local %s | FileCheck -check-prefix=CHECK-USR %s
119 // CHECK-USR: get-cursor.cpp c:get-cursor.cpp@472@F@test#@e Extent=[38:12 - 38:15]
120 // CHECK-USR: get-cursor.cpp c:get-cursor.cpp@483@F@test#@x Extent=[39:5 - 39:8]
121
122 // RUN: c-index-test -cursor-at=%s:45:9 %s | FileCheck -check-prefix=CHECK-LOCALCLASS %s
123 // CHECK-LOCALCLASS: 45:9 DeclRefExpr=x:44:11 Extent=[45:9 - 45:10] Spelling=x ([45:9 - 45:10])
124
125 // RUN: c-index-test -cursor-at=%s:50:23 -cursor-at=%s:55:23 %s | FileCheck -check-prefix=CHECK-TEMPLPARAM %s
126 // CHECK-TEMPLPARAM: 50:23 TypeRef=struct X:3:8 Extent=[50:23 - 50:24] Spelling=struct X ([50:23 - 50:24])
127 // CHECK-TEMPLPARAM: 55:23 TypeRef=struct X:3:8 Extent=[55:23 - 55:24] Spelling=struct X ([55:23 - 55:24])
128
129 // RUN: c-index-test -cursor-at=%s:66:23 %s | FileCheck -check-prefix=CHECK-TEMPLSPEC %s
130 // CHECK-TEMPLSPEC: 66:23 ClassDecl=TC:66:23 (Definition) [Specialization of TC:59:7] Extent=[66:1 - 66:31] Spelling=TC ([66:23 - 66:25])
131