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