index-templates.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. // Test is line- and column-sensitive. See run lines below.
  2. template<typename T, T Value, template<typename U, U ValU> class X>
  3. void f(X<T, Value> x);
  4. template<typename T> class allocator;
  5. template<typename T, typename Alloc = allocator<T> >
  6. class vector {
  7. void clear();
  8. };
  9. template<typename T>
  10. class vector<T*> { };
  11. struct Z1 { };
  12. template class vector<Z1>;
  13. struct Z2 { };
  14. template<>
  15. class vector<Z2> {
  16. void clear();
  17. };
  18. template<typename T, typename U>
  19. struct Y {
  20. using typename T::type;
  21. using U::operator Z2;
  22. };
  23. struct Z3 { };
  24. const unsigned OneDimension = 1;
  25. template<typename T, unsigned Dimensions = OneDimension>
  26. struct array { };
  27. template<template<typename, unsigned> class DataStructure = array>
  28. struct storage { };
  29. typedef unsigned Unsigned;
  30. template<typename T, Unsigned Value>
  31. struct value_c;
  32. template class vector<int*>;
  33. struct Z4 {
  34. template<typename T> T getAs();
  35. };
  36. void template_exprs() {
  37. f<Unsigned, OneDimension, array>(array<Unsigned, OneDimension>());
  38. Z4().getAs<Unsigned>();
  39. }
  40. template<typename T> void swap(T&, T&);
  41. template<typename T, typename U> void swap(Y<T, U>&, Y<T, U>&);
  42. void swap(Z4&, Z4&);
  43. struct Z5 {
  44. int f(int);
  45. float f(float);
  46. };
  47. template<typename T>
  48. void unresolved_exprs(T &x) {
  49. swap(x, x);
  50. Z5 z5;
  51. z5.f(x);
  52. swap<T>(x, x);
  53. }
  54. template<typename T, typename U>
  55. struct Pair {
  56. T first;
  57. U second;
  58. };
  59. template<typename T, typename U>
  60. void init_list(T t, U u) {
  61. typedef U second_type;
  62. Pair<T, U> p = { t, second_type(u) };
  63. }
  64. template<typename T>
  65. struct compare { };
  66. template<typename Key, typename Value,
  67. typename Comparison = compare<Pair<Key, Value> >,
  68. typename Allocator = allocator<Pair<Key, Value> > >
  69. struct map;
  70. void f(map<Z4, Pair<int, Z4> >);
  71. template class Pair<int, int>;
  72. template<typename T, typename U>
  73. struct SuperPair : Pair<int, int>, Pair<T, U> { };
  74. enum FxnTmplEnum {
  75. FxnTmplEnum_A, FxnTmplEnum_B, FxnTmplEnum_C,
  76. };
  77. template <typename T, int I, FxnTmplEnum, int E>
  78. void foo(T Value) {}
  79. static const int FxnTmpl_Var = 7;
  80. template <>
  81. void foo<float, 9, FxnTmplEnum_B, FxnTmpl_Var + 7>(float Value);
  82. // RUN: c-index-test -test-load-source all -fno-delayed-template-parsing %s | FileCheck -check-prefix=CHECK-LOAD %s
  83. // CHECK-LOAD: index-templates.cpp:4:6: FunctionTemplate=f:4:6 Extent=[3:1 - 4:22]
  84. // CHECK-LOAD: index-templates.cpp:3:19: TemplateTypeParameter=T:3:19 (Definition) Extent=[3:10 - 3:20]
  85. // CHECK-LOAD: index-templates.cpp:3:24: NonTypeTemplateParameter=Value:3:24 (Definition) Extent=[3:22 - 3:29]
  86. // FIXME: Need the template type parameter here
  87. // CHECK-LOAD: index-templates.cpp:3:66: TemplateTemplateParameter=X:3:66 (Definition) Extent=[3:31 - 3:67]
  88. // CHECK-LOAD: index-templates.cpp:4:20: ParmDecl=x:4:20 (Definition) Extent=[4:8 - 4:21]
  89. // CHECK-LOAD: index-templates.cpp:4:8: TemplateRef=X:3:66 Extent=[4:8 - 4:9]
  90. // FIXME: Need the template type parameter here
  91. // CHECK-LOAD: index-templates.cpp:4:13: DeclRefExpr=Value:3:24 Extent=[4:13 - 4:18]
  92. // CHECK-LOAD: index-templates.cpp:6:28: ClassTemplate=allocator:6:28 Extent=[6:1 - 6:37]
  93. // CHECK-LOAD: index-templates.cpp:6:19: TemplateTypeParameter=T:6:19 (Definition) Extent=[6:10 - 6:20]
  94. // CHECK-LOAD: index-templates.cpp:9:7: ClassTemplate=vector:9:7 (Definition) Extent=[8:1 - 11:2]
  95. // CHECK-LOAD: index-templates.cpp:8:19: TemplateTypeParameter=T:8:19 (Definition) Extent=[8:10 - 8:20]
  96. // CHECK-LOAD: index-templates.cpp:8:31: TemplateTypeParameter=Alloc:8:31 (Definition) Extent=[8:22 - 8:51]
  97. // CHECK-LOAD: index-templates.cpp:8:39: TemplateRef=allocator:6:28 Extent=[8:39 - 8:48]
  98. // CHECK-LOAD: index-templates.cpp:10:8: CXXMethod=clear:10:8 Extent=[10:3 - 10:15]
  99. // CHECK-LOAD: index-templates.cpp:14:7: ClassTemplatePartialSpecialization=vector:14:7 (Definition) [Specialization of vector:9:7] Extent=[13:1 - 14:21]
  100. // CHECK-LOAD: index-templates.cpp:13:19: TemplateTypeParameter=T:13:19 (Definition) Extent=[13:10 - 13:20]
  101. // CHECK-LOAD: index-templates.cpp:16:8: StructDecl=Z1:16:8 (Definition) Extent=[16:1 - 16:14]
  102. // CHECK-LOAD: index-templates.cpp:18:16: ClassDecl=vector:18:16 (Definition) [Specialization of vector:9:7] Extent=[18:1 - 18:26]
  103. // CHECK-LOAD: index-templates.cpp:18:23: TypeRef=struct Z1:16:8 Extent=[18:23 - 18:25]
  104. // CHECK-LOAD-NOT: CXXMethod=clear
  105. // CHECK-LOAD: index-templates.cpp:20:8: StructDecl=Z2:20:8 (Definition) Extent=[20:1 - 20:14]
  106. // CHECK-LOAD: index-templates.cpp:23:7: ClassDecl=vector:23:7 (Definition) [Specialization of vector:9:7] Extent=[22:1 - 25:2]
  107. // CHECK-LOAD: index-templates.cpp:23:14: TypeRef=struct Z2:20:8 Extent=[23:14 - 23:16]
  108. // CHECK-LOAD: index-templates.cpp:24:8: CXXMethod=clear:24:8 Extent=[24:3 - 24:15]
  109. // CHECK-LOAD: index-templates.cpp:28:8: ClassTemplate=Y:28:8 (Definition) Extent=[27:1 - 31:2]
  110. // CHECK-LOAD: index-templates.cpp:27:19: TemplateTypeParameter=T:27:19 (Definition) Extent=[27:10 - 27:20]
  111. // CHECK-LOAD: index-templates.cpp:27:31: TemplateTypeParameter=U:27:31 (Definition) Extent=[27:22 - 27:32]
  112. // CHECK-LOAD: index-templates.cpp:29:21: UsingDeclaration=type:29:21 Extent=[29:3 - 29:25]
  113. // CHECK-LOAD: index-templates.cpp:30:12: UsingDeclaration=operator Z2:30:12 Extent=[30:3 - 30:23]
  114. // CHECK-LOAD: index-templates.cpp:30:21: TypeRef=struct Z2:20:8 Extent=[30:21 - 30:23]
  115. // CHECK-LOAD: index-templates.cpp:35:16: VarDecl=OneDimension:35:16 (Definition) Extent=[35:1 - 35:32]
  116. // CHECK-LOAD: index-templates.cpp:35:31: UnexposedExpr= Extent=[35:31 - 35:32]
  117. // CHECK-LOAD: index-templates.cpp:35:31: IntegerLiteral= Extent=[35:31 - 35:32]
  118. // CHECK-LOAD: index-templates.cpp:37:8: ClassTemplate=array:37:8 (Definition) Extent=[36:1 - 37:17]
  119. // CHECK-LOAD: index-templates.cpp:36:19: TemplateTypeParameter=T:36:19 (Definition) Extent=[36:10 - 36:20]
  120. // CHECK-LOAD: index-templates.cpp:36:31: NonTypeTemplateParameter=Dimensions:36:31 (Definition) Extent=[36:22 - 36:56]
  121. // CHECK-LOAD: index-templates.cpp:36:44: DeclRefExpr=OneDimension:35:16 Extent=[36:44 - 36:56]
  122. // CHECK-LOAD: index-templates.cpp:40:8: ClassTemplate=storage:40:8 (Definition) Extent=[39:1 - 40:19]
  123. // CHECK-LOAD: index-templates.cpp:39:45: TemplateTemplateParameter=DataStructure:39:45 (Definition) Extent=[39:10 - 39:66]
  124. // CHECK-LOAD: index-templates.cpp:39:19: TemplateTypeParameter=:39:19 (Definition) Extent=[39:19 - 39:27]
  125. // CHECK-LOAD: index-templates.cpp:39:37: NonTypeTemplateParameter=:39:37 (Definition) Extent=[39:29 - 39:37]
  126. // CHECK-LOAD: index-templates.cpp:39:61: TemplateRef=array:37:8 Extent=[39:61 - 39:66]
  127. // CHECK-LOAD: index-templates.cpp:42:18: TypedefDecl=Unsigned:42:18 (Definition) Extent=[42:1 - 42:26]
  128. // CHECK-LOAD: index-templates.cpp:45:8: ClassTemplate=value_c:45:8 Extent=[44:1 - 45:15]
  129. // CHECK-LOAD: index-templates.cpp:44:19: TemplateTypeParameter=T:44:19 (Definition) Extent=[44:10 - 44:20]
  130. // CHECK-LOAD: index-templates.cpp:44:31: NonTypeTemplateParameter=Value:44:31 (Definition) Extent=[44:22 - 44:36]
  131. // CHECK-LOAD: index-templates.cpp:44:22: TypeRef=Unsigned:42:18 Extent=[44:22 - 44:30]
  132. // CHECK-LOAD: index-templates.cpp:47:16: ClassDecl=vector:47:16 (Definition) [Specialization of vector:14:7] Extent=[47:1 - 47:28]
  133. // CHECK-LOAD: index-templates.cpp:49:8: StructDecl=Z4:49:8 (Definition) Extent=[49:1 - 51:2]
  134. // CHECK-LOAD: index-templates.cpp:50:26: FunctionTemplate=getAs:50:26 Extent=[50:3 - 50:33]
  135. // CHECK-LOAD: index-templates.cpp:50:21: TemplateTypeParameter=T:50:21 (Definition) Extent=[50:12 - 50:22]
  136. // CHECK-LOAD: index-templates.cpp:53:6: FunctionDecl=template_exprs:53:6 (Definition)
  137. // CHECK-LOAD: index-templates.cpp:54:3: CallExpr=f:4:6 Extent=[54:3 - 54:68]
  138. // CHECK-LOAD: index-templates.cpp:54:3: UnexposedExpr=f:4:6 Extent=[54:3 - 54:35]
  139. // CHECK-LOAD: index-templates.cpp:54:3: DeclRefExpr=f:4:6 RefName=[54:3 - 54:4] RefName=[54:4 - 54:35] Extent=[54:3 - 54:35]
  140. // CHECK-LOAD: index-templates.cpp:54:5: TypeRef=Unsigned:42:18 Extent=[54:5 - 54:13]
  141. // CHECK-LOAD: index-templates.cpp:54:15: DeclRefExpr=OneDimension:35:16 Extent=[54:15 - 54:27]
  142. // CHECK-LOAD: index-templates.cpp:54:29: TemplateRef=array:37:8 Extent=[54:29 - 54:34]
  143. // CHECK-LOAD: index-templates.cpp:55:8: MemberRefExpr=getAs:50:26 SingleRefName=[55:8 - 55:13] RefName=[55:8 - 55:13] Extent=[55:3 - 55:23]
  144. // CHECK-LOAD: index-templates.cpp:55:3: CallExpr=Z4:49:8 Extent=[55:3 - 55:7]
  145. // CHECK-LOAD: index-templates.cpp:55:14: TypeRef=Unsigned:42:18 Extent=[55:14 - 55:22]
  146. // CHECK-LOAD: index-templates.cpp:68:6: FunctionTemplate=unresolved_exprs:68:6 (Definition)
  147. // CHECK-LOAD: index-templates.cpp:69:3: OverloadedDeclRef=swap[60:6, 59:39, 58:27]
  148. // CHECK-LOAD: index-templates.cpp:71:6: OverloadedDeclRef=f[63:7, 64:9]
  149. // CHECK-LOAD: index-templates.cpp:72:3: OverloadedDeclRef=swap[58:27, 59:39]
  150. // CHECK-LOAD: index-templates.cpp:82:6: FunctionTemplate=init_list:82:6 (Definition)
  151. // CHECK-LOAD: index-templates.cpp:85:14: VarDecl=p:85:14 (Definition)
  152. // CHECK-LOAD: index-templates.cpp:85:20: DeclRefExpr=t:82:18 Extent=[85:20 - 85:21]
  153. // CHECK-LOAD: index-templates.cpp:85:23: TypeRef=second_type:83:13 Extent=[85:23 - 85:34]
  154. // CHECK-LOAD: index-templates.cpp:85:35: DeclRefExpr=u:82:23 Extent=[85:35 - 85:36]
  155. // CHECK-LOAD: index-templates.cpp:101:8: ClassTemplate=SuperPair:101:8 (Definition) Extent=[100:1 - 101:50]
  156. // CHECK-LOAD: index-templates.cpp:100:19: TemplateTypeParameter=T:100:19 (Definition) Extent=[100:10 - 100:20]
  157. // CHECK-LOAD: index-templates.cpp:100:31: TemplateTypeParameter=U:100:31 (Definition) Extent=[100:22 - 100:32]
  158. // CHECK-LOAD: index-templates.cpp:101:20: C++ base class specifier=Pair<int, int>:98:16 [access=public isVirtual=false] Extent=[101:20 - 101:34]
  159. // CHECK-LOAD: index-templates.cpp:101:36: C++ base class specifier=Pair<T, U>:76:8 [access=public isVirtual=false] Extent=[101:36 - 101:46]
  160. // CHECK-LOAD: index-templates.cpp:111:6: FunctionDecl=foo:111:6 [Specialization of foo:107:6] [Template arg 0: kind: 1, type: float] [Template arg 1: kind: 4, intval: 9] [Template arg 2: kind: 4, intval: 1] [Template arg 3: kind: 4, intval: 14] Extent=[110:1 - 111:64]
  161. // RUN: c-index-test -test-load-source-usrs all -fno-delayed-template-parsing %s | FileCheck -check-prefix=CHECK-USRS %s
  162. // CHECK-USRS: index-templates.cpp c:@FT@>3#T#Nt0.0#t>2#T#Nt1.0f#>t0.22S0_#v# Extent=[3:1 - 4:22]
  163. // CHECK-USRS: index-templates.cpp c:index-templates.cpp@70 Extent=[3:10 - 3:20]
  164. // CHECK-USRS: index-templates.cpp c:index-templates.cpp@82 Extent=[3:22 - 3:29]
  165. // CHECK-USRS: index-templates.cpp c:index-templates.cpp@91 Extent=[3:31 - 3:67]
  166. // CHECK-USRS: index-templates.cpp c:index-templates.cpp@136@FT@>3#T#Nt0.0#t>2#T#Nt1.0f#>t0.22S0_#v#@x Extent=[4:8 - 4:21]
  167. // CHECK-USRS: index-templates.cpp c:@ST>1#T@allocator Extent=[6:1 - 6:37]
  168. // CHECK-USRS: index-templates.cpp c:index-templates.cpp@162 Extent=[6:10 - 6:20]
  169. // CHECK-USRS: index-templates.cpp c:@ST>2#T#T@vector Extent=[8:1 - 11:2]
  170. // CHECK-USRS: index-templates.cpp c:index-templates.cpp@201 Extent=[8:10 - 8:20]
  171. // CHECK-USRS: index-templates.cpp c:index-templates.cpp@213 Extent=[8:22 - 8:51]
  172. // CHECK-USRS: index-templates.cpp c:@ST>2#T#T@vector@F@clear# Extent=[10:3 - 10:15]
  173. // CHECK-USRS: index-templates.cpp c:@SP>1#T@vector>#*t0.0#>@ST>1#T@allocator1S0_ Extent=[13:1 - 14:21]
  174. // CHECK-USRS: index-templates.cpp c:index-templates.cpp@289 Extent=[13:10 - 13:20]
  175. // CHECK-USRS: index-templates.cpp c:@S@Z1 Extent=[16:1 - 16:14]
  176. // CHECK-USRS: index-templates.cpp c:@S@vector>#$@S@Z1#$@S@allocator>#S0_ Extent=[18:1 - 18:26]
  177. // CHECK-USRS: index-templates.cpp c:@S@Z2 Extent=[20:1 - 20:14]
  178. // CHECK-USRS: index-templates.cpp c:@S@vector>#$@S@Z2#$@S@allocator>#S0_ Extent=[22:1 - 25:2]
  179. // CHECK-USRS: index-templates.cpp c:@S@vector>#$@S@Z2#$@S@allocator>#S0_@F@clear# Extent=[24:3 - 24:15]
  180. // CHECK-USRS: index-templates.cpp c:@ST>2#T#T@Y Extent=[27:1 - 31:2]
  181. // CHECK-USRS: index-templates.cpp c:index-templates.cpp@443 Extent=[27:10 - 27:20]
  182. // CHECK-USRS: index-templates.cpp c:index-templates.cpp@455 Extent=[27:22 - 27:32]
  183. // CHECK-USRS-NOT: type
  184. // CHECK-USRS: index-templates.cpp c:@S@Z3 Extent=[33:1 - 33:14]
  185. // CHECK-USRS: index-templates.cpp c:@F@f#$@S@map>#$@S@Z4#$@S@Pair>#I#S1_#$@S@compare>#$@S@Pair>#S1_#S2_#$@S@allocator>#S4_#