clang: lib/AST/DeclTemplate.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
29#include "llvm/ADT/ArrayRef.h"
30#include "llvm/ADT/FoldingSet.h"
31#include "llvm/ADT/PointerUnion.h"
32#include "llvm/ADT/STLExtras.h"
33#include "llvm/ADT/SmallVector.h"
34#include "llvm/Support/ErrorHandling.h"
35#include
36#include
37#include
38
39using namespace clang;
40
41
42
43
44
45template
46static bool
48 return P.hasDefaultArgument() &&
49 P.getDefaultArgument().getArgument().containsUnexpandedParameterPack();
50}
51
57 Expr *RequiresClause)
58 : TemplateLoc(TemplateLoc), LAngleLoc(LAngleLoc), RAngleLoc(RAngleLoc),
59 NumParams(Params.size()), ContainsUnexpandedParameterPack(false),
60 HasRequiresClause(RequiresClause != nullptr),
61 HasConstrainedParameters(false) {
62 for (unsigned Idx = 0; Idx < NumParams; ++Idx) {
64 begin()[Idx] = P;
65
67 if (const auto *NTTP = dyn_cast(P)) {
68 if (!IsPack && (NTTP->getType()->containsUnexpandedParameterPack() ||
70 ContainsUnexpandedParameterPack = true;
71 if (NTTP->hasPlaceholderTypeConstraint())
72 HasConstrainedParameters = true;
73 } else if (const auto *TTP = dyn_cast(P)) {
74 if (!IsPack &&
75 (TTP->getTemplateParameters()->containsUnexpandedParameterPack() ||
77 ContainsUnexpandedParameterPack = true;
78 }
79 } else if (const auto *TTP = dyn_cast(P)) {
81 ContainsUnexpandedParameterPack = true;
82 } else if (const TypeConstraint *TC = TTP->getTypeConstraint();
85 ContainsUnexpandedParameterPack = true;
86 }
87 if (TTP->hasTypeConstraint())
88 HasConstrainedParameters = true;
89 } else {
90 llvm_unreachable("unexpected template parameter type");
91 }
92 }
93
94 if (HasRequiresClause) {
96 ContainsUnexpandedParameterPack = true;
97 *getTrailingObjects<Expr *>() = RequiresClause;
98 }
99}
100
102 if (ContainsUnexpandedParameterPack)
103 return true;
104 if (!HasConstrainedParameters)
105 return false;
106
107
108
109
110 for (const NamedDecl *Param : llvm::reverse(asArray())) {
111 if (!Param->isImplicit())
112 break;
113
114 if (const auto *TTP = dyn_cast(Param)) {
115 const auto *TC = TTP->getTypeConstraint();
116 if (TC && TC->getImmediatelyDeclaredConstraint()
117 ->containsUnexpandedParameterPack())
118 return true;
119 }
120 }
121
122 return false;
123}
124
130 void *Mem = C.Allocate(totalSizeToAlloc<NamedDecl *, Expr *>(
131 Params.size(), RequiresClause ? 1u : 0u),
134 RAngleLoc, RequiresClause);
135}
136
140 ID.AddBoolean(RC != nullptr);
141 if (RC)
144 for (NamedDecl *D : *this) {
145 if (const auto *NTTP = dyn_cast(D)) {
146 ID.AddInteger(0);
147 ID.AddBoolean(NTTP->isParameterPack());
148 NTTP->getType().getCanonicalType().Profile(ID);
149 ID.AddBoolean(NTTP->hasPlaceholderTypeConstraint());
150 if (const Expr *E = NTTP->getPlaceholderTypeConstraint())
151 E->Profile(ID, C, true);
152 continue;
153 }
154 if (const auto *TTP = dyn_cast(D)) {
155 ID.AddInteger(1);
156 ID.AddBoolean(TTP->isParameterPack());
157 ID.AddBoolean(TTP->hasTypeConstraint());
158 if (const TypeConstraint *TC = TTP->getTypeConstraint())
159 TC->getImmediatelyDeclaredConstraint()->Profile(ID, C,
160 true);
161 continue;
162 }
164 ID.AddInteger(2);
165 ID.AddInteger(TTP->templateParameterKind());
166 ID.AddBoolean(TTP->isParameterPack());
167 TTP->getTemplateParameters()->Profile(ID, C);
168 }
169}
170
172 unsigned NumRequiredArgs = 0;
173 for (const NamedDecl *P : asArray()) {
176 NumRequiredArgs += *Expansions;
177 continue;
178 }
179 break;
180 }
181
182 if (const auto *TTP = dyn_cast(P)) {
183 if (TTP->hasDefaultArgument())
184 break;
185 } else if (const auto *NTTP = dyn_cast(P)) {
186 if (NTTP->hasDefaultArgument())
187 break;
188 } else if (const auto *TTP = dyn_cast(P);
189 TTP && TTP->hasDefaultArgument())
190 break;
191
192 ++NumRequiredArgs;
193 }
194
195 return NumRequiredArgs;
196}
197
199 if (size() == 0)
200 return 0;
201
202 const NamedDecl *FirstParm = getParam(0);
203 if (const auto *TTP = dyn_cast(FirstParm))
204 return TTP->getDepth();
205 else if (const auto *NTTP = dyn_cast(FirstParm))
206 return NTTP->getDepth();
207 else
209}
210
216
217 if (const auto *TTP = dyn_cast(P))
220
223 }
225}
226
229 if (HasConstrainedParameters)
230 for (const NamedDecl *Param : *this) {
231 if (const auto *TTP = dyn_cast(Param)) {
232 if (const auto *TC = TTP->getTypeConstraint())
233 ACs.emplace_back(TC->getImmediatelyDeclaredConstraint(),
234 TC->getArgPackSubstIndex());
235 } else if (const auto *NTTP = dyn_cast(Param)) {
236 if (const Expr *E = NTTP->getPlaceholderTypeConstraint())
237 ACs.emplace_back(E);
238 }
239 }
240 if (HasRequiresClause)
242}
243
245 return HasRequiresClause || HasConstrainedParameters;
246}
247
250 if (!InjectedArgs) {
251 InjectedArgs = new (Context) TemplateArgument[size()];
252 llvm::transform(*this, InjectedArgs, [&](NamedDecl *ND) {
254 });
255 }
256 return {InjectedArgs, NumParams};
257}
258
261 unsigned Idx) {
263 return true;
264 const NamedDecl *TemplParam = TPL->getParam(Idx);
265 if (const auto *ParamValueDecl =
266 dyn_cast(TemplParam))
267 if (ParamValueDecl->getType()->getContainedDeducedType())
268 return true;
269 return false;
270}
271
272namespace clang {
273
275 return new (C) char[sizeof(void*) * 2];
276}
277
278}
279
280
281
282
283
288
289void TemplateDecl::anchor() {}
290
294 if (auto *FD = dyn_cast_or_null(getTemplatedDecl()))
296 ACs.emplace_back(TRC);
297}
298
301 return true;
302 if (auto *FD = dyn_cast_or_null(getTemplatedDecl()))
303 return static_cast<bool>(FD->getTrailingRequiresClause());
304 return false;
305}
306
309 case TemplateDecl::TypeAliasTemplate:
310 return true;
311 case TemplateDecl::BuiltinTemplate:
313 default:
314 return false;
315 };
316}
317
318
319
320
321
322void RedeclarableTemplateDecl::anchor() {}
323
327
328
329
333 if (Prev->Common) {
334 Common = Prev->Common;
335 break;
336 }
337
338 PrevDecls.push_back(Prev);
339 }
340
341
343
344
345
347 }
348
349
351 Prev->Common = Common;
352
354}
355
357 bool OnlyPartial ) const {
360 return;
361
363 OnlyPartial);
364}
365
370 return false;
371
372
373
374 if (TPL)
376 false);
377
379 Args);
380}
381
382template <class EntryType, typename... ProfileArguments>
385 llvm::FoldingSetVector &Specs, void *&InsertPos,
386 ProfileArguments... ProfileArgs) {
388
389 llvm::FoldingSetNodeID ID;
390 EntryType::Profile(ID, ProfileArgs..., getASTContext());
391 EntryType *Entry = Specs.FindNodeOrInsertPos(ID, InsertPos);
392 return Entry ? SETraits::getDecl(Entry)->getMostRecentDecl() : nullptr;
393}
394
395template <class EntryType, typename... ProfileArguments>
398 llvm::FoldingSetVector &Specs, void *&InsertPos,
399 ProfileArguments... ProfileArgs) {
400
403
405 return nullptr;
406
408}
409
410template<class Derived, class EntryType>
412 llvm::FoldingSetVector &Specializations, EntryType *Entry,
413 void *InsertPos) {
415
416 if (InsertPos) {
417#ifndef NDEBUG
418 auto Args = SETraits::getTemplateArgs(Entry);
419
420
421
422
424 void *CorrectInsertPos;
426 InsertPos == CorrectInsertPos &&
427 "given incorrect InsertPos for specialization");
428#endif
429 Specializations.InsertNode(Entry, InsertPos);
430 } else {
431 EntryType *Existing = Specializations.GetOrInsertNode(Entry);
432 (void)Existing;
434 "non-canonical specialization?");
435 }
436
438 L->AddedCXXTemplateSpecialization(cast(this),
439 SETraits::getDecl(Entry));
440}
441
442
443
444
445
453 TD->setInvalidDecl();
454 return TD;
455}
456
462
465 auto *CommonPtr = new (C) Common;
466 C.addDestruction(CommonPtr);
467 return CommonPtr;
468}
469
473
474llvm::FoldingSetVector &
479
482 void *&InsertPos) {
485}
486
493
496
497
498
499 if (!Base::Common)
500 return;
501
502 Common *ThisCommon = static_cast<Common *>(Base::Common);
503 Common *PrevCommon = nullptr;
506 if (Prev->Base::Common) {
507 PrevCommon = static_cast<Common *>(Prev->Base::Common);
508 break;
509 }
510 PreviousDecls.push_back(Prev);
511 }
512
513
514
515 if (!PrevCommon) {
516 for (auto *D : PreviousDecls)
517 D->Base::Common = ThisCommon;
518 return;
519 }
520
521
523 "Can't merge incompatible declarations!");
524
525 Base::Common = PrevCommon;
526}
527
528
529
530
531
540 TD->setInvalidDecl();
541 return TD;
542}
543
549
551 bool OnlyPartial ) const {
553}
554
555llvm::FoldingSetVector &
560
561llvm::FoldingSetVector &
566
569 auto *CommonPtr = new (C) Common;
570 C.addDestruction(CommonPtr);
571 return CommonPtr;
572}
573
576 void *&InsertPos) {
579}
580
582 void *InsertPos) {
585 InsertPos);
586}
587
595
599 ID.AddInteger(TemplateArgs.size());
602 TPL->Profile(ID, Context);
603}
604
607 void *InsertPos) {
608 if (InsertPos)
610 else {
613 (void)Existing;
614 assert(Existing->isCanonicalDecl() && "Non-canonical specialization?");
615 }
616
618 L->AddedCXXTemplateSpecialization(this, D);
619}
620
623 llvm::FoldingSetVector &PartialSpecs
625 PS.clear();
626 PS.reserve(PartialSpecs.size());
629}
630
636 if (Context.hasSameType(P.getCanonicalInjectedSpecializationType(Context),
637 T))
639 }
640
641 return nullptr;
642}
643
649 if (P.getInstantiatedFromMember()->getCanonicalDecl() == DCanon)
651 }
652
653 return nullptr;
654}
655
659
668 CanonicalArgs));
669 }
671}
672
673
674
675
676
680 bool Typename, bool ParameterPack, bool HasTypeConstraint,
682 auto *TTPDecl =
683 new (C, DC,
684 additionalSizeToAlloc(HasTypeConstraint ? 1 : 0))
685 TemplateTypeParmDecl(DC, KeyLoc, NameLoc, Id, Typename,
686 HasTypeConstraint, NumExpanded);
687 QualType TTPType = C.getTemplateTypeParmType(D, P, ParameterPack, TTPDecl);
688 TTPDecl->setTypeForDecl(TTPType.getTypePtr());
689 return TTPDecl;
690}
691
694 return new (C, ID)
696 false, false, std::nullopt);
697}
698
701 bool HasTypeConstraint) {
702 return new (C, ID,
703 additionalSizeToAlloc(HasTypeConstraint ? 1 : 0))
705 false, HasTypeConstraint, std::nullopt);
706}
707
712
724
728 DefaultArgument.set(nullptr);
729 else
731}
732
734 return dyn_cast(getTypeForDecl())->getDepth();
735}
736
738 return dyn_cast(getTypeForDecl())->getIndex();
739}
740
742 return dyn_cast(getTypeForDecl())->isParameterPack();
743}
744
748 assert(HasTypeConstraint &&
749 "HasTypeConstraint=true must be passed at construction in order to "
750 "call setTypeConstraint");
751 assert(!TypeConstraintInitialized &&
752 "TypeConstraint was already initialized!");
753 new (getTrailingObjects())
754 TypeConstraint(Loc, ImmediatelyDeclaredConstraint, ArgPackSubstIndex);
755 TypeConstraintInitialized = true;
756}
757
758
759
760
761
762NonTypeTemplateParmDecl::NonTypeTemplateParmDecl(
766 : DeclaratorDecl(NonTypeTemplateParm, DC, IdLoc, Id, T, TInfo, StartLoc),
768 ExpandedParameterPack(true), NumExpandedTypes(ExpandedTypes.size()) {
769 if (!ExpandedTypes.empty() && !ExpandedTInfos.empty()) {
770 auto TypesAndInfos =
771 getTrailingObjects<std::pair<QualType, TypeSourceInfo *>>();
772 for (unsigned I = 0; I != NumExpandedTypes; ++I) {
773 new (&TypesAndInfos[I].first) QualType(ExpandedTypes[I]);
774 TypesAndInfos[I].second = ExpandedTInfos[I];
775 }
776 }
777}
778
783 AutoType *AT =
784 C.getLangOpts().CPlusPlus20 ? T->getContainedAutoType() : nullptr;
785 const bool HasConstraint = AT && AT->isConstrained();
786 auto *NTTP =
787 new (C, DC,
788 additionalSizeToAlloc<std::pair<QualType, TypeSourceInfo *>, Expr *>(
789 0, HasConstraint ? 1 : 0))
790 NonTypeTemplateParmDecl(DC, StartLoc, IdLoc, D, P, Id, T,
791 ParameterPack, TInfo);
792 if (HasConstraint)
793 NTTP->setPlaceholderTypeConstraint(nullptr);
794 return NTTP;
795}
796
803 const bool HasConstraint = AT && AT->isConstrained();
804 auto *NTTP =
805 new (C, DC,
806 additionalSizeToAlloc<std::pair<QualType, TypeSourceInfo *>, Expr *>(
807 ExpandedTypes.size(), HasConstraint ? 1 : 0))
808 NonTypeTemplateParmDecl(DC, StartLoc, IdLoc, D, P, Id, T, TInfo,
809 ExpandedTypes, ExpandedTInfos);
810 if (HasConstraint)
811 NTTP->setPlaceholderTypeConstraint(nullptr);
812 return NTTP;
813}
814
817 bool HasTypeConstraint) {
818 auto *NTTP =
819 new (C, ID,
820 additionalSizeToAlloc<std::pair<QualType, TypeSourceInfo *>, Expr *>(
821 0, HasTypeConstraint ? 1 : 0))
823 0, 0, nullptr, QualType(), false, nullptr);
824 if (HasTypeConstraint)
826 return NTTP;
827}
828
831 unsigned NumExpandedTypes,
832 bool HasTypeConstraint) {
833 auto *NTTP =
834 new (C, ID,
835 additionalSizeToAlloc<std::pair<QualType, TypeSourceInfo *>, Expr *>(
836 NumExpandedTypes, HasTypeConstraint ? 1 : 0))
838 0, 0, nullptr, QualType(), nullptr, {}, {});
839 NTTP->NumExpandedTypes = NumExpandedTypes;
840 if (HasTypeConstraint)
841 NTTP->setPlaceholderTypeConstraint(nullptr);
842 return NTTP;
843}
844
851
856
860 DefaultArgument.set(nullptr);
861 else
863}
864
865
866
867
868
869void TemplateTemplateParmDecl::anchor() {}
870
871TemplateTemplateParmDecl::TemplateTemplateParmDecl(
875 : TemplateDecl(TemplateTemplateParm, DC, L, Id, Params),
877 ParameterPack(true), ExpandedParameterPack(true),
878 NumExpandedParams(Expansions.size()) {
879 llvm::uninitialized_copy(Expansions, getTrailingObjects());
880}
881
886 return new (C, DC) TemplateTemplateParmDecl(DC, L, D, P, ParameterPack, Id,
887 Kind, Typename, Params);
888}
889
896 return new (C, DC,
897 additionalSizeToAlloc<TemplateParameterList *>(Expansions.size()))
898 TemplateTemplateParmDecl(DC, L, D, P, Id, Kind, Typename, Params,
899 Expansions);
900}
901
904 return new (C, ID) TemplateTemplateParmDecl(
907}
908
911 unsigned NumExpansions) {
912 auto *TTP =
913 new (C, ID, additionalSizeToAlloc<TemplateParameterList *>(NumExpansions))
914 TemplateTemplateParmDecl(nullptr, SourceLocation(), 0, 0, nullptr,
916 nullptr, {});
917 TTP->NumExpandedParams = NumExpansions;
918 return TTP;
919}
920
925
929 DefaultArgument.set(nullptr);
930 else
932}
933
934
935
936
938 : NumArguments(Args.size()) {
939 llvm::uninitialized_copy(Args, getTrailingObjects());
940}
941
945 void *Mem = Context.Allocate(totalSizeToAlloc(Args.size()));
946 return new (Mem) TemplateArgumentList(Args);
947}
948
955 if (TemplateArgsAsWritten)
957 *TemplateArgsAsWritten);
958
959 void *Mem =
960 C.Allocate(totalSizeToAlloc<MemberSpecializationInfo *>(MSInfo ? 1 : 0));
961 return new (Mem) FunctionTemplateSpecializationInfo(
962 FD, Template, TSK, TemplateArgs, ArgsAsWritten, POI, MSInfo);
963}
964
965
966
967
968
974 : CXXRecordDecl(DK, TK, Context, DC, StartLoc, IdLoc,
976 SpecializedTemplate(SpecializedTemplate),
978 SpecializationKind(TSK_Undeclared), StrictPackMatch(StrictPackMatch) {
979 assert(DK == Kind::ClassTemplateSpecialization || StrictPackMatch == false);
980}
981
987
994 Context, ClassTemplateSpecialization, TK, DC, StartLoc, IdLoc,
995 SpecializedTemplate, Args, StrictPackMatch, PrevDecl);
996
997
998
999
1000
1001 if (!SpecializedTemplate->getTemplatedDecl()->isCompleteDefinition())
1002 Result->setHasExternalLexicalStorage(
1003 SpecializedTemplate->getTemplatedDecl()->hasExternalLexicalStorage());
1004
1006}
1007
1011 return new (C, ID)
1013}
1014
1018
1019 const auto *PS = dyn_cast(this);
1021 PS ? PS->getTemplateArgsAsWritten() : nullptr) {
1022 printTemplateArgumentList(
1023 OS, ArgsAsWritten->arguments(), Policy,
1025 } else {
1027 printTemplateArgumentList(
1028 OS, TemplateArgs.asArray(), Policy,
1030 }
1031}
1032
1035 if (const auto *PartialSpec =
1036 SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization*>())
1037 return PartialSpec->PartialSpecialization->getSpecializedTemplate();
1039}
1040
1049 assert(!Pattern.isNull() &&
1050 "Class template specialization without pattern?");
1051 if (const auto *CTPSD =
1052 dyn_cast<ClassTemplatePartialSpecializationDecl *>(Pattern))
1053 return CTPSD->getSourceRange();
1055 }
1060 Range.setEnd(Args->getRAngleLoc());
1061 return Range;
1062 }
1067 Range.setBegin(ExternKW);
1070 Range.setBegin(TemplateKW);
1072 Range.setEnd(Args->getRAngleLoc());
1073 return Range;
1074 }
1075 }
1076 llvm_unreachable("unhandled template specialization kind");
1077}
1078
1080 auto *Info = dyn_cast_if_present<ExplicitInstantiationInfo *>(ExplicitInfo);
1081 if (!Info) {
1082
1083 if (Loc.isInvalid())
1084 return;
1087 ExplicitInfo = Info;
1088 }
1089 Info->ExternKeywordLoc = Loc;
1090}
1091
1094 auto *Info = dyn_cast_if_present<ExplicitInstantiationInfo *>(ExplicitInfo);
1095 if (!Info) {
1096
1097 if (Loc.isInvalid())
1098 return;
1101 ExplicitInfo = Info;
1102 }
1103 Info->TemplateKeywordLoc = Loc;
1104}
1105
1106
1107
1108
1116 TD->setInvalidDecl();
1117 return TD;
1118}
1119
1123 nullptr, nullptr);
1124
1126}
1127
1128
1129
1130
1131ImplicitConceptSpecializationDecl::ImplicitConceptSpecializationDecl(
1134 : Decl(ImplicitConceptSpecialization, DC, SL),
1135 NumTemplateArgs(ConvertedArgs.size()) {
1136 setTemplateArguments(ConvertedArgs);
1137}
1138
1139ImplicitConceptSpecializationDecl::ImplicitConceptSpecializationDecl(
1140 EmptyShell Empty, unsigned NumTemplateArgs)
1141 : Decl(ImplicitConceptSpecialization, Empty),
1142 NumTemplateArgs(NumTemplateArgs) {}
1143
1147 return new (C, DC,
1148 additionalSizeToAlloc(ConvertedArgs.size()))
1149 ImplicitConceptSpecializationDecl(DC, SL, ConvertedArgs);
1150}
1151
1155 return new (C, ID, additionalSizeToAlloc(NumTemplateArgs))
1156 ImplicitConceptSpecializationDecl(EmptyShell{}, NumTemplateArgs);
1157}
1158
1161 assert(Converted.size() == NumTemplateArgs);
1162 llvm::uninitialized_copy(Converted, getTrailingObjects());
1163}
1164
1165
1166
1167
1168void ClassTemplatePartialSpecializationDecl::anchor() {}
1169
1170ClassTemplatePartialSpecializationDecl::ClassTemplatePartialSpecializationDecl(
1177 Context, ClassTemplatePartialSpecialization, TK, DC, StartLoc, IdLoc,
1178
1179
1180 SpecializedTemplate, Args, false, PrevDecl),
1181 TemplateParams(Params), InstantiatedFromMember(nullptr, false),
1182 CanonInjectedTST(CanonInjectedTST) {
1185}
1186
1193 ClassTemplatePartialSpecializationDecl *PrevDecl) {
1194 auto *Result = new (Context, DC) ClassTemplatePartialSpecializationDecl(
1195 Context, TK, DC, StartLoc, IdLoc, Params, SpecializedTemplate, Args,
1196 CanonInjectedTST, PrevDecl);
1199}
1200
1204 return new (C, ID) ClassTemplatePartialSpecializationDecl(C);
1205}
1206
1210 if (CanonInjectedTST.isNull()) {
1211 CanonInjectedTST =
1216 }
1217 return CanonInjectedTST;
1218}
1219
1221 if (const ClassTemplatePartialSpecializationDecl *MT =
1224 return MT->getSourceRange();
1229 return Range;
1230}
1231
1232
1233
1234
1235
1236void FriendTemplateDecl::anchor() {}
1237
1244 if (!Params.empty()) {
1246 llvm::copy(Params, TPL);
1247 }
1248 return new (Context, DC)
1249 FriendTemplateDecl(DC, L, TPL, Params.size(), Friend, FLoc);
1250}
1251
1254 return new (C, ID) FriendTemplateDecl(EmptyShell());
1255}
1256
1257
1258
1259
1260
1268 TD->setInvalidDecl();
1269 return TD;
1270}
1271
1277
1280 auto *CommonPtr = new (C) Common;
1281 C.addDestruction(CommonPtr);
1282 return CommonPtr;
1283}
1284
1285
1286
1287
1288
1291 while (CurD) {
1293 return CurD;
1295 }
1296 return nullptr;
1297}
1298
1306 TD->setInvalidDecl();
1307 return TD;
1308}
1309
1315
1317 bool OnlyPartial ) const {
1319}
1320
1321llvm::FoldingSetVector &
1326
1327llvm::FoldingSetVector &
1332
1335 auto *CommonPtr = new (C) Common;
1336 C.addDestruction(CommonPtr);
1337 return CommonPtr;
1338}
1339
1342 void *&InsertPos) {
1345}
1346
1348 void *InsertPos) {
1351}
1352
1359
1363 ID.AddInteger(TemplateArgs.size());
1366 TPL->Profile(ID, Context);
1367}
1368
1371 if (InsertPos)
1373 else {
1376 (void)Existing;
1377 assert(Existing->isCanonicalDecl() && "Non-canonical specialization?");
1378 }
1379
1381 L->AddedCXXTemplateSpecialization(this, D);
1382}
1383
1386 llvm::FoldingSetVector &PartialSpecs =
1388 PS.clear();
1389 PS.reserve(PartialSpecs.size());
1391 PS.push_back(P.getMostRecentDecl());
1392}
1393
1399 if (P.getInstantiatedFromMember()->getCanonicalDecl() == DCanon)
1400 return P.getMostRecentDecl();
1401 }
1402
1403 return nullptr;
1404}
1405
1406
1407
1408
1409
1414 : VarDecl(DK, Context, DC, StartLoc, IdLoc,
1416 SpecializedTemplate(SpecializedTemplate),
1419
1425
1431 VarTemplateSpecialization, Context, DC, StartLoc, IdLoc,
1432 SpecializedTemplate, T, TInfo, S, Args);
1433}
1434
1438 return new (C, ID)
1440}
1441
1445
1446 const auto *PS = dyn_cast(this);
1448 PS ? PS->getTemplateArgsAsWritten() : nullptr) {
1449 printTemplateArgumentList(
1450 OS, ArgsAsWritten->arguments(), Policy,
1452 } else {
1454 printTemplateArgumentList(
1455 OS, TemplateArgs.asArray(), Policy,
1457 }
1458}
1459
1461 if (const auto *PartialSpec =
1462 SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization *>())
1463 return PartialSpec->PartialSpecialization->getSpecializedTemplate();
1465}
1466
1474 assert(!Pattern.isNull() &&
1475 "Variable template specialization without pattern?");
1476 if (const auto *VTPSD =
1477 dyn_cast<VarTemplatePartialSpecializationDecl *>(Pattern))
1478 return VTPSD->getSourceRange();
1482 return Definition->getSourceRange();
1483 }
1485 }
1490 Range.setEnd(Args->getRAngleLoc());
1491 return Range;
1492 }
1497 Range.setBegin(ExternKW);
1500 Range.setBegin(TemplateKW);
1502 Range.setEnd(Args->getRAngleLoc());
1503 return Range;
1504 }
1505 }
1506 llvm_unreachable("unhandled template specialization kind");
1507}
1508
1510 auto *Info = dyn_cast_if_present<ExplicitInstantiationInfo *>(ExplicitInfo);
1511 if (!Info) {
1512
1513 if (Loc.isInvalid())
1514 return;
1517 ExplicitInfo = Info;
1518 }
1519 Info->ExternKeywordLoc = Loc;
1520}
1521
1523 auto *Info = dyn_cast_if_present<ExplicitInstantiationInfo *>(ExplicitInfo);
1524 if (!Info) {
1525
1526 if (Loc.isInvalid())
1527 return;
1530 ExplicitInfo = Info;
1531 }
1532 Info->TemplateKeywordLoc = Loc;
1533}
1534
1535
1536
1537
1538
1539void VarTemplatePartialSpecializationDecl::anchor() {}
1540
1541VarTemplatePartialSpecializationDecl::VarTemplatePartialSpecializationDecl(
1547 DC, StartLoc, IdLoc, SpecializedTemplate, T,
1548 TInfo, S, Args),
1549 TemplateParams(Params), InstantiatedFromMember(nullptr, false) {
1552}
1553
1560 auto *Result = new (Context, DC) VarTemplatePartialSpecializationDecl(
1561 Context, DC, StartLoc, IdLoc, Params, SpecializedTemplate, T, TInfo, S,
1562 Args);
1565}
1566
1570 return new (C, ID) VarTemplatePartialSpecializationDecl(C);
1571}
1572
1574 if (const VarTemplatePartialSpecializationDecl *MT =
1577 return MT->getSourceRange();
1582 return Range;
1583}
1584
1587 switch (BTK) {
1588#define CREATE_BUILTIN_TEMPLATE_PARAMETER_LIST
1589#include "clang/Basic/BuiltinTemplates.inc"
1590 }
1591
1592 llvm_unreachable("unhandled BuiltinTemplateKind!");
1593}
1594
1595void BuiltinTemplateDecl::anchor() {}
1596
1602 BTK(BTK) {}
1603
1607
1609 auto *T = dyn_cast_or_null(
1611 return T && T->isPackProducingBuiltinTemplate();
1612}
1613
1617 DeclContext *DC = C.getTranslationUnitDecl();
1619 C.addDestruction(&TPOD->Value);
1620 return TPOD;
1621}
1622
1625 auto *TPOD = new (C, ID) TemplateParamObjectDecl(nullptr, QualType(), APValue());
1626 C.addDestruction(&TPOD->Value);
1627 return TPOD;
1628}
1629
1632 OS << "<template param ";
1634 OS << ">";
1635}
1636
1640
1646
1650
1655
1656std::tuple<NamedDecl *, TemplateArgument>
1659 case Decl::Kind::BuiltinTemplate:
1660 case Decl::Kind::ClassTemplate:
1661 case Decl::Kind::Concept:
1662 case Decl::Kind::FunctionTemplate:
1663 case Decl::Kind::TemplateTemplateParm:
1664 case Decl::Kind::TypeAliasTemplate:
1665 case Decl::Kind::VarTemplate:
1666 return {cast(D)->getTemplateParameters()->getParam(Index),
1667 {}};
1668 case Decl::Kind::ClassTemplateSpecialization: {
1670 auto P = CTSD->getSpecializedTemplateOrPartial();
1672 if (const auto *CTPSD =
1673 dyn_cast<ClassTemplatePartialSpecializationDecl *>(P)) {
1674 TPL = CTPSD->getTemplateParameters();
1675
1676 return {TPL->getParam(Index), {}};
1677 }
1679 return {TPL->getParam(Index), CTSD->getTemplateArgs()[Index]};
1680 }
1681 case Decl::Kind::VarTemplateSpecialization: {
1683 auto P = VTSD->getSpecializedTemplateOrPartial();
1685 if (const auto *VTPSD =
1686 dyn_cast<VarTemplatePartialSpecializationDecl *>(P)) {
1687 TPL = VTPSD->getTemplateParameters();
1688
1689 return {TPL->getParam(Index), {}};
1690 }
1692 return {TPL->getParam(Index), VTSD->getTemplateArgs()[Index]};
1693 }
1694 case Decl::Kind::ClassTemplatePartialSpecialization:
1696 ->getTemplateParameters()
1697 ->getParam(Index),
1698 {}};
1699 case Decl::Kind::VarTemplatePartialSpecialization:
1701 ->getTemplateParameters()
1702 ->getParam(Index),
1703 {}};
1704
1705 case Decl::TemplateTypeParm:
1707
1708 case Decl::Kind::CXXRecord:
1711 case Decl::Kind::CXXDeductionGuide:
1712 case Decl::Kind::CXXConversion:
1713 case Decl::Kind::CXXConstructor:
1714 case Decl::Kind::CXXDestructor:
1715 case Decl::Kind::CXXMethod:
1716 case Decl::Kind::Function:
1718 cast(D)->getTemplateSpecializationInfo()->getTemplate(),
1719 Index);
1720 default:
1721 llvm_unreachable("Unhandled templated declaration kind");
1722 }
1723}
1724
1726 if (const auto *FD = dyn_cast(&D)) {
1727
1729 return *FTD;
1730
1731
1733 return D;
1734
1735
1737 return *FTD;
1738
1739
1742 return *MemberDecl;
1743
1744 return D;
1745 }
1746 if (const auto *VD = dyn_cast(&D)) {
1747
1748
1749 if (VD->isStaticDataMember())
1751 return *MemberDecl;
1752
1753 return D;
1754 }
1755 if (const auto *CRD = dyn_cast(&D)) {
1756
1757 if (const ClassTemplateDecl *CTD = CRD->getDescribedClassTemplate())
1758 return *CTD;
1759
1760
1761
1762 if (const auto *CTSD = dyn_cast(CRD)) {
1764 return D;
1770 : *static_cast<const Decl *>(
1772 }
1773
1774
1776 CRD->getMemberSpecializationInfo())
1777 return *Info->getInstantiatedFrom();
1778
1779 return D;
1780 }
1781 if (const auto *ED = dyn_cast(&D)) {
1782
1784 return *MemberDecl;
1785
1786 return D;
1787 }
1788
1789 return D;
1790}
Defines the clang::ASTContext interface.
#define BuiltinTemplate(BTName)
Defines enum values for all the target-independent builtin functions.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
static bool DefaultTemplateArgumentContainsUnexpandedPack(const TemplateParam &P)
Definition DeclTemplate.cpp:47
static bool AdoptTemplateParameterList(TemplateParameterList *Params, DeclContext *Owner)
Definition DeclTemplate.cpp:211
static TemplateParameterList * createBuiltinTemplateParameterList(const ASTContext &C, DeclContext *DC, BuiltinTemplateKind BTK)
Definition DeclTemplate.cpp:1585
Defines the C++ template declaration subclasses.
Defines the clang::Expr interface and subclasses for C++ expressions.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
This file contains the declaration of the ODRHash class, which calculates a hash based on AST nodes,...
static StringRef getIdentifier(const Token &Tok)
Defines the clang::SourceLocation class and associated facilities.
Defines the clang::TypeLoc interface and its subclasses.
C Language Family Type Representation.
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
void printPretty(raw_ostream &OS, const ASTContext &Ctx, QualType Ty) const
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
QualType getCanonicalTemplateSpecializationType(ElaboratedTypeKeyword Keyword, TemplateName T, ArrayRef< TemplateArgument > CanonicalArgs) const
TemplateArgument getInjectedTemplateArg(NamedDecl *ParamDecl) const
ExternalASTSource * getExternalSource() const
Retrieve a pointer to the external AST source associated with this AST context, if any.
bool canonicalizeTemplateArguments(MutableArrayRef< TemplateArgument > Args) const
Canonicalize the given template argument list.
An abstract interface that should be implemented by listeners that want to be notified when an AST en...
BuiltinTemplateKind getBuiltinTemplateKind() const
bool isPackProducingBuiltinTemplate() const
Definition DeclTemplate.cpp:1604
CXXRecordDecl(Kind K, TagKind TK, const ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, CXXRecordDecl *PrevDecl)
CXXRecordDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
static CanQual< Type > CreateUnsafe(QualType Other)
Declaration of a class template.
void AddPartialSpecialization(ClassTemplatePartialSpecializationDecl *D, void *InsertPos)
Insert the specified partial specialization knowing that it is not already in.
Definition DeclTemplate.cpp:605
llvm::FoldingSetVector< ClassTemplateSpecializationDecl > & getSpecializations() const
Retrieve the set of specializations of this class template.
Definition DeclTemplate.cpp:556
llvm::FoldingSetVector< ClassTemplatePartialSpecializationDecl > & getPartialSpecializations() const
Retrieve the set of partial specializations of this class template.
Definition DeclTemplate.cpp:562
ClassTemplatePartialSpecializationDecl * findPartialSpecialization(ArrayRef< TemplateArgument > Args, TemplateParameterList *TPL, void *&InsertPos)
Return the partial specialization with the provided arguments if it exists, otherwise return the inse...
Definition DeclTemplate.cpp:589
ClassTemplateDecl(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, TemplateParameterList *Params, NamedDecl *Decl)
CommonBase * newCommon(ASTContext &C) const override
Definition DeclTemplate.cpp:568
static ClassTemplateDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, TemplateParameterList *Params, NamedDecl *Decl)
Create a class template node.
Definition DeclTemplate.cpp:532
ClassTemplateDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
ClassTemplatePartialSpecializationDecl * findPartialSpecInstantiatedFromMember(ClassTemplatePartialSpecializationDecl *D)
Find a class template partial specialization which was instantiated from the given member partial spe...
Definition DeclTemplate.cpp:645
void LoadLazySpecializations(bool OnlyPartial=false) const
Load any lazily-loaded specializations from the external source.
Definition DeclTemplate.cpp:550
void AddSpecialization(ClassTemplateSpecializationDecl *D, void *InsertPos)
Insert the specified specialization knowing that it is not already in.
Definition DeclTemplate.cpp:581
CanQualType getCanonicalInjectedSpecializationType(const ASTContext &Ctx) const
Retrieve the canonical template specialization type of the injected-class-name for this class templat...
Definition DeclTemplate.cpp:656
Common * getCommonPtr() const
ClassTemplateSpecializationDecl * findSpecialization(ArrayRef< TemplateArgument > Args, void *&InsertPos)
Return the specialization with the provided arguments if it exists, otherwise return the insertion po...
Definition DeclTemplate.cpp:575
static ClassTemplateDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Create an empty class template node.
Definition DeclTemplate.cpp:544
ClassTemplatePartialSpecializationDecl * getInstantiatedFromMember() const
Retrieve the member class template partial specialization from which this particular class template p...
CanQualType getCanonicalInjectedSpecializationType(const ASTContext &Ctx) const
Retrieves the canonical injected specialization type for this partial specialization.
Definition DeclTemplate.cpp:1208
void Profile(llvm::FoldingSetNodeID &ID) const
bool isMemberSpecialization() const
Determines whether this class template partial specialization template was a specialization of a memb...
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition DeclTemplate.cpp:1220
static ClassTemplatePartialSpecializationDecl * Create(ASTContext &Context, TagKind TK, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, TemplateParameterList *Params, ClassTemplateDecl *SpecializedTemplate, ArrayRef< TemplateArgument > Args, CanQualType CanonInjectedTST, ClassTemplatePartialSpecializationDecl *PrevDecl)
Definition DeclTemplate.cpp:1188
static ClassTemplatePartialSpecializationDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition DeclTemplate.cpp:1202
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Represents a class template specialization, which refers to a class template with a given set of temp...
TemplateSpecializationKind getSpecializationKind() const
Determine the kind of specialization that this declaration represents.
const ASTTemplateArgumentListInfo * getTemplateArgsAsWritten() const
Retrieve the template argument list as written in the sources, if any.
ClassTemplateDecl * getSpecializedTemplate() const
Retrieve the template that this specialization specializes.
Definition DeclTemplate.cpp:1034
static ClassTemplateSpecializationDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition DeclTemplate.cpp:1009
llvm::PointerUnion< ClassTemplateDecl *, ClassTemplatePartialSpecializationDecl * > getSpecializedTemplateOrPartial() const
Retrieve the class template or class template partial specialization which was specialized by this.
void getNameForDiagnostic(raw_ostream &OS, const PrintingPolicy &Policy, bool Qualified) const override
Appends a human-readable name for this declaration into the given stream.
Definition DeclTemplate.cpp:1015
static ClassTemplateSpecializationDecl * Create(ASTContext &Context, TagKind TK, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, ClassTemplateDecl *SpecializedTemplate, ArrayRef< TemplateArgument > Args, bool StrictPackMatch, ClassTemplateSpecializationDecl *PrevDecl)
Definition DeclTemplate.cpp:988
void setExternKeywordLoc(SourceLocation Loc)
Sets the location of the extern keyword.
Definition DeclTemplate.cpp:1079
const TemplateArgumentList & getTemplateArgs() const
Retrieve the template arguments of the class template specialization.
SourceLocation getExternKeywordLoc() const
Gets the location of the extern keyword, if present.
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition DeclTemplate.cpp:1042
SourceLocation getTemplateKeywordLoc() const
Gets the location of the template keyword, if present.
ClassTemplateSpecializationDecl(ASTContext &Context, Kind DK, TagKind TK, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, ClassTemplateDecl *SpecializedTemplate, ArrayRef< TemplateArgument > Args, bool StrictPackMatch, ClassTemplateSpecializationDecl *PrevDecl)
Definition DeclTemplate.cpp:969
void setTemplateKeywordLoc(SourceLocation Loc)
Sets the location of the template keyword.
Definition DeclTemplate.cpp:1092
ConceptDecl(DeclContext *DC, SourceLocation L, DeclarationName Name, TemplateParameterList *Params, Expr *ConstraintExpr)
static ConceptDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition DeclTemplate.cpp:1120
static ConceptDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, TemplateParameterList *Params, Expr *ConstraintExpr=nullptr)
Definition DeclTemplate.cpp:1109
A reference to a concept and its template args, as it appears in the code.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Decl - This represents one declaration (or definition), e.g.
ASTContext & getASTContext() const LLVM_READONLY
ASTMutationListener * getASTMutationListener() const
void setInvalidDecl(bool Invalid=true)
setInvalidDecl - Indicates the Decl had a semantic error.
Kind
Lists the kind of concrete classes of Decl.
bool isCanonicalDecl() const
Whether this particular Decl is a canonical one.
bool isInvalidDecl() const
bool isTemplateParameterPack() const
isTemplateParameter - Determines whether this declaration is a template parameter pack.
void setDeclContext(DeclContext *DC)
setDeclContext - Set both the semantic and lexical DeclContext to DC.
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
The name of a declaration.
Represents a ValueDecl that came out of a declarator.
SourceLocation getOuterLocStart() const
Return start of source range taking into account any outer template declarations.
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
unsigned getNumTemplateParameterLists() const
EnumDecl * getInstantiatedFromMemberEnum() const
Returns the enumeration (declared within the template) from which this enumeration type was instantia...
This represents one expression.
bool containsUnexpandedParameterPack() const
Whether this expression contains an unexpanded parameter pack (for C++11 variadic templates).
virtual bool LoadExternalSpecializations(const Decl *D, bool OnlyPartial)
Load all the external specializations for the Decl.
Declaration of a friend template.
static FriendTemplateDecl * Create(ASTContext &Context, DeclContext *DC, SourceLocation Loc, MutableArrayRef< TemplateParameterList * > Params, FriendUnion Friend, SourceLocation FriendLoc)
Definition DeclTemplate.cpp:1239
llvm::PointerUnion< NamedDecl *, TypeSourceInfo * > FriendUnion
static FriendTemplateDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition DeclTemplate.cpp:1252
Represents a function declaration or definition.
FunctionDecl * getInstantiatedFromMemberFunction() const
If this function is an instantiation of a member function of a class template specialization,...
Declaration of a template function.
FunctionDecl * findSpecialization(ArrayRef< TemplateArgument > Args, void *&InsertPos)
Return the specialization with the provided arguments if it exists, otherwise return the insertion po...
Definition DeclTemplate.cpp:481
void addSpecialization(FunctionTemplateSpecializationInfo *Info, void *InsertPos)
Add a specialization of this function template.
Definition DeclTemplate.cpp:487
CommonBase * newCommon(ASTContext &C) const override
Definition DeclTemplate.cpp:464
Common * getCommonPtr() const
FunctionTemplateDecl * getPreviousDecl()
Retrieve the previous declaration of this function template, or nullptr if no such declaration exists...
static FunctionTemplateDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Create an empty function template node.
Definition DeclTemplate.cpp:458
FunctionTemplateDecl(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, TemplateParameterList *Params, NamedDecl *Decl)
static FunctionTemplateDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, TemplateParameterList *Params, NamedDecl *Decl)
Create a function template node.
Definition DeclTemplate.cpp:447
llvm::FoldingSetVector< FunctionTemplateSpecializationInfo > & getSpecializations() const
Retrieve the set of function template specializations of this function template.
Definition DeclTemplate.cpp:475
void mergePrevDecl(FunctionTemplateDecl *Prev)
Merge Prev with our RedeclarableTemplateDecl::Common.
Definition DeclTemplate.cpp:494
void LoadLazySpecializations() const
Load any lazily-loaded specializations from the external source.
Definition DeclTemplate.cpp:470
Provides information about a function template specialization, which is a FunctionDecl that has been ...
static FunctionTemplateSpecializationInfo * Create(ASTContext &C, FunctionDecl *FD, FunctionTemplateDecl *Template, TemplateSpecializationKind TSK, TemplateArgumentList *TemplateArgs, const TemplateArgumentListInfo *TemplateArgsAsWritten, SourceLocation POI, MemberSpecializationInfo *MSInfo)
Definition DeclTemplate.cpp:949
One of these records is kept for each identifier that is lexed.
void setTemplateArguments(ArrayRef< TemplateArgument > Converted)
Definition DeclTemplate.cpp:1159
static ImplicitConceptSpecializationDecl * Create(const ASTContext &C, DeclContext *DC, SourceLocation SL, ArrayRef< TemplateArgument > ConvertedArgs)
Definition DeclTemplate.cpp:1144
static ImplicitConceptSpecializationDecl * CreateDeserialized(const ASTContext &C, GlobalDeclID ID, unsigned NumTemplateArgs)
Definition DeclTemplate.cpp:1153
Provides information a specialization of a member of a class template, which may be a member function...
This represents a decl that may have a name.
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
NamedDecl(Kind DK, DeclContext *DC, SourceLocation L, DeclarationName N)
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
NamedDecl * getMostRecentDecl()
virtual void getNameForDiagnostic(raw_ostream &OS, const PrintingPolicy &Policy, bool Qualified) const
Appends a human-readable name for this declaration into the given stream.
NonTypeTemplateParmDecl - Declares a non-type template parameter, e.g., "Size" in.
static NonTypeTemplateParmDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID, bool HasTypeConstraint)
Definition DeclTemplate.cpp:816
SourceLocation getDefaultArgumentLoc() const
Retrieve the location of the default argument, if any.
Definition DeclTemplate.cpp:852
bool hasDefaultArgument() const
Determine whether this template parameter has a default argument.
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition DeclTemplate.cpp:845
bool defaultArgumentWasInherited() const
Determines whether the default argument was inherited from a previous declaration of this template.
const TemplateArgumentLoc & getDefaultArgument() const
Retrieve the default argument, if any.
static NonTypeTemplateParmDecl * Create(const ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, unsigned D, unsigned P, const IdentifierInfo *Id, QualType T, bool ParameterPack, TypeSourceInfo *TInfo)
Definition DeclTemplate.cpp:779
void setPlaceholderTypeConstraint(Expr *E)
void setDefaultArgument(const ASTContext &C, const TemplateArgumentLoc &DefArg)
Set the default argument for this template parameter, and whether that default argument was inherited...
Definition DeclTemplate.cpp:857
A (possibly-)qualified type.
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
void print(raw_ostream &OS, const PrintingPolicy &Policy, const Twine &PlaceHolder=Twine(), unsigned Indentation=0) const
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
RedeclarableTemplateDecl(Kind DK, ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, TemplateParameterList *Params, NamedDecl *Decl)
void loadLazySpecializationsImpl(bool OnlyPartial=false) const
Definition DeclTemplate.cpp:356
CommonBase * getCommonPtr() const
Retrieves the "common" pointer shared by all (re-)declarations of the same template.
Definition DeclTemplate.cpp:324
RedeclarableTemplateDecl * getPreviousDecl()
Return the previous declaration of this declaration or NULL if this is the first declaration.
CommonBase * Common
Pointer to the common data shared by all declarations of this template.
SpecEntryTraits< EntryType >::DeclType * findSpecializationImpl(llvm::FoldingSetVector< EntryType > &Specs, void *&InsertPos, ProfileArguments... ProfileArgs)
Definition DeclTemplate.cpp:397
virtual CommonBase * newCommon(ASTContext &C) const =0
RedeclarableTemplateDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this template.
void addSpecializationImpl(llvm::FoldingSetVector< EntryType > &Specs, EntryType *Entry, void *InsertPos)
Definition DeclTemplate.cpp:411
SpecEntryTraits< EntryType >::DeclType * findSpecializationLocally(llvm::FoldingSetVector< EntryType > &Specs, void *&InsertPos, ProfileArguments... ProfileArgs)
Definition DeclTemplate.cpp:384
ArrayRef< TemplateArgument > getInjectedTemplateArgs(const ASTContext &Context) const
Retrieve the "injected" template arguments that correspond to the template parameters of this templat...
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
A trivial tuple used to represent a source range.
SourceLocation getBegin() const
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context, bool Canonical, bool ProfileLambdaExpr=false) const
Produce a unique representation of the given statement.
bool isThisDeclarationADefinition() const
Return true if this declaration is a completion definition of the type.
unsigned getNumTemplateParameterLists() const
A convenient class for passing around template argument information.
A template argument list.
static TemplateArgumentList * CreateCopy(ASTContext &Context, ArrayRef< TemplateArgument > Args)
Create a new template argument list that copies the given set of template arguments.
Definition DeclTemplate.cpp:943
Location wrapper for a TemplateArgument.
SourceLocation getLocation() const
const TemplateArgument & getArgument() const
SourceRange getSourceRange() const LLVM_READONLY
Represents a template argument.
bool isNull() const
Determine whether this template argument has no value.
The base class of all kinds of template declarations (e.g., class, function, etc.).
NamedDecl * TemplatedDecl
TemplateParameterList * TemplateParams
void getAssociatedConstraints(llvm::SmallVectorImpl< AssociatedConstraint > &AC) const
Get the total constraint-expression associated with this template, including constraint-expressions d...
Definition DeclTemplate.cpp:291
bool isTypeAlias() const
Definition DeclTemplate.cpp:307
bool hasAssociatedConstraints() const
Definition DeclTemplate.cpp:299
NamedDecl * getTemplatedDecl() const
Get the underlying, templated declaration.
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
TemplateDecl(Kind DK, DeclContext *DC, SourceLocation L, DeclarationName Name, TemplateParameterList *Params, NamedDecl *Decl)
Definition DeclTemplate.cpp:284
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Represents a C++ template name within the type system.
TemplateDecl * getAsTemplateDecl(bool IgnoreDeduced=false) const
Retrieve the underlying template declaration that this template name refers to, if known.
A template parameter object.
void printAsExpr(llvm::raw_ostream &OS) const
Print this object as an equivalent expression.
Definition DeclTemplate.cpp:1637
const APValue & getValue() const
void printName(llvm::raw_ostream &OS, const PrintingPolicy &Policy) const override
Print this template parameter object in a human-readable format.
Definition DeclTemplate.cpp:1630
void printAsInit(llvm::raw_ostream &OS) const
Print this object as an initializer suitable for a variable of the object's type.
Definition DeclTemplate.cpp:1647
Stores a list of template parameters for a TemplateDecl and its derived classes.
NamedDecl * getParam(unsigned Idx)
ArrayRef< TemplateArgument > getInjectedTemplateArgs(const ASTContext &Context)
Get the template argument list of the template parameter list.
unsigned getDepth() const
Get the depth of this template parameter list in the set of template parameter lists.
bool hasAssociatedConstraints() const
unsigned getMinRequiredArguments() const
Returns the minimum number of arguments needed to form a template specialization.
static TemplateParameterList * Create(const ASTContext &C, SourceLocation TemplateLoc, SourceLocation LAngleLoc, ArrayRef< NamedDecl * > Params, SourceLocation RAngleLoc, Expr *RequiresClause)
Expr * getRequiresClause()
The constraint-expression of the associated requires-clause.
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &C) const
bool containsUnexpandedParameterPack() const
Determine whether this template parameter list contains an unexpanded parameter pack.
TemplateParameterList(const ASTContext &C, SourceLocation TemplateLoc, SourceLocation LAngleLoc, ArrayRef< NamedDecl * > Params, SourceLocation RAngleLoc, Expr *RequiresClause)
void getAssociatedConstraints(llvm::SmallVectorImpl< AssociatedConstraint > &AC) const
All associated constraints derived from this template parameter list, including the requires clause a...
ArrayRef< NamedDecl * > asArray()
static bool shouldIncludeTypeForArgument(const PrintingPolicy &Policy, const TemplateParameterList *TPL, unsigned Idx)
SourceLocation getTemplateLoc() const
Defines the position of a template parameter within a template parameter list.
TemplateTemplateParmDecl - Declares a template template parameter, e.g., "T" in.
const TemplateArgumentLoc & getDefaultArgument() const
Retrieve the default argument, if any.
static TemplateTemplateParmDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition DeclTemplate.cpp:903
static TemplateTemplateParmDecl * Create(const ASTContext &C, DeclContext *DC, SourceLocation L, unsigned D, unsigned P, bool ParameterPack, IdentifierInfo *Id, TemplateNameKind ParameterKind, bool Typename, TemplateParameterList *Params)
Definition DeclTemplate.cpp:882
SourceLocation getDefaultArgumentLoc() const
Retrieve the location of the default argument, if any.
Definition DeclTemplate.cpp:921
void setDefaultArgument(const ASTContext &C, const TemplateArgumentLoc &DefArg)
Set the default argument for this template parameter, and whether that default argument was inherited...
Definition DeclTemplate.cpp:926
bool hasDefaultArgument() const
Determine whether this template parameter has a default argument.
Declaration of a template type parameter.
SourceLocation getDefaultArgumentLoc() const
Retrieves the location of the default argument declaration.
Definition DeclTemplate.cpp:708
const TemplateArgumentLoc & getDefaultArgument() const
Retrieve the default argument, if any.
unsigned getIndex() const
Retrieve the index of the template parameter.
Definition DeclTemplate.cpp:737
void setTypeConstraint(ConceptReference *CR, Expr *ImmediatelyDeclaredConstraint, UnsignedOrNone ArgPackSubstIndex)
Definition DeclTemplate.cpp:745
static TemplateTypeParmDecl * CreateDeserialized(const ASTContext &C, GlobalDeclID ID)
Definition DeclTemplate.cpp:693
bool hasDefaultArgument() const
Determine whether this template parameter has a default argument.
bool defaultArgumentWasInherited() const
Determines whether the default argument was inherited from a previous declaration of this template.
bool isParameterPack() const
Returns whether this is a parameter pack.
Definition DeclTemplate.cpp:741
static TemplateTypeParmDecl * Create(const ASTContext &C, DeclContext *DC, SourceLocation KeyLoc, SourceLocation NameLoc, unsigned D, unsigned P, IdentifierInfo *Id, bool Typename, bool ParameterPack, bool HasTypeConstraint=false, UnsignedOrNone NumExpanded=std::nullopt)
Definition DeclTemplate.cpp:677
unsigned getDepth() const
Retrieve the depth of the template parameter.
Definition DeclTemplate.cpp:733
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition DeclTemplate.cpp:713
void setDefaultArgument(const ASTContext &C, const TemplateArgumentLoc &DefArg)
Set the default argument for this template parameter.
Definition DeclTemplate.cpp:725
Declaration of an alias template.
CommonBase * newCommon(ASTContext &C) const override
Definition DeclTemplate.cpp:1279
static TypeAliasTemplateDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Create an empty alias template node.
Definition DeclTemplate.cpp:1273
TypeAliasTemplateDecl(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, TemplateParameterList *Params, NamedDecl *Decl)
static TypeAliasTemplateDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, TemplateParameterList *Params, NamedDecl *Decl)
Create a function template node.
Definition DeclTemplate.cpp:1262
Models the abbreviated syntax to constrain a template type parameter: template <convertible_to<string...
Expr * getImmediatelyDeclaredConstraint() const
Get the immediately-declared constraint expression introduced by this type-constraint,...
const Type * getTypeForDecl() const
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
SourceLocation getBeginLoc() const LLVM_READONLY
A container of type source information.
QualType getType() const
Return the type wrapped by this type source info.
AutoType * getContainedAutoType() const
Get the AutoType whose type will be deduced for a variable with an initializer of this type.
Represents a variable declaration or definition.
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
VarDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
VarDecl * getInstantiatedFromStaticDataMember() const
If this variable is an instantiated static data member of a class template specialization,...
@ Definition
This declaration is definitely a definition.
Declaration of a variable template.
VarTemplateDecl * getDefinition()
Definition DeclTemplate.cpp:1289
VarTemplateDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this template.
void AddPartialSpecialization(VarTemplatePartialSpecializationDecl *D, void *InsertPos)
Insert the specified partial specialization knowing that it is not already in.
Definition DeclTemplate.cpp:1369
Common * getCommonPtr() const
VarTemplatePartialSpecializationDecl * findPartialSpecialization(ArrayRef< TemplateArgument > Args, TemplateParameterList *TPL, void *&InsertPos)
Return the partial specialization with the provided arguments if it exists, otherwise return the inse...
Definition DeclTemplate.cpp:1354
void AddSpecialization(VarTemplateSpecializationDecl *D, void *InsertPos)
Insert the specified specialization knowing that it is not already in.
Definition DeclTemplate.cpp:1347
VarTemplateDecl * getPreviousDecl()
Retrieve the previous declaration of this variable template, or nullptr if no such declaration exists...
CommonBase * newCommon(ASTContext &C) const override
Definition DeclTemplate.cpp:1334
void LoadLazySpecializations(bool OnlyPartial=false) const
Load any lazily-loaded specializations from the external source.
Definition DeclTemplate.cpp:1316
VarTemplateDecl(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, TemplateParameterList *Params, NamedDecl *Decl)
static VarTemplateDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Create an empty variable template node.
Definition DeclTemplate.cpp:1310
static VarTemplateDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, TemplateParameterList *Params, VarDecl *Decl)
Create a variable template node.
Definition DeclTemplate.cpp:1299
llvm::FoldingSetVector< VarTemplatePartialSpecializationDecl > & getPartialSpecializations() const
Retrieve the set of partial specializations of this class template.
Definition DeclTemplate.cpp:1328
llvm::FoldingSetVector< VarTemplateSpecializationDecl > & getSpecializations() const
Retrieve the set of specializations of this variable template.
Definition DeclTemplate.cpp:1322
bool isThisDeclarationADefinition() const
Returns whether this template declaration defines the primary variable pattern.
VarTemplateSpecializationDecl * findSpecialization(ArrayRef< TemplateArgument > Args, void *&InsertPos)
Return the specialization with the provided arguments if it exists, otherwise return the insertion po...
Definition DeclTemplate.cpp:1341
VarTemplatePartialSpecializationDecl * findPartialSpecInstantiatedFromMember(VarTemplatePartialSpecializationDecl *D)
Find a variable template partial specialization which was instantiated from the given member partial ...
Definition DeclTemplate.cpp:1395
static VarTemplatePartialSpecializationDecl * Create(ASTContext &Context, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, TemplateParameterList *Params, VarTemplateDecl *SpecializedTemplate, QualType T, TypeSourceInfo *TInfo, StorageClass S, ArrayRef< TemplateArgument > Args)
Definition DeclTemplate.cpp:1555
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition DeclTemplate.cpp:1573
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
VarTemplatePartialSpecializationDecl * getInstantiatedFromMember() const
Retrieve the member variable template partial specialization from which this particular variable temp...
bool isMemberSpecialization() const
Determines whether this variable template partial specialization was a specialization of a member par...
void Profile(llvm::FoldingSetNodeID &ID) const
static VarTemplatePartialSpecializationDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition DeclTemplate.cpp:1568
Represents a variable template specialization, which refers to a variable template with a given set o...
VarTemplateSpecializationDecl(Kind DK, ASTContext &Context, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, VarTemplateDecl *SpecializedTemplate, QualType T, TypeSourceInfo *TInfo, StorageClass S, ArrayRef< TemplateArgument > Args)
Definition DeclTemplate.cpp:1410
const ASTTemplateArgumentListInfo * getTemplateArgsAsWritten() const
Retrieve the template argument list as written in the sources, if any.
void setTemplateKeywordLoc(SourceLocation Loc)
Sets the location of the template keyword.
Definition DeclTemplate.cpp:1522
const TemplateArgumentList & getTemplateArgs() const
Retrieve the template arguments of the variable template specialization.
SourceLocation getTemplateKeywordLoc() const
Gets the location of the template keyword, if present.
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition DeclTemplate.cpp:1467
static VarTemplateSpecializationDecl * Create(ASTContext &Context, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, VarTemplateDecl *SpecializedTemplate, QualType T, TypeSourceInfo *TInfo, StorageClass S, ArrayRef< TemplateArgument > Args)
Definition DeclTemplate.cpp:1426
llvm::PointerUnion< VarTemplateDecl *, VarTemplatePartialSpecializationDecl * > getSpecializedTemplateOrPartial() const
Retrieve the variable template or variable template partial specialization which was specialized by t...
TemplateSpecializationKind getSpecializationKind() const
Determine the kind of specialization that this declaration represents.
VarTemplateDecl * getSpecializedTemplate() const
Retrieve the template that this specialization specializes.
Definition DeclTemplate.cpp:1460
SourceLocation getExternKeywordLoc() const
Gets the location of the extern keyword, if present.
static VarTemplateSpecializationDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition DeclTemplate.cpp:1436
void setExternKeywordLoc(SourceLocation Loc)
Sets the location of the extern keyword.
Definition DeclTemplate.cpp:1509
void getNameForDiagnostic(raw_ostream &OS, const PrintingPolicy &Policy, bool Qualified) const override
Appends a human-readable name for this declaration into the given stream.
Definition DeclTemplate.cpp:1442
The JSON file list parser is used to communicate input to InstallAPI.
CanQual< Type > CanQualType
Represents a canonical, potentially-qualified type.
bool isa(CodeGen::Address addr)
bool isPackProducingBuiltinTemplateName(TemplateName N)
Definition DeclTemplate.cpp:1608
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
StorageClass
Storage classes.
UnsignedOrNone getExpandedPackSize(const NamedDecl *Param)
Check whether the template parameter is a pack expansion, and if so, determine the number of paramete...
void * allocateDefaultArgStorageChain(const ASTContext &C)
Definition DeclTemplate.cpp:274
@ Result
The result type of a method or function.
const FunctionProtoType * T
TagTypeKind
The kind of a tag type.
BuiltinTemplateKind
Kinds of BuiltinTemplateDecl.
std::tuple< NamedDecl *, TemplateArgument > getReplacedTemplateParameter(Decl *D, unsigned Index)
Internal helper used by Subst* nodes to retrieve a parameter from the AssociatedDecl,...
Definition DeclTemplate.cpp:1657
TemplateNameKind
Specifies the kind of template name that an identifier refers to.
@ TNK_Type_template
The name refers to a template whose specialization produces a type.
const Decl & adjustDeclToTemplate(const Decl &D)
If we have a 'templated' declaration for a template, adjust 'D' to refer to the actual template.
Definition DeclTemplate.cpp:1725
TemplateSpecializationKind
Describes the kind of template specialization that a particular template specialization declaration r...
@ TSK_ExplicitInstantiationDefinition
This template specialization was instantiated from a template due to an explicit instantiation defini...
@ TSK_ExplicitInstantiationDeclaration
This template specialization was instantiated from a template due to an explicit instantiation declar...
@ TSK_ExplicitSpecialization
This template specialization was declared or defined by an explicit specialization (C++ [temp....
@ TSK_ImplicitInstantiation
This template specialization was implicitly instantiated from a template.
@ TSK_Undeclared
This template specialization was formed from a template-id but has not yet been declared,...
U cast(CodeGen::Address addr)
@ None
No keyword precedes the qualified type name.
@ Struct
The "struct" keyword introduces the elaborated-type-specifier.
@ Typename
The "typename" keyword precedes the qualified type name, e.g., typename T::type.
Represents an explicit template argument list in C++, e.g., the "" in "sort".
static const ASTTemplateArgumentListInfo * Create(const ASTContext &C, const TemplateArgumentListInfo &List)
Data that is common to all of the declarations of a given class template.
CanQualType CanonInjectedTST
The Injected Template Specialization Type for this declaration.
llvm::FoldingSetVector< ClassTemplatePartialSpecializationDecl > PartialSpecializations
The class template partial specializations for this class template.
llvm::FoldingSetVector< ClassTemplateSpecializationDecl > Specializations
The class template specializations for this class template, including explicit specializations and in...
A placeholder type used to construct an empty shell of a decl-derived type that will be filled in lat...
Provides information about an explicit instantiation of a variable or class template.
const ASTTemplateArgumentListInfo * TemplateArgsAsWritten
The template arguments as written..
Data that is common to all of the declarations of a given function template.
llvm::FoldingSetVector< FunctionTemplateSpecializationInfo > Specializations
The function template specializations for this function template, including explicit specializations ...
Describes how types, statements, expressions, and declarations should be printed.
unsigned AlwaysIncludeTypeForTemplateArgument
Whether to use type suffixes (eg: 1U) on integral non-type template parameters.
Data that is common to all of the declarations of a given variable template.
llvm::FoldingSetVector< VarTemplatePartialSpecializationDecl > PartialSpecializations
The variable template partial specializations for this variable template.
llvm::FoldingSetVector< VarTemplateSpecializationDecl > Specializations
The variable template specializations for this variable template, including explicit specializations ...