blob: 0990057df4f16e375f3182292222627493e2d307 [file] [log] [blame]
Douglas Gregor74296542009-02-27 19:31:52 +00001//===------- SemaTemplateInstantiate.cpp - C++ Template Instantiation ------===/
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//===----------------------------------------------------------------------===/
8//
9// This file implements C++ template instantiation.
10//
11//===----------------------------------------------------------------------===/
12
13#include "Sema.h"
14#include "clang/AST/ASTContext.h"
15#include "clang/AST/Expr.h"
16#include "clang/AST/ExprCXX.h"
17#include "clang/AST/DeclTemplate.h"
18#include "clang/Parse/DeclSpec.h"
19#include "clang/Basic/LangOptions.h"
Douglas Gregorf57dcd02009-02-28 00:25:32 +000020#include "llvm/Support/Compiler.h"
Douglas Gregor74296542009-02-27 19:31:52 +000021
22using namespace clang;
23
Douglas Gregor375733c2009-03-10 00:06:19 +000024Sema::InstantiatingTemplate::
25InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
26 ClassTemplateSpecializationDecl *Entity,
27 SourceRange InstantiationRange)
28 : SemaRef(SemaRef) {
29 if (SemaRef.ActiveTemplateInstantiations.size()
30 > SemaRef.getLangOptions().InstantiationDepth) {
31 SemaRef.Diag(PointOfInstantiation,
32 diag::err_template_recursion_depth_exceeded)
33 << SemaRef.getLangOptions().InstantiationDepth
34 << InstantiationRange;
35 SemaRef.Diag(PointOfInstantiation, diag::note_template_recursion_depth)
36 << SemaRef.getLangOptions().InstantiationDepth;
37 Invalid = true;
38 } else {
39 ActiveTemplateInstantiation Inst;
40 Inst.PointOfInstantiation = PointOfInstantiation;
41 Inst.Entity = Entity;
42 Inst.InstantiationRange = InstantiationRange;
43 SemaRef.ActiveTemplateInstantiations.push_back(Inst);
44 Invalid = false;
45 }
46}
47
48Sema::InstantiatingTemplate::~InstantiatingTemplate() {
49 if (!Invalid)
50 SemaRef.ActiveTemplateInstantiations.pop_back();
51}
52
Douglas Gregor74296542009-02-27 19:31:52 +000053//===----------------------------------------------------------------------===/
54// Template Instantiation for Types
55//===----------------------------------------------------------------------===/
Douglas Gregorf57dcd02009-02-28 00:25:32 +000056namespace {
57 class VISIBILITY_HIDDEN TemplateTypeInstantiator {
58 Sema &SemaRef;
59 const TemplateArgument *TemplateArgs;
60 unsigned NumTemplateArgs;
61 SourceLocation Loc;
62 DeclarationName Entity;
Douglas Gregor74296542009-02-27 19:31:52 +000063
Douglas Gregorf57dcd02009-02-28 00:25:32 +000064 public:
65 TemplateTypeInstantiator(Sema &SemaRef,
66 const TemplateArgument *TemplateArgs,
67 unsigned NumTemplateArgs,
68 SourceLocation Loc,
69 DeclarationName Entity)
70 : SemaRef(SemaRef), TemplateArgs(TemplateArgs),
71 NumTemplateArgs(NumTemplateArgs), Loc(Loc), Entity(Entity) { }
72
73 QualType operator()(QualType T) const { return Instantiate(T); }
74
75 QualType Instantiate(QualType T) const;
76
77 // Declare instantiate functions for each type.
78#define TYPE(Class, Base) \
79 QualType Instantiate##Class##Type(const Class##Type *T, \
80 unsigned Quals) const;
81#define ABSTRACT_TYPE(Class, Base)
82#include "clang/AST/TypeNodes.def"
83 };
84}
85
86QualType
87TemplateTypeInstantiator::InstantiateExtQualType(const ExtQualType *T,
88 unsigned Quals) const {
Douglas Gregor74296542009-02-27 19:31:52 +000089 // FIXME: Implement this
90 assert(false && "Cannot instantiate ExtQualType yet");
91 return QualType();
92}
93
Douglas Gregorf57dcd02009-02-28 00:25:32 +000094QualType
95TemplateTypeInstantiator::InstantiateBuiltinType(const BuiltinType *T,
96 unsigned Quals) const {
Douglas Gregorc0139ca2009-02-28 01:04:19 +000097 assert(false && "Builtin types are not dependent and cannot be instantiated");
Douglas Gregorf57dcd02009-02-28 00:25:32 +000098 return QualType(T, Quals);
Douglas Gregor74296542009-02-27 19:31:52 +000099}
100
Douglas Gregorf57dcd02009-02-28 00:25:32 +0000101QualType
102TemplateTypeInstantiator::
103InstantiateFixedWidthIntType(const FixedWidthIntType *T, unsigned Quals) const {
Douglas Gregor74296542009-02-27 19:31:52 +0000104 // FIXME: Implement this
105 assert(false && "Cannot instantiate FixedWidthIntType yet");
106 return QualType();
107}
108
Douglas Gregorf57dcd02009-02-28 00:25:32 +0000109QualType
110TemplateTypeInstantiator::InstantiateComplexType(const ComplexType *T,
111 unsigned Quals) const {
Douglas Gregor74296542009-02-27 19:31:52 +0000112 // FIXME: Implement this
113 assert(false && "Cannot instantiate ComplexType yet");
114 return QualType();
115}
116
Douglas Gregorf57dcd02009-02-28 00:25:32 +0000117QualType
118TemplateTypeInstantiator::InstantiatePointerType(const PointerType *T,
119 unsigned Quals) const {
120 QualType PointeeType = Instantiate(T->getPointeeType());
121 if (PointeeType.isNull())
122 return QualType();
123
124 return SemaRef.BuildPointerType(PointeeType, Quals, Loc, Entity);
Douglas Gregor74296542009-02-27 19:31:52 +0000125}
126
Douglas Gregorf57dcd02009-02-28 00:25:32 +0000127QualType
128TemplateTypeInstantiator::InstantiateBlockPointerType(const BlockPointerType *T,
129 unsigned Quals) const {
Douglas Gregor74296542009-02-27 19:31:52 +0000130 // FIXME: Implement this
131 assert(false && "Cannot instantiate BlockPointerType yet");
132 return QualType();
133}
134
Douglas Gregorf57dcd02009-02-28 00:25:32 +0000135QualType
136TemplateTypeInstantiator::InstantiateReferenceType(const ReferenceType *T,
137 unsigned Quals) const {
138 QualType ReferentType = Instantiate(T->getPointeeType());
139 if (ReferentType.isNull())
140 return QualType();
141
142 return SemaRef.BuildReferenceType(ReferentType, Quals, Loc, Entity);
Douglas Gregor74296542009-02-27 19:31:52 +0000143}
144
Douglas Gregorf57dcd02009-02-28 00:25:32 +0000145QualType
146TemplateTypeInstantiator::
147InstantiateMemberPointerType(const MemberPointerType *T,
148 unsigned Quals) const {
Douglas Gregor74296542009-02-27 19:31:52 +0000149 // FIXME: Implement this
150 assert(false && "Cannot instantiate MemberPointerType yet");
151 return QualType();
152}
153
Douglas Gregorf57dcd02009-02-28 00:25:32 +0000154QualType
155TemplateTypeInstantiator::
156InstantiateConstantArrayType(const ConstantArrayType *T,
157 unsigned Quals) const {
158 QualType ElementType = Instantiate(T->getElementType());
159 if (ElementType.isNull())
160 return ElementType;
161
162 // Build a temporary integer literal to specify the size for
163 // BuildArrayType. Since we have already checked the size as part of
164 // creating the dependent array type in the first place, we know
165 // there aren't any errors.
Douglas Gregor448fcd32009-03-09 20:07:22 +0000166 // FIXME: Is IntTy big enough? Maybe not, but LongLongTy causes
167 // problems that I have yet to investigate.
168 IntegerLiteral ArraySize(T->getSize(), SemaRef.Context.IntTy, Loc);
Douglas Gregorf57dcd02009-02-28 00:25:32 +0000169 return SemaRef.BuildArrayType(ElementType, T->getSizeModifier(),
170 &ArraySize, T->getIndexTypeQualifier(),
171 Loc, Entity);
Douglas Gregor74296542009-02-27 19:31:52 +0000172}
173
Douglas Gregorf57dcd02009-02-28 00:25:32 +0000174QualType
175TemplateTypeInstantiator::
176InstantiateIncompleteArrayType(const IncompleteArrayType *T,
177 unsigned Quals) const {
178 QualType ElementType = Instantiate(T->getElementType());
179 if (ElementType.isNull())
180 return ElementType;
181
182 return SemaRef.BuildArrayType(ElementType, T->getSizeModifier(),
183 0, T->getIndexTypeQualifier(),
184 Loc, Entity);
Douglas Gregor74296542009-02-27 19:31:52 +0000185}
186
Douglas Gregorf57dcd02009-02-28 00:25:32 +0000187QualType
188TemplateTypeInstantiator::
189InstantiateVariableArrayType(const VariableArrayType *T,
190 unsigned Quals) const {
Douglas Gregor74296542009-02-27 19:31:52 +0000191 // FIXME: Implement this
192 assert(false && "Cannot instantiate VariableArrayType yet");
193 return QualType();
194}
195
Douglas Gregorf57dcd02009-02-28 00:25:32 +0000196QualType
197TemplateTypeInstantiator::
198InstantiateDependentSizedArrayType(const DependentSizedArrayType *T,
199 unsigned Quals) const {
Douglas Gregor74296542009-02-27 19:31:52 +0000200 // FIXME: Implement this
201 assert(false && "Cannot instantiate DependentSizedArrayType yet");
202 return QualType();
203}
204
Douglas Gregorf57dcd02009-02-28 00:25:32 +0000205QualType
206TemplateTypeInstantiator::InstantiateVectorType(const VectorType *T,
207 unsigned Quals) const {
Douglas Gregor74296542009-02-27 19:31:52 +0000208 // FIXME: Implement this
209 assert(false && "Cannot instantiate VectorType yet");
210 return QualType();
211}
212
Douglas Gregorf57dcd02009-02-28 00:25:32 +0000213QualType
214TemplateTypeInstantiator::InstantiateExtVectorType(const ExtVectorType *T,
215 unsigned Quals) const {
Douglas Gregor74296542009-02-27 19:31:52 +0000216 // FIXME: Implement this
217 assert(false && "Cannot instantiate ExtVectorType yet");
218 return QualType();
219}
220
Douglas Gregorf57dcd02009-02-28 00:25:32 +0000221QualType
222TemplateTypeInstantiator::
223InstantiateFunctionProtoType(const FunctionProtoType *T,
224 unsigned Quals) const {
Douglas Gregorc0139ca2009-02-28 01:04:19 +0000225 QualType ResultType = Instantiate(T->getResultType());
226 if (ResultType.isNull())
227 return ResultType;
228
229 llvm::SmallVector<QualType, 16> ParamTypes;
230 for (FunctionProtoType::arg_type_iterator Param = T->arg_type_begin(),
231 ParamEnd = T->arg_type_end();
232 Param != ParamEnd; ++Param) {
233 QualType P = Instantiate(*Param);
234 if (P.isNull())
235 return P;
236
237 ParamTypes.push_back(P);
238 }
239
240 return SemaRef.BuildFunctionType(ResultType, &ParamTypes[0],
241 ParamTypes.size(),
242 T->isVariadic(), T->getTypeQuals(),
243 Loc, Entity);
Douglas Gregor74296542009-02-27 19:31:52 +0000244}
245
Douglas Gregorf57dcd02009-02-28 00:25:32 +0000246QualType
247TemplateTypeInstantiator::
248InstantiateFunctionNoProtoType(const FunctionNoProtoType *T,
249 unsigned Quals) const {
Douglas Gregorc0139ca2009-02-28 01:04:19 +0000250 assert(false && "Functions without prototypes cannot be dependent.");
Douglas Gregor74296542009-02-27 19:31:52 +0000251 return QualType();
252}
253
Douglas Gregorf57dcd02009-02-28 00:25:32 +0000254QualType
255TemplateTypeInstantiator::InstantiateTypedefType(const TypedefType *T,
256 unsigned Quals) const {
Douglas Gregor74296542009-02-27 19:31:52 +0000257 // FIXME: Implement this
258 assert(false && "Cannot instantiate TypedefType yet");
259 return QualType();
260}
261
Douglas Gregorf57dcd02009-02-28 00:25:32 +0000262QualType
263TemplateTypeInstantiator::InstantiateTypeOfExprType(const TypeOfExprType *T,
264 unsigned Quals) const {
Douglas Gregor74296542009-02-27 19:31:52 +0000265 // FIXME: Implement this
266 assert(false && "Cannot instantiate TypeOfExprType yet");
267 return QualType();
268}
269
Douglas Gregorf57dcd02009-02-28 00:25:32 +0000270QualType
271TemplateTypeInstantiator::InstantiateTypeOfType(const TypeOfType *T,
272 unsigned Quals) const {
Douglas Gregor74296542009-02-27 19:31:52 +0000273 // FIXME: Implement this
274 assert(false && "Cannot instantiate TypeOfType yet");
275 return QualType();
276}
277
Douglas Gregorf57dcd02009-02-28 00:25:32 +0000278QualType
279TemplateTypeInstantiator::InstantiateRecordType(const RecordType *T,
280 unsigned Quals) const {
Douglas Gregor74296542009-02-27 19:31:52 +0000281 // FIXME: Implement this
282 assert(false && "Cannot instantiate RecordType yet");
283 return QualType();
284}
285
Douglas Gregorf57dcd02009-02-28 00:25:32 +0000286QualType
Douglas Gregorf57dcd02009-02-28 00:25:32 +0000287TemplateTypeInstantiator::InstantiateEnumType(const EnumType *T,
288 unsigned Quals) const {
Douglas Gregor74296542009-02-27 19:31:52 +0000289 // FIXME: Implement this
290 assert(false && "Cannot instantiate EnumType yet");
291 return QualType();
292}
293
Douglas Gregorf57dcd02009-02-28 00:25:32 +0000294QualType
295TemplateTypeInstantiator::
296InstantiateTemplateTypeParmType(const TemplateTypeParmType *T,
297 unsigned Quals) const {
Douglas Gregor74296542009-02-27 19:31:52 +0000298 if (T->getDepth() == 0) {
299 // Replace the template type parameter with its corresponding
300 // template argument.
301 assert(T->getIndex() < NumTemplateArgs && "Wrong # of template args");
302 assert(TemplateArgs[T->getIndex()].getKind() == TemplateArgument::Type &&
303 "Template argument kind mismatch");
304 QualType Result = TemplateArgs[T->getIndex()].getAsType();
Douglas Gregorf57dcd02009-02-28 00:25:32 +0000305 if (Result.isNull() || !Quals)
Douglas Gregor74296542009-02-27 19:31:52 +0000306 return Result;
307
308 // C++ [dcl.ref]p1:
309 // [...] Cv-qualified references are ill-formed except when
310 // the cv-qualifiers are introduced through the use of a
311 // typedef (7.1.3) or of a template type argument (14.3), in
312 // which case the cv-qualifiers are ignored.
Douglas Gregorf57dcd02009-02-28 00:25:32 +0000313 if (Quals && Result->isReferenceType())
314 Quals = 0;
Douglas Gregor74296542009-02-27 19:31:52 +0000315
Douglas Gregorf57dcd02009-02-28 00:25:32 +0000316 return QualType(Result.getTypePtr(), Quals | Result.getCVRQualifiers());
Douglas Gregor74296542009-02-27 19:31:52 +0000317 }
318
319 // The template type parameter comes from an inner template (e.g.,
320 // the template parameter list of a member template inside the
321 // template we are instantiating). Create a new template type
322 // parameter with the template "level" reduced by one.
323 return SemaRef.Context.getTemplateTypeParmType(T->getDepth() - 1,
324 T->getIndex(),
Douglas Gregorf57dcd02009-02-28 00:25:32 +0000325 T->getName())
326 .getQualifiedType(Quals);
Douglas Gregor74296542009-02-27 19:31:52 +0000327}
328
Douglas Gregorf57dcd02009-02-28 00:25:32 +0000329QualType
330TemplateTypeInstantiator::
331InstantiateClassTemplateSpecializationType(
332 const ClassTemplateSpecializationType *T,
333 unsigned Quals) const {
Douglas Gregorf9ff4b12009-03-09 23:48:35 +0000334 llvm::SmallVector<TemplateArgument, 16> InstantiatedTemplateArgs;
335 InstantiatedTemplateArgs.reserve(T->getNumArgs());
336 for (ClassTemplateSpecializationType::iterator Arg = T->begin(),
337 ArgEnd = T->end();
338 Arg != ArgEnd; ++Arg) {
339 switch (Arg->getKind()) {
340 case TemplateArgument::Type: {
341 QualType T = SemaRef.InstantiateType(Arg->getAsType(),
342 TemplateArgs, NumTemplateArgs,
343 Arg->getLocation(),
344 DeclarationName());
345 if (T.isNull())
346 return QualType();
347
348 InstantiatedTemplateArgs.push_back(
349 TemplateArgument(Arg->getLocation(), T));
350 break;
351 }
352
353 case TemplateArgument::Declaration:
354 case TemplateArgument::Integral:
355 InstantiatedTemplateArgs.push_back(*Arg);
356 break;
357
358 case TemplateArgument::Expression:
359 assert(false && "Cannot instantiate expressions yet");
360 break;
361 }
362 }
363
364 // FIXME: We're missing the locations of the template name, '<', and
365 // '>'.
366 return SemaRef.CheckClassTemplateId(cast<ClassTemplateDecl>(T->getTemplate()),
367 Loc,
368 SourceLocation(),
369 &InstantiatedTemplateArgs[0],
370 InstantiatedTemplateArgs.size(),
371 SourceLocation());
Douglas Gregor74296542009-02-27 19:31:52 +0000372}
373
Douglas Gregorf57dcd02009-02-28 00:25:32 +0000374QualType
375TemplateTypeInstantiator::
376InstantiateObjCInterfaceType(const ObjCInterfaceType *T,
377 unsigned Quals) const {
378 assert(false && "Objective-C types cannot be dependent");
Douglas Gregor74296542009-02-27 19:31:52 +0000379 return QualType();
380}
381
Douglas Gregorf57dcd02009-02-28 00:25:32 +0000382QualType
383TemplateTypeInstantiator::
384InstantiateObjCQualifiedInterfaceType(const ObjCQualifiedInterfaceType *T,
385 unsigned Quals) const {
386 assert(false && "Objective-C types cannot be dependent");
Douglas Gregor74296542009-02-27 19:31:52 +0000387 return QualType();
388}
389
Douglas Gregorf57dcd02009-02-28 00:25:32 +0000390QualType
391TemplateTypeInstantiator::
392InstantiateObjCQualifiedIdType(const ObjCQualifiedIdType *T,
393 unsigned Quals) const {
394 assert(false && "Objective-C types cannot be dependent");
Douglas Gregor74296542009-02-27 19:31:52 +0000395 return QualType();
396}
397
Douglas Gregorf57dcd02009-02-28 00:25:32 +0000398QualType
399TemplateTypeInstantiator::
400InstantiateObjCQualifiedClassType(const ObjCQualifiedClassType *T,
401 unsigned Quals) const {
402 assert(false && "Objective-C types cannot be dependent");
Douglas Gregor74296542009-02-27 19:31:52 +0000403 return QualType();
404}
405
Douglas Gregorf57dcd02009-02-28 00:25:32 +0000406/// \brief The actual implementation of Sema::InstantiateType().
407QualType TemplateTypeInstantiator::Instantiate(QualType T) const {
408 // If T is not a dependent type, there is nothing to do.
409 if (!T->isDependentType())
410 return T;
411
412 switch (T->getTypeClass()) {
413#define TYPE(Class, Base) \
414 case Type::Class: \
415 return Instantiate##Class##Type(cast<Class##Type>(T.getTypePtr()), \
416 T.getCVRQualifiers());
417#define ABSTRACT_TYPE(Class, Base)
418#include "clang/AST/TypeNodes.def"
419 }
420
421 assert(false && "Not all types have been decoded for instantiation");
422 return QualType();
423}
Douglas Gregor74296542009-02-27 19:31:52 +0000424
425/// \brief Instantiate the type T with a given set of template arguments.
426///
427/// This routine substitutes the given template arguments into the
428/// type T and produces the instantiated type.
429///
430/// \param T the type into which the template arguments will be
431/// substituted. If this type is not dependent, it will be returned
432/// immediately.
433///
434/// \param TemplateArgs the template arguments that will be
435/// substituted for the top-level template parameters within T.
436///
437/// \param NumTemplateArgs the number of template arguments provided
438/// by TemplateArgs.
439///
440/// \param Loc the location in the source code where this substitution
441/// is being performed. It will typically be the location of the
442/// declarator (if we're instantiating the type of some declaration)
443/// or the location of the type in the source code (if, e.g., we're
444/// instantiating the type of a cast expression).
445///
446/// \param Entity the name of the entity associated with a declaration
447/// being instantiated (if any). May be empty to indicate that there
448/// is no such entity (if, e.g., this is a type that occurs as part of
449/// a cast expression) or that the entity has no name (e.g., an
450/// unnamed function parameter).
451///
452/// \returns If the instantiation succeeds, the instantiated
453/// type. Otherwise, produces diagnostics and returns a NULL type.
454QualType Sema::InstantiateType(QualType T,
455 const TemplateArgument *TemplateArgs,
456 unsigned NumTemplateArgs,
457 SourceLocation Loc, DeclarationName Entity) {
458 // If T is not a dependent type, there is nothing to do.
459 if (!T->isDependentType())
460 return T;
461
Douglas Gregorf57dcd02009-02-28 00:25:32 +0000462 TemplateTypeInstantiator Instantiator(*this, TemplateArgs, NumTemplateArgs,
463 Loc, Entity);
464 return Instantiator(T);
Douglas Gregor74296542009-02-27 19:31:52 +0000465}
Douglas Gregored3a3982009-03-03 04:44:36 +0000466
467/// \brief Instantiate the base class specifiers of the given class
468/// template specialization.
469///
470/// Produces a diagnostic and returns true on error, returns false and
471/// attaches the instantiated base classes to the class template
472/// specialization if successful.
473bool
474Sema::InstantiateBaseSpecifiers(
475 ClassTemplateSpecializationDecl *ClassTemplateSpec,
476 ClassTemplateDecl *ClassTemplate) {
477 bool Invalid = false;
478 llvm::SmallVector<CXXBaseSpecifier*, 8> InstantiatedBases;
479 for (ClassTemplateSpecializationDecl::base_class_iterator
480 Base = ClassTemplate->getTemplatedDecl()->bases_begin(),
481 BaseEnd = ClassTemplate->getTemplatedDecl()->bases_end();
482 Base != BaseEnd && !Invalid; ++Base) {
483 if (!Base->getType()->isDependentType()) {
484 // FIXME: Allocate via ASTContext
485 InstantiatedBases.push_back(new CXXBaseSpecifier(*Base));
486 continue;
487 }
488
489 QualType BaseType = InstantiateType(Base->getType(),
490 ClassTemplateSpec->getTemplateArgs(),
491 ClassTemplateSpec->getNumTemplateArgs(),
492 Base->getSourceRange().getBegin(),
493 DeclarationName());
494 if (BaseType.isNull()) {
495 Invalid = true;
496 continue;
497 }
498
499 if (CXXBaseSpecifier *InstantiatedBase
500 = CheckBaseSpecifier(ClassTemplateSpec,
501 Base->getSourceRange(),
502 Base->isVirtual(),
503 Base->getAccessSpecifierAsWritten(),
504 BaseType,
505 /*FIXME: Not totally accurate */
506 Base->getSourceRange().getBegin()))
507 InstantiatedBases.push_back(InstantiatedBase);
508 else
509 Invalid = true;
510 }
511
512 if (AttachBaseSpecifiers(ClassTemplateSpec, &InstantiatedBases[0],
513 InstantiatedBases.size()))
514 Invalid = true;
515
516 return Invalid;
517}
518
519bool
520Sema::InstantiateClassTemplateSpecialization(
521 ClassTemplateSpecializationDecl *ClassTemplateSpec,
522 bool ExplicitInstantiation) {
523 // Perform the actual instantiation on the canonical declaration.
524 ClassTemplateSpec = cast<ClassTemplateSpecializationDecl>(
525 Context.getCanonicalDecl(ClassTemplateSpec));
526
527 // We can only instantiate something that hasn't already been
528 // instantiated or specialized. Fail without any diagnostics: our
529 // caller will provide an error message.
530 if (ClassTemplateSpec->getSpecializationKind() != TSK_Undeclared)
531 return true;
532
533 // FIXME: Push this class template instantiation onto the
534 // instantiation stack, checking for recursion that exceeds a
535 // certain depth.
536
537 // FIXME: Perform class template partial specialization to select
538 // the best template.
539 ClassTemplateDecl *Template = ClassTemplateSpec->getSpecializedTemplate();
540
541 if (!Template->getTemplatedDecl()->getDefinition(Context)) {
542 Diag(ClassTemplateSpec->getLocation(),
543 diag::err_template_implicit_instantiate_undefined)
544 << Context.getTypeDeclType(ClassTemplateSpec);
545 Diag(Template->getTemplatedDecl()->getLocation(),
546 diag::note_template_decl_here);
547 return true;
548 }
549
550 // Note that this is an instantiation.
551 ClassTemplateSpec->setSpecializationKind(
552 ExplicitInstantiation? TSK_ExplicitInstantiation
553 : TSK_ImplicitInstantiation);
554
555
556 bool Invalid = false;
557
Douglas Gregor375733c2009-03-10 00:06:19 +0000558 InstantiatingTemplate Inst(*this, ClassTemplateSpec->getLocation(),
559 ClassTemplateSpec);
560 if (Inst)
561 return true;
562
Douglas Gregored3a3982009-03-03 04:44:36 +0000563 // Enter the scope of this instantiation. We don't use
564 // PushDeclContext because we don't have a scope.
565 DeclContext *PreviousContext = CurContext;
566 CurContext = ClassTemplateSpec;
567
568 // Start the definition of this instantiation.
569 ClassTemplateSpec->startDefinition();
570
571 // FIXME: Create the injected-class-name for the
572 // instantiation. Should this be a typedef or something like it?
573
574 // Instantiate the base class specifiers.
575 if (InstantiateBaseSpecifiers(ClassTemplateSpec, Template))
576 Invalid = true;
577
578 // FIXME: Instantiate all of the members.
579
580 // Add any implicitly-declared members that we might need.
581 AddImplicitlyDeclaredMembersToClass(ClassTemplateSpec);
582
583 // Finish the definition of this instantiation.
584 // FIXME: ActOnFields does more checking, which we'll eventually need.
585 ClassTemplateSpec->completeDefinition(Context);
586
587 // Exit the scope of this instantiation.
588 CurContext = PreviousContext;
589
590 return Invalid;
591}