| 1 |
// RUN: c-index-test core -print-source-symbols -- %s -std=c++14 -target x86_64-apple-macosx10.7 | FileCheck %s |
| 2 |
// References to declarations in instantiations should be canonicalized: |
| 3 |
|
| 4 |
template<typename T> |
| 5 |
class BaseTemplate { |
| 6 |
public: |
| 7 |
T baseTemplateFunction(); |
| 8 |
// CHECK: [[@LINE-1]]:5 | instance-method/C++ | baseTemplateFunction | c:@ST>1#T@BaseTemplate@F@baseTemplateFunction# |
| 9 |
|
| 10 |
T baseTemplateField; |
| 11 |
// CHECK: [[@LINE-1]]:5 | field/C++ | baseTemplateField | c:@ST>1#T@BaseTemplate@FI@baseTemplateField |
| 12 |
|
| 13 |
struct NestedBaseType { }; |
| 14 |
// CHECK: [[@LINE-1]]:10 | struct/C | NestedBaseType | c:@ST>1#T@BaseTemplate@S@NestedBaseType | |
| 15 |
}; |
| 16 |
|
| 17 |
template<typename T, typename S> |
| 18 |
class TemplateClass: public BaseTemplate<T> { |
| 19 |
public: |
| 20 |
T function() { return T(); } |
| 21 |
// CHECK: [[@LINE-1]]:5 | instance-method/C++ | function | c:@ST>2#T#T@TemplateClass@F@function# |
| 22 |
|
| 23 |
static void staticFunction() { } |
| 24 |
// CHECK: [[@LINE-1]]:15 | static-method/C++ | staticFunction | c:@ST>2#T#T@TemplateClass@F@staticFunction#S |
| 25 |
|
| 26 |
T field; |
| 27 |
// CHECK: [[@LINE-1]]:5 | field/C++ | field | c:@ST>2#T#T@TemplateClass@FI@field |
| 28 |
|
| 29 |
struct NestedType { |
| 30 |
// CHECK: [[@LINE-1]]:10 | struct/C++ | NestedType | c:@ST>2#T#T@TemplateClass@S@NestedType | |
| 31 |
|
| 32 |
T nestedField; |
| 33 |
// CHECK: [[@LINE-1]]:7 | field/C++ | nestedField | c:@ST>2#T#T@TemplateClass@S@NestedType@FI@nestedField | |
| 34 |
|
| 35 |
class SubNestedType { |
| 36 |
// CHECK: [[@LINE-1]]:11 | class/C++ | SubNestedType | c:@ST>2#T#T@TemplateClass@S@NestedType@S@SubNestedType | |
| 37 |
public: |
| 38 |
SubNestedType(int); |
| 39 |
}; |
| 40 |
using TypeAlias = T; |
| 41 |
// CHECK: [[@LINE-1]]:11 | type-alias/C++ | TypeAlias | c:@ST>2#T#T@TemplateClass@S@NestedType@TypeAlias | |
| 42 |
|
| 43 |
typedef int Typedef; |
| 44 |
// CHECK: [[@LINE-1]]:17 | type-alias/C | Typedef | c:{{.*}}index-instantiated-source.cpp@ST>2#T#T@TemplateClass@S@NestedType@T@Typedef | |
| 45 |
|
| 46 |
enum Enum { |
| 47 |
// CHECK: [[@LINE-1]]:10 | enum/C | Enum | c:@ST>2#T#T@TemplateClass@S@NestedType@E@Enum | |
| 48 |
EnumCase |
| 49 |
// CHECK: [[@LINE-1]]:7 | enumerator/C | EnumCase | c:@ST>2#T#T@TemplateClass@S@NestedType@E@Enum@EnumCase | |
| 50 |
}; |
| 51 |
}; |
| 52 |
}; |
| 53 |
|
| 54 |
void canonicalizeInstaniationReferences(TemplateClass<int, float> &object) { |
| 55 |
(void)object.function(); |
| 56 |
// CHECK: [[@LINE-1]]:16 | instance-method/C++ | function | c:@ST>2#T#T@TemplateClass@F@function# | <no-cgname> |
| 57 |
(void)object.field; |
| 58 |
// CHECK: [[@LINE-1]]:16 | field/C++ | field | c:@ST>2#T#T@TemplateClass@FI@field | <no-cgname> | Ref,RelCont | rel: 1 |
| 59 |
(void)object.baseTemplateFunction(); |
| 60 |
// CHECK: [[@LINE-1]]:16 | instance-method/C++ | baseTemplateFunction | c:@ST>1#T@BaseTemplate@F@baseTemplateFunction# | <no-cgname> |
| 61 |
(void)object.baseTemplateField; |
| 62 |
// CHECK: [[@LINE-1]]:16 | field/C++ | baseTemplateField | c:@ST>1#T@BaseTemplate@FI@baseTemplateField | <no-cgname> | Ref,RelCont | rel: 1 |
| 63 |
|
| 64 |
TemplateClass<int, float>::staticFunction(); |
| 65 |
// CHECK: [[@LINE-1]]:30 | static-method/C++ | staticFunction | c:@ST>2#T#T@TemplateClass@F@staticFunction#S | <no-cgname |
| 66 |
|
| 67 |
TemplateClass<int, float>::NestedBaseType nestedBaseType; |
| 68 |
// CHECK: [[@LINE-1]]:30 | struct/C | NestedBaseType | c:@ST>1#T@BaseTemplate@S@NestedBaseType | |
| 69 |
TemplateClass<int, float>::NestedType nestedSubType; |
| 70 |
// CHECK: [[@LINE-1]]:30 | struct/C++ | NestedType | c:@ST>2#T#T@TemplateClass@S@NestedType | |
| 71 |
(void)nestedSubType.nestedField; |
| 72 |
// CHECK: [[@LINE-1]]:23 | field/C++ | nestedField | c:@ST>2#T#T@TemplateClass@S@NestedType@FI@nestedField | |
| 73 |
|
| 74 |
typedef TemplateClass<int, float> TT; |
| 75 |
TT::NestedType::SubNestedType subNestedType(0); |
| 76 |
// CHECK: [[@LINE-1]]:19 | class/C++ | SubNestedType | c:@ST>2#T#T@TemplateClass@S@NestedType@S@SubNestedType | |
| 77 |
// CHECK: [[@LINE-2]]:7 | struct/C++ | NestedType | c:@ST>2#T#T@TemplateClass@S@NestedType | |
| 78 |
|
| 79 |
TT::NestedType::TypeAlias nestedTypeAlias; |
| 80 |
// CHECK: [[@LINE-1]]:19 | type-alias/C++ | TypeAlias | c:@ST>2#T#T@TemplateClass@S@NestedType@TypeAlias | |
| 81 |
TT::NestedType::Typedef nestedTypedef; |
| 82 |
// CHECK: [[@LINE-1]]:19 | type-alias/C | Typedef | c:{{.*}}index-instantiated-source.cpp@ST>2#T#T@TemplateClass@S@NestedType@T@Typedef | |
| 83 |
|
| 84 |
TT::NestedType::Enum nestedEnum; |
| 85 |
// CHECK: [[@LINE-1]]:19 | enum/C | Enum | c:@ST>2#T#T@TemplateClass@S@NestedType@E@Enum | |
| 86 |
(void)TT::NestedType::Enum::EnumCase; |
| 87 |
// CHECK: [[@LINE-1]]:31 | enumerator/C | EnumCase | c:@ST>2#T#T@TemplateClass@S@NestedType@E@Enum@EnumCase | |
| 88 |
} |
| 89 |
|
| 90 |
namespace index_specialization { |
| 91 |
template <typename T> |
| 92 |
class Foo {}; |
| 93 |
|
| 94 |
// if there are no explicit template specializations provided, report the |
| 95 |
// primary templates. |
| 96 |
Foo<int> *t1; // incomplete instantiation. |
| 97 |
// CHECK: [[@LINE-1]]:1 | class(Gen)/C++ | Foo | c:@N@index_specialization@ST>1#T@Foo | <no-cgname> | Ref,RelCont | rel: 1 |
| 98 |
|
| 99 |
Foo<double> t2; |
| 100 |
// CHECK: [[@LINE-1]]:1 | class(Gen)/C++ | Foo | c:@N@index_specialization@ST>1#T@Foo | <no-cgname> | Ref,RelCont | rel: 1 |
| 101 |
|
| 102 |
// explicit instantiations. |
| 103 |
template class Foo<float>; |
| 104 |
Foo<float> t3; |
| 105 |
// CHECK: [[@LINE-1]]:1 | class(Gen)/C++ | Foo | c:@N@index_specialization@ST>1#T@Foo | <no-cgname> | Ref,RelCont | rel: 1 |
| 106 |
|
| 107 |
|
| 108 |
template <typename T> |
| 109 |
class Bar {}; |
| 110 |
|
| 111 |
// explicit template specialization definition! |
| 112 |
template <>class Bar<int> {}; |
| 113 |
// report the explicit template specialization if it exists. |
| 114 |
Bar<int> *b1; |
| 115 |
// CHECK: [[@LINE-1]]:1 | class(Gen,TS)/C++ | Bar | c:@N@index_specialization@S@Bar>#I | <no-cgname> | Ref,RelCont | rel: 1 |
| 116 |
|
| 117 |
// explicit template declaration, not a definition! |
| 118 |
template <> class Bar <float>; |
| 119 |
Bar<float> *b2; |
| 120 |
// CHECK: [[@LINE-1]]:1 | class(Gen,TS)/C++ | Bar | c:@N@index_specialization@S@Bar>#f | <no-cgname> | Ref,RelCont | rel: 1 |
| 121 |
|
| 122 |
} // namespace index_specialization |