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