xref: /minix3/external/bsd/llvm/dist/clang/test/Index/index-refs.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc 
2*f4a2713aSLionel Sambuc namespace NS {
3*f4a2713aSLionel Sambuc   extern int gx;
4*f4a2713aSLionel Sambuc   typedef int MyInt;
5*f4a2713aSLionel Sambuc }
6*f4a2713aSLionel Sambuc 
7*f4a2713aSLionel Sambuc enum {
8*f4a2713aSLionel Sambuc   EnumVal = 1
9*f4a2713aSLionel Sambuc };
10*f4a2713aSLionel Sambuc 
11*f4a2713aSLionel Sambuc NS::MyInt NS::gx = EnumVal;
12*f4a2713aSLionel Sambuc 
13*f4a2713aSLionel Sambuc void foo() {
14*f4a2713aSLionel Sambuc   NS::MyInt x;
15*f4a2713aSLionel Sambuc }
16*f4a2713aSLionel Sambuc 
17*f4a2713aSLionel Sambuc enum {
18*f4a2713aSLionel Sambuc   SecondVal = EnumVal
19*f4a2713aSLionel Sambuc };
20*f4a2713aSLionel Sambuc 
21*f4a2713aSLionel Sambuc struct S {
22*f4a2713aSLionel Sambuc   S& operator++();
23*f4a2713aSLionel Sambuc   int operator*();
24*f4a2713aSLionel Sambuc   S& operator=(int x);
25*f4a2713aSLionel Sambuc   S& operator!=(int x);
26*f4a2713aSLionel Sambuc   S& operator()(int x);
27*f4a2713aSLionel Sambuc };
28*f4a2713aSLionel Sambuc 
29*f4a2713aSLionel Sambuc void foo2(S &s) {
30*f4a2713aSLionel Sambuc   (void)++s;
31*f4a2713aSLionel Sambuc   (void)*s;
32*f4a2713aSLionel Sambuc   s = 3;
33*f4a2713aSLionel Sambuc   (void)(s != 3);
34*f4a2713aSLionel Sambuc   s(3);
35*f4a2713aSLionel Sambuc }
36*f4a2713aSLionel Sambuc 
37*f4a2713aSLionel Sambuc namespace NS {
38*f4a2713aSLionel Sambuc   namespace Inn {}
39*f4a2713aSLionel Sambuc   typedef int Foo;
40*f4a2713aSLionel Sambuc }
41*f4a2713aSLionel Sambuc 
42*f4a2713aSLionel Sambuc using namespace NS;
43*f4a2713aSLionel Sambuc using namespace NS::Inn;
44*f4a2713aSLionel Sambuc using NS::Foo;
45*f4a2713aSLionel Sambuc 
46*f4a2713aSLionel Sambuc template <typename T1, typename T2>
47*f4a2713aSLionel Sambuc struct TS { };
48*f4a2713aSLionel Sambuc 
49*f4a2713aSLionel Sambuc template <typename T>
50*f4a2713aSLionel Sambuc struct TS<T, int> {
51*f4a2713aSLionel Sambuc   typedef int MyInt;
52*f4a2713aSLionel Sambuc };
53*f4a2713aSLionel Sambuc 
54*f4a2713aSLionel Sambuc void foo3() {
55*f4a2713aSLionel Sambuc   TS<int, int> s;
56*f4a2713aSLionel Sambuc }
57*f4a2713aSLionel Sambuc 
58*f4a2713aSLionel Sambuc const int array_size = 3;
59*f4a2713aSLionel Sambuc typedef int some_arr[array_size];
60*f4a2713aSLionel Sambuc 
61*f4a2713aSLionel Sambuc const int default_param = 3;
62*f4a2713aSLionel Sambuc void foo4(int p = default_param);
63*f4a2713aSLionel Sambuc 
64*f4a2713aSLionel Sambuc struct S2 {
65*f4a2713aSLionel Sambuc   int x,y;
66*f4a2713aSLionel Sambuc };
67*f4a2713aSLionel Sambuc 
68*f4a2713aSLionel Sambuc void foo5() {
69*f4a2713aSLionel Sambuc   struct S2 s = { .y = 1, .x = 4};
70*f4a2713aSLionel Sambuc }
71*f4a2713aSLionel Sambuc 
72*f4a2713aSLionel Sambuc // RUN: c-index-test -index-file %s | FileCheck %s
73*f4a2713aSLionel Sambuc // CHECK:      [indexDeclaration]: kind: namespace | name: NS
74*f4a2713aSLionel Sambuc // CHECK-NEXT: [indexDeclaration]: kind: variable | name: gx
75*f4a2713aSLionel Sambuc // CHECK-NEXT: [indexDeclaration]: kind: typedef | name: MyInt
76*f4a2713aSLionel Sambuc // CHECK-NEXT: [indexDeclaration]: kind: enum
77*f4a2713aSLionel Sambuc // CHECK-NEXT: [indexDeclaration]: kind: enumerator | name: EnumVal
78*f4a2713aSLionel Sambuc // CHECK-NEXT: [indexDeclaration]: kind: variable | name: gx
79*f4a2713aSLionel Sambuc // CHECK-NEXT: [indexEntityReference]: kind: namespace | name: NS
80*f4a2713aSLionel Sambuc // CHECK-NEXT: [indexEntityReference]: kind: typedef | name: MyInt
81*f4a2713aSLionel Sambuc // CHECK-NEXT: [indexEntityReference]: kind: namespace | name: NS
82*f4a2713aSLionel Sambuc // CHECK-NEXT: [indexEntityReference]: kind: enumerator | name: EnumVal
83*f4a2713aSLionel Sambuc // CHECK-NEXT: [indexDeclaration]: kind: function | name: foo
84*f4a2713aSLionel Sambuc // CHECK-NEXT: [indexEntityReference]: kind: namespace | name: NS
85*f4a2713aSLionel Sambuc // CHECK-NEXT: [indexEntityReference]: kind: typedef | name: MyInt
86*f4a2713aSLionel Sambuc // CHECK-NEXT: [indexDeclaration]: kind: enum
87*f4a2713aSLionel Sambuc // CHECK-NEXT: [indexDeclaration]: kind: enumerator | name: SecondVal
88*f4a2713aSLionel Sambuc // CHECK-NEXT: [indexEntityReference]: kind: enumerator | name: EnumVal
89*f4a2713aSLionel Sambuc 
90*f4a2713aSLionel Sambuc // CHECK:      [indexDeclaration]: kind: function | name: foo2
91*f4a2713aSLionel Sambuc // CHECK:      [indexEntityReference]: kind: c++-instance-method | name: operator++
92*f4a2713aSLionel Sambuc // CHECK-NEXT: [indexEntityReference]: kind: c++-instance-method | name: operator*
93*f4a2713aSLionel Sambuc // CHECK-NEXT: [indexEntityReference]: kind: c++-instance-method | name: operator=
94*f4a2713aSLionel Sambuc // CHECK-NEXT: [indexEntityReference]: kind: c++-instance-method | name: operator!=
95*f4a2713aSLionel Sambuc // CHECK-NEXT: [indexEntityReference]: kind: c++-instance-method | name: operator()
96*f4a2713aSLionel Sambuc 
97*f4a2713aSLionel Sambuc // CHECK:      [indexEntityReference]: kind: namespace | name: NS | {{.*}} | loc: 42:17
98*f4a2713aSLionel Sambuc // CHECK-NEXT: [indexEntityReference]: kind: namespace | name: NS | {{.*}} | loc: 43:17
99*f4a2713aSLionel Sambuc // CHECK-NEXT: [indexEntityReference]: kind: namespace | name: Inn | {{.*}} | loc: 43:21
100*f4a2713aSLionel Sambuc // CHECK-NEXT: [indexEntityReference]: kind: namespace | name: NS | {{.*}} | loc: 44:7
101*f4a2713aSLionel Sambuc // CHECK-NEXT: [indexEntityReference]: kind: typedef | name: Foo | {{.*}} | loc: 44:11
102*f4a2713aSLionel Sambuc 
103*f4a2713aSLionel Sambuc // CHECK:      [indexDeclaration]: kind: c++-class-template | name: TS | {{.*}} | loc: 47:8
104*f4a2713aSLionel Sambuc // CHECK-NEXT: [indexDeclaration]: kind: struct-template-partial-spec | name: TS | USR: c:@SP>1#T@TS>#t0.0#I | {{.*}} | loc: 50:8
105*f4a2713aSLionel Sambuc // CHECK-NEXT: [indexDeclaration]: kind: typedef | name: MyInt | USR: c:index-refs.cpp@593@SP>1#T@TS>#t0.0#I@T@MyInt | {{.*}} | loc: 51:15 | semantic-container: [TS:50:8] | lexical-container: [TS:50:8]
106*f4a2713aSLionel Sambuc /* when indexing implicit instantiations
107*f4a2713aSLionel Sambuc   [indexDeclaration]: kind: struct-template-spec | name: TS | USR: c:@S@TS>#I | {{.*}} | loc: 50:8
108*f4a2713aSLionel Sambuc   [indexDeclaration]: kind: typedef | name: MyInt | USR: c:index-refs.cpp@593@S@TS>#I@T@MyInt | {{.*}} | loc: 51:15 | semantic-container: [TS:50:8] | lexical-container: [TS:50:8]
109*f4a2713aSLionel Sambuc  */
110*f4a2713aSLionel Sambuc // CHECK-NEXT: [indexDeclaration]: kind: function | name: foo3
111*f4a2713aSLionel Sambuc /* when indexing implicit instantiations
112*f4a2713aSLionel Sambuc   [indexEntityReference]: kind: struct-template-spec | name: TS | USR: c:@S@TS>#I | {{.*}} | loc: 55:3
113*f4a2713aSLionel Sambuc */
114*f4a2713aSLionel Sambuc // CHECK-NEXT: [indexEntityReference]: kind: c++-class-template | name: TS | USR: c:@ST>2#T#T@TS | {{.*}} | loc: 55:3
115*f4a2713aSLionel Sambuc 
116*f4a2713aSLionel Sambuc // CHECK:      [indexEntityReference]: kind: variable | name: array_size | {{.*}} | loc: 59:22
117*f4a2713aSLionel Sambuc // CHECK:      [indexEntityReference]: kind: variable | name: default_param | {{.*}} | loc: 62:19
118*f4a2713aSLionel Sambuc // CHECK-NOT:  [indexEntityReference]: kind: variable | name: default_param | {{.*}} | loc: 62:19
119*f4a2713aSLionel Sambuc 
120*f4a2713aSLionel Sambuc // CHECK:      [indexEntityReference]: kind: field | name: y | {{.*}} | loc: 69:20
121*f4a2713aSLionel Sambuc // CHECK-NEXT: [indexEntityReference]: kind: field | name: x | {{.*}} | loc: 69:28
122