blob: 4bd7ad4e83f24ca428070c975d9be61dbd805d9e [file] [log] [blame]
Douglas Gregor99ebf652009-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"
Douglas Gregor313a81d2009-03-12 18:36:18 +000018#include "clang/AST/StmtVisitor.h"
Douglas Gregor99ebf652009-02-27 19:31:52 +000019#include "clang/Parse/DeclSpec.h"
Douglas Gregorba498172009-03-13 21:01:28 +000020#include "clang/Lex/Preprocessor.h" // for the identifier table
Douglas Gregor99ebf652009-02-27 19:31:52 +000021#include "clang/Basic/LangOptions.h"
Douglas Gregorcd281c32009-02-28 00:25:32 +000022#include "llvm/Support/Compiler.h"
Douglas Gregor99ebf652009-02-27 19:31:52 +000023
24using namespace clang;
25
Douglas Gregoree1828a2009-03-10 18:03:33 +000026//===----------------------------------------------------------------------===/
27// Template Instantiation Support
28//===----------------------------------------------------------------------===/
29
Douglas Gregor26dce442009-03-10 00:06:19 +000030Sema::InstantiatingTemplate::
31InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
32 ClassTemplateSpecializationDecl *Entity,
33 SourceRange InstantiationRange)
34 : SemaRef(SemaRef) {
Douglas Gregordf667e72009-03-10 20:44:00 +000035
36 Invalid = CheckInstantiationDepth(PointOfInstantiation,
37 InstantiationRange);
38 if (!Invalid) {
Douglas Gregor26dce442009-03-10 00:06:19 +000039 ActiveTemplateInstantiation Inst;
Douglas Gregordf667e72009-03-10 20:44:00 +000040 Inst.Kind = ActiveTemplateInstantiation::TemplateInstantiation;
Douglas Gregor26dce442009-03-10 00:06:19 +000041 Inst.PointOfInstantiation = PointOfInstantiation;
Douglas Gregordf667e72009-03-10 20:44:00 +000042 Inst.Entity = reinterpret_cast<uintptr_t>(Entity);
Douglas Gregor313a81d2009-03-12 18:36:18 +000043 Inst.TemplateArgs = 0;
44 Inst.NumTemplateArgs = 0;
Douglas Gregordf667e72009-03-10 20:44:00 +000045 Inst.InstantiationRange = InstantiationRange;
46 SemaRef.ActiveTemplateInstantiations.push_back(Inst);
47 Invalid = false;
48 }
49}
50
51Sema::InstantiatingTemplate::InstantiatingTemplate(Sema &SemaRef,
52 SourceLocation PointOfInstantiation,
53 TemplateDecl *Template,
54 const TemplateArgument *TemplateArgs,
55 unsigned NumTemplateArgs,
56 SourceRange InstantiationRange)
57 : SemaRef(SemaRef) {
58
59 Invalid = CheckInstantiationDepth(PointOfInstantiation,
60 InstantiationRange);
61 if (!Invalid) {
62 ActiveTemplateInstantiation Inst;
63 Inst.Kind
64 = ActiveTemplateInstantiation::DefaultTemplateArgumentInstantiation;
65 Inst.PointOfInstantiation = PointOfInstantiation;
66 Inst.Entity = reinterpret_cast<uintptr_t>(Template);
67 Inst.TemplateArgs = TemplateArgs;
68 Inst.NumTemplateArgs = NumTemplateArgs;
Douglas Gregor26dce442009-03-10 00:06:19 +000069 Inst.InstantiationRange = InstantiationRange;
70 SemaRef.ActiveTemplateInstantiations.push_back(Inst);
71 Invalid = false;
72 }
73}
74
75Sema::InstantiatingTemplate::~InstantiatingTemplate() {
76 if (!Invalid)
77 SemaRef.ActiveTemplateInstantiations.pop_back();
78}
79
Douglas Gregordf667e72009-03-10 20:44:00 +000080bool Sema::InstantiatingTemplate::CheckInstantiationDepth(
81 SourceLocation PointOfInstantiation,
82 SourceRange InstantiationRange) {
83 if (SemaRef.ActiveTemplateInstantiations.size()
84 <= SemaRef.getLangOptions().InstantiationDepth)
85 return false;
86
87 SemaRef.Diag(PointOfInstantiation,
88 diag::err_template_recursion_depth_exceeded)
89 << SemaRef.getLangOptions().InstantiationDepth
90 << InstantiationRange;
91 SemaRef.Diag(PointOfInstantiation, diag::note_template_recursion_depth)
92 << SemaRef.getLangOptions().InstantiationDepth;
93 return true;
94}
95
Douglas Gregoree1828a2009-03-10 18:03:33 +000096/// \brief Post-diagnostic hook for printing the instantiation stack.
97void Sema::PrintInstantiationStackHook(unsigned, void *Cookie) {
Douglas Gregor27b152f2009-03-10 18:52:44 +000098 Sema &SemaRef = *static_cast<Sema*>(Cookie);
99 SemaRef.PrintInstantiationStack();
100 SemaRef.LastTemplateInstantiationErrorContext
Douglas Gregordf667e72009-03-10 20:44:00 +0000101 = SemaRef.ActiveTemplateInstantiations.back();
Douglas Gregoree1828a2009-03-10 18:03:33 +0000102}
103
104/// \brief Prints the current instantiation stack through a series of
105/// notes.
106void Sema::PrintInstantiationStack() {
107 for (llvm::SmallVector<ActiveTemplateInstantiation, 16>::reverse_iterator
108 Active = ActiveTemplateInstantiations.rbegin(),
109 ActiveEnd = ActiveTemplateInstantiations.rend();
110 Active != ActiveEnd;
111 ++Active) {
Douglas Gregordf667e72009-03-10 20:44:00 +0000112 switch (Active->Kind) {
113 case ActiveTemplateInstantiation::TemplateInstantiation: {
114 ClassTemplateSpecializationDecl *Spec
115 = cast<ClassTemplateSpecializationDecl>((Decl*)Active->Entity);
116 Diags.Report(FullSourceLoc(Active->PointOfInstantiation, SourceMgr),
117 diag::note_template_class_instantiation_here)
118 << Context.getTypeDeclType(Spec)
119 << Active->InstantiationRange;
120 break;
121 }
122
123 case ActiveTemplateInstantiation::DefaultTemplateArgumentInstantiation: {
124 TemplateDecl *Template = cast<TemplateDecl>((Decl *)Active->Entity);
125 std::string TemplateArgsStr
126 = ClassTemplateSpecializationType::PrintTemplateArgumentList(
127 Active->TemplateArgs,
128 Active->NumTemplateArgs);
129 Diags.Report(FullSourceLoc(Active->PointOfInstantiation, SourceMgr),
130 diag::note_default_arg_instantiation_here)
131 << (Template->getNameAsString() + TemplateArgsStr)
132 << Active->InstantiationRange;
133 break;
134 }
135 }
Douglas Gregoree1828a2009-03-10 18:03:33 +0000136 }
137}
138
Douglas Gregor99ebf652009-02-27 19:31:52 +0000139//===----------------------------------------------------------------------===/
140// Template Instantiation for Types
141//===----------------------------------------------------------------------===/
Douglas Gregorcd281c32009-02-28 00:25:32 +0000142namespace {
143 class VISIBILITY_HIDDEN TemplateTypeInstantiator {
144 Sema &SemaRef;
145 const TemplateArgument *TemplateArgs;
146 unsigned NumTemplateArgs;
147 SourceLocation Loc;
148 DeclarationName Entity;
Douglas Gregor99ebf652009-02-27 19:31:52 +0000149
Douglas Gregorcd281c32009-02-28 00:25:32 +0000150 public:
151 TemplateTypeInstantiator(Sema &SemaRef,
152 const TemplateArgument *TemplateArgs,
153 unsigned NumTemplateArgs,
154 SourceLocation Loc,
155 DeclarationName Entity)
156 : SemaRef(SemaRef), TemplateArgs(TemplateArgs),
157 NumTemplateArgs(NumTemplateArgs), Loc(Loc), Entity(Entity) { }
158
159 QualType operator()(QualType T) const { return Instantiate(T); }
160
161 QualType Instantiate(QualType T) const;
162
163 // Declare instantiate functions for each type.
164#define TYPE(Class, Base) \
165 QualType Instantiate##Class##Type(const Class##Type *T, \
166 unsigned Quals) const;
167#define ABSTRACT_TYPE(Class, Base)
168#include "clang/AST/TypeNodes.def"
169 };
170}
171
172QualType
173TemplateTypeInstantiator::InstantiateExtQualType(const ExtQualType *T,
174 unsigned Quals) const {
Douglas Gregor99ebf652009-02-27 19:31:52 +0000175 // FIXME: Implement this
176 assert(false && "Cannot instantiate ExtQualType yet");
177 return QualType();
178}
179
Douglas Gregorcd281c32009-02-28 00:25:32 +0000180QualType
181TemplateTypeInstantiator::InstantiateBuiltinType(const BuiltinType *T,
182 unsigned Quals) const {
Douglas Gregor724651c2009-02-28 01:04:19 +0000183 assert(false && "Builtin types are not dependent and cannot be instantiated");
Douglas Gregorcd281c32009-02-28 00:25:32 +0000184 return QualType(T, Quals);
Douglas Gregor99ebf652009-02-27 19:31:52 +0000185}
186
Douglas Gregorcd281c32009-02-28 00:25:32 +0000187QualType
188TemplateTypeInstantiator::
189InstantiateFixedWidthIntType(const FixedWidthIntType *T, unsigned Quals) const {
Douglas Gregor99ebf652009-02-27 19:31:52 +0000190 // FIXME: Implement this
191 assert(false && "Cannot instantiate FixedWidthIntType yet");
192 return QualType();
193}
194
Douglas Gregorcd281c32009-02-28 00:25:32 +0000195QualType
196TemplateTypeInstantiator::InstantiateComplexType(const ComplexType *T,
197 unsigned Quals) const {
Douglas Gregor99ebf652009-02-27 19:31:52 +0000198 // FIXME: Implement this
199 assert(false && "Cannot instantiate ComplexType yet");
200 return QualType();
201}
202
Douglas Gregorcd281c32009-02-28 00:25:32 +0000203QualType
204TemplateTypeInstantiator::InstantiatePointerType(const PointerType *T,
205 unsigned Quals) const {
206 QualType PointeeType = Instantiate(T->getPointeeType());
207 if (PointeeType.isNull())
208 return QualType();
209
210 return SemaRef.BuildPointerType(PointeeType, Quals, Loc, Entity);
Douglas Gregor99ebf652009-02-27 19:31:52 +0000211}
212
Douglas Gregorcd281c32009-02-28 00:25:32 +0000213QualType
214TemplateTypeInstantiator::InstantiateBlockPointerType(const BlockPointerType *T,
215 unsigned Quals) const {
Douglas Gregor99ebf652009-02-27 19:31:52 +0000216 // FIXME: Implement this
217 assert(false && "Cannot instantiate BlockPointerType yet");
218 return QualType();
219}
220
Douglas Gregorcd281c32009-02-28 00:25:32 +0000221QualType
222TemplateTypeInstantiator::InstantiateReferenceType(const ReferenceType *T,
223 unsigned Quals) const {
224 QualType ReferentType = Instantiate(T->getPointeeType());
225 if (ReferentType.isNull())
226 return QualType();
227
228 return SemaRef.BuildReferenceType(ReferentType, Quals, Loc, Entity);
Douglas Gregor99ebf652009-02-27 19:31:52 +0000229}
230
Douglas Gregorcd281c32009-02-28 00:25:32 +0000231QualType
232TemplateTypeInstantiator::
233InstantiateMemberPointerType(const MemberPointerType *T,
234 unsigned Quals) const {
Douglas Gregor99ebf652009-02-27 19:31:52 +0000235 // FIXME: Implement this
236 assert(false && "Cannot instantiate MemberPointerType yet");
237 return QualType();
238}
239
Douglas Gregorcd281c32009-02-28 00:25:32 +0000240QualType
241TemplateTypeInstantiator::
242InstantiateConstantArrayType(const ConstantArrayType *T,
243 unsigned Quals) const {
244 QualType ElementType = Instantiate(T->getElementType());
245 if (ElementType.isNull())
246 return ElementType;
247
248 // Build a temporary integer literal to specify the size for
249 // BuildArrayType. Since we have already checked the size as part of
250 // creating the dependent array type in the first place, we know
251 // there aren't any errors.
Douglas Gregor8d217212009-03-09 20:07:22 +0000252 // FIXME: Is IntTy big enough? Maybe not, but LongLongTy causes
253 // problems that I have yet to investigate.
254 IntegerLiteral ArraySize(T->getSize(), SemaRef.Context.IntTy, Loc);
Douglas Gregorcd281c32009-02-28 00:25:32 +0000255 return SemaRef.BuildArrayType(ElementType, T->getSizeModifier(),
256 &ArraySize, T->getIndexTypeQualifier(),
257 Loc, Entity);
Douglas Gregor99ebf652009-02-27 19:31:52 +0000258}
259
Douglas Gregorcd281c32009-02-28 00:25:32 +0000260QualType
261TemplateTypeInstantiator::
262InstantiateIncompleteArrayType(const IncompleteArrayType *T,
263 unsigned Quals) const {
264 QualType ElementType = Instantiate(T->getElementType());
265 if (ElementType.isNull())
266 return ElementType;
267
268 return SemaRef.BuildArrayType(ElementType, T->getSizeModifier(),
269 0, T->getIndexTypeQualifier(),
270 Loc, Entity);
Douglas Gregor99ebf652009-02-27 19:31:52 +0000271}
272
Douglas Gregorcd281c32009-02-28 00:25:32 +0000273QualType
274TemplateTypeInstantiator::
275InstantiateVariableArrayType(const VariableArrayType *T,
276 unsigned Quals) const {
Douglas Gregor99ebf652009-02-27 19:31:52 +0000277 // FIXME: Implement this
278 assert(false && "Cannot instantiate VariableArrayType yet");
279 return QualType();
280}
281
Douglas Gregorcd281c32009-02-28 00:25:32 +0000282QualType
283TemplateTypeInstantiator::
284InstantiateDependentSizedArrayType(const DependentSizedArrayType *T,
285 unsigned Quals) const {
Douglas Gregor99ebf652009-02-27 19:31:52 +0000286 // FIXME: Implement this
287 assert(false && "Cannot instantiate DependentSizedArrayType yet");
288 return QualType();
289}
290
Douglas Gregorcd281c32009-02-28 00:25:32 +0000291QualType
292TemplateTypeInstantiator::InstantiateVectorType(const VectorType *T,
293 unsigned Quals) const {
Douglas Gregor99ebf652009-02-27 19:31:52 +0000294 // FIXME: Implement this
295 assert(false && "Cannot instantiate VectorType yet");
296 return QualType();
297}
298
Douglas Gregorcd281c32009-02-28 00:25:32 +0000299QualType
300TemplateTypeInstantiator::InstantiateExtVectorType(const ExtVectorType *T,
301 unsigned Quals) const {
Douglas Gregor99ebf652009-02-27 19:31:52 +0000302 // FIXME: Implement this
303 assert(false && "Cannot instantiate ExtVectorType yet");
304 return QualType();
305}
306
Douglas Gregorcd281c32009-02-28 00:25:32 +0000307QualType
308TemplateTypeInstantiator::
309InstantiateFunctionProtoType(const FunctionProtoType *T,
310 unsigned Quals) const {
Douglas Gregor724651c2009-02-28 01:04:19 +0000311 QualType ResultType = Instantiate(T->getResultType());
312 if (ResultType.isNull())
313 return ResultType;
314
315 llvm::SmallVector<QualType, 16> ParamTypes;
316 for (FunctionProtoType::arg_type_iterator Param = T->arg_type_begin(),
317 ParamEnd = T->arg_type_end();
318 Param != ParamEnd; ++Param) {
319 QualType P = Instantiate(*Param);
320 if (P.isNull())
321 return P;
322
323 ParamTypes.push_back(P);
324 }
325
326 return SemaRef.BuildFunctionType(ResultType, &ParamTypes[0],
327 ParamTypes.size(),
328 T->isVariadic(), T->getTypeQuals(),
329 Loc, Entity);
Douglas Gregor99ebf652009-02-27 19:31:52 +0000330}
331
Douglas Gregorcd281c32009-02-28 00:25:32 +0000332QualType
333TemplateTypeInstantiator::
334InstantiateFunctionNoProtoType(const FunctionNoProtoType *T,
335 unsigned Quals) const {
Douglas Gregor724651c2009-02-28 01:04:19 +0000336 assert(false && "Functions without prototypes cannot be dependent.");
Douglas Gregor99ebf652009-02-27 19:31:52 +0000337 return QualType();
338}
339
Douglas Gregorcd281c32009-02-28 00:25:32 +0000340QualType
341TemplateTypeInstantiator::InstantiateTypedefType(const TypedefType *T,
342 unsigned Quals) const {
Douglas Gregor99ebf652009-02-27 19:31:52 +0000343 // FIXME: Implement this
344 assert(false && "Cannot instantiate TypedefType yet");
345 return QualType();
346}
347
Douglas Gregorcd281c32009-02-28 00:25:32 +0000348QualType
349TemplateTypeInstantiator::InstantiateTypeOfExprType(const TypeOfExprType *T,
350 unsigned Quals) const {
Douglas Gregor99ebf652009-02-27 19:31:52 +0000351 // FIXME: Implement this
352 assert(false && "Cannot instantiate TypeOfExprType yet");
353 return QualType();
354}
355
Douglas Gregorcd281c32009-02-28 00:25:32 +0000356QualType
357TemplateTypeInstantiator::InstantiateTypeOfType(const TypeOfType *T,
358 unsigned Quals) const {
Douglas Gregor99ebf652009-02-27 19:31:52 +0000359 // FIXME: Implement this
360 assert(false && "Cannot instantiate TypeOfType yet");
361 return QualType();
362}
363
Douglas Gregorcd281c32009-02-28 00:25:32 +0000364QualType
365TemplateTypeInstantiator::InstantiateRecordType(const RecordType *T,
366 unsigned Quals) const {
Douglas Gregor99ebf652009-02-27 19:31:52 +0000367 // FIXME: Implement this
368 assert(false && "Cannot instantiate RecordType yet");
369 return QualType();
370}
371
Douglas Gregorcd281c32009-02-28 00:25:32 +0000372QualType
Douglas Gregorcd281c32009-02-28 00:25:32 +0000373TemplateTypeInstantiator::InstantiateEnumType(const EnumType *T,
374 unsigned Quals) const {
Douglas Gregor99ebf652009-02-27 19:31:52 +0000375 // FIXME: Implement this
376 assert(false && "Cannot instantiate EnumType yet");
377 return QualType();
378}
379
Douglas Gregorcd281c32009-02-28 00:25:32 +0000380QualType
381TemplateTypeInstantiator::
382InstantiateTemplateTypeParmType(const TemplateTypeParmType *T,
383 unsigned Quals) const {
Douglas Gregor99ebf652009-02-27 19:31:52 +0000384 if (T->getDepth() == 0) {
385 // Replace the template type parameter with its corresponding
386 // template argument.
387 assert(T->getIndex() < NumTemplateArgs && "Wrong # of template args");
388 assert(TemplateArgs[T->getIndex()].getKind() == TemplateArgument::Type &&
389 "Template argument kind mismatch");
390 QualType Result = TemplateArgs[T->getIndex()].getAsType();
Douglas Gregorcd281c32009-02-28 00:25:32 +0000391 if (Result.isNull() || !Quals)
Douglas Gregor99ebf652009-02-27 19:31:52 +0000392 return Result;
393
394 // C++ [dcl.ref]p1:
395 // [...] Cv-qualified references are ill-formed except when
396 // the cv-qualifiers are introduced through the use of a
397 // typedef (7.1.3) or of a template type argument (14.3), in
398 // which case the cv-qualifiers are ignored.
Douglas Gregorcd281c32009-02-28 00:25:32 +0000399 if (Quals && Result->isReferenceType())
400 Quals = 0;
Douglas Gregor99ebf652009-02-27 19:31:52 +0000401
Douglas Gregorcd281c32009-02-28 00:25:32 +0000402 return QualType(Result.getTypePtr(), Quals | Result.getCVRQualifiers());
Douglas Gregor99ebf652009-02-27 19:31:52 +0000403 }
404
405 // The template type parameter comes from an inner template (e.g.,
406 // the template parameter list of a member template inside the
407 // template we are instantiating). Create a new template type
408 // parameter with the template "level" reduced by one.
409 return SemaRef.Context.getTemplateTypeParmType(T->getDepth() - 1,
410 T->getIndex(),
Douglas Gregorcd281c32009-02-28 00:25:32 +0000411 T->getName())
412 .getQualifiedType(Quals);
Douglas Gregor99ebf652009-02-27 19:31:52 +0000413}
414
Douglas Gregorcd281c32009-02-28 00:25:32 +0000415QualType
416TemplateTypeInstantiator::
417InstantiateClassTemplateSpecializationType(
418 const ClassTemplateSpecializationType *T,
419 unsigned Quals) const {
Douglas Gregor40808ce2009-03-09 23:48:35 +0000420 llvm::SmallVector<TemplateArgument, 16> InstantiatedTemplateArgs;
421 InstantiatedTemplateArgs.reserve(T->getNumArgs());
422 for (ClassTemplateSpecializationType::iterator Arg = T->begin(),
423 ArgEnd = T->end();
424 Arg != ArgEnd; ++Arg) {
425 switch (Arg->getKind()) {
426 case TemplateArgument::Type: {
427 QualType T = SemaRef.InstantiateType(Arg->getAsType(),
428 TemplateArgs, NumTemplateArgs,
429 Arg->getLocation(),
430 DeclarationName());
431 if (T.isNull())
432 return QualType();
433
434 InstantiatedTemplateArgs.push_back(
435 TemplateArgument(Arg->getLocation(), T));
436 break;
437 }
438
439 case TemplateArgument::Declaration:
440 case TemplateArgument::Integral:
441 InstantiatedTemplateArgs.push_back(*Arg);
442 break;
443
444 case TemplateArgument::Expression:
Douglas Gregorba498172009-03-13 21:01:28 +0000445 Sema::OwningExprResult E
446 = SemaRef.InstantiateExpr(Arg->getAsExpr(), TemplateArgs,
447 NumTemplateArgs);
448 if (E.isInvalid())
449 return QualType();
450 InstantiatedTemplateArgs.push_back((Expr *)E.release());
Douglas Gregor40808ce2009-03-09 23:48:35 +0000451 break;
452 }
453 }
454
455 // FIXME: We're missing the locations of the template name, '<', and
456 // '>'.
457 return SemaRef.CheckClassTemplateId(cast<ClassTemplateDecl>(T->getTemplate()),
458 Loc,
459 SourceLocation(),
460 &InstantiatedTemplateArgs[0],
461 InstantiatedTemplateArgs.size(),
462 SourceLocation());
Douglas Gregor99ebf652009-02-27 19:31:52 +0000463}
464
Douglas Gregorcd281c32009-02-28 00:25:32 +0000465QualType
466TemplateTypeInstantiator::
467InstantiateObjCInterfaceType(const ObjCInterfaceType *T,
468 unsigned Quals) const {
469 assert(false && "Objective-C types cannot be dependent");
Douglas Gregor99ebf652009-02-27 19:31:52 +0000470 return QualType();
471}
472
Douglas Gregorcd281c32009-02-28 00:25:32 +0000473QualType
474TemplateTypeInstantiator::
475InstantiateObjCQualifiedInterfaceType(const ObjCQualifiedInterfaceType *T,
476 unsigned Quals) const {
477 assert(false && "Objective-C types cannot be dependent");
Douglas Gregor99ebf652009-02-27 19:31:52 +0000478 return QualType();
479}
480
Douglas Gregorcd281c32009-02-28 00:25:32 +0000481QualType
482TemplateTypeInstantiator::
483InstantiateObjCQualifiedIdType(const ObjCQualifiedIdType *T,
484 unsigned Quals) const {
485 assert(false && "Objective-C types cannot be dependent");
Douglas Gregor99ebf652009-02-27 19:31:52 +0000486 return QualType();
487}
488
Douglas Gregorcd281c32009-02-28 00:25:32 +0000489QualType
490TemplateTypeInstantiator::
491InstantiateObjCQualifiedClassType(const ObjCQualifiedClassType *T,
492 unsigned Quals) const {
493 assert(false && "Objective-C types cannot be dependent");
Douglas Gregor99ebf652009-02-27 19:31:52 +0000494 return QualType();
495}
496
Douglas Gregorcd281c32009-02-28 00:25:32 +0000497/// \brief The actual implementation of Sema::InstantiateType().
498QualType TemplateTypeInstantiator::Instantiate(QualType T) const {
499 // If T is not a dependent type, there is nothing to do.
500 if (!T->isDependentType())
501 return T;
502
503 switch (T->getTypeClass()) {
504#define TYPE(Class, Base) \
505 case Type::Class: \
506 return Instantiate##Class##Type(cast<Class##Type>(T.getTypePtr()), \
507 T.getCVRQualifiers());
508#define ABSTRACT_TYPE(Class, Base)
509#include "clang/AST/TypeNodes.def"
510 }
511
512 assert(false && "Not all types have been decoded for instantiation");
513 return QualType();
514}
Douglas Gregor99ebf652009-02-27 19:31:52 +0000515
516/// \brief Instantiate the type T with a given set of template arguments.
517///
518/// This routine substitutes the given template arguments into the
519/// type T and produces the instantiated type.
520///
521/// \param T the type into which the template arguments will be
522/// substituted. If this type is not dependent, it will be returned
523/// immediately.
524///
525/// \param TemplateArgs the template arguments that will be
526/// substituted for the top-level template parameters within T.
527///
528/// \param NumTemplateArgs the number of template arguments provided
529/// by TemplateArgs.
530///
531/// \param Loc the location in the source code where this substitution
532/// is being performed. It will typically be the location of the
533/// declarator (if we're instantiating the type of some declaration)
534/// or the location of the type in the source code (if, e.g., we're
535/// instantiating the type of a cast expression).
536///
537/// \param Entity the name of the entity associated with a declaration
538/// being instantiated (if any). May be empty to indicate that there
539/// is no such entity (if, e.g., this is a type that occurs as part of
540/// a cast expression) or that the entity has no name (e.g., an
541/// unnamed function parameter).
542///
543/// \returns If the instantiation succeeds, the instantiated
544/// type. Otherwise, produces diagnostics and returns a NULL type.
545QualType Sema::InstantiateType(QualType T,
546 const TemplateArgument *TemplateArgs,
547 unsigned NumTemplateArgs,
548 SourceLocation Loc, DeclarationName Entity) {
Douglas Gregordf667e72009-03-10 20:44:00 +0000549 assert(!ActiveTemplateInstantiations.empty() &&
550 "Cannot perform an instantiation without some context on the "
551 "instantiation stack");
552
Douglas Gregor99ebf652009-02-27 19:31:52 +0000553 // If T is not a dependent type, there is nothing to do.
554 if (!T->isDependentType())
555 return T;
556
Douglas Gregorcd281c32009-02-28 00:25:32 +0000557 TemplateTypeInstantiator Instantiator(*this, TemplateArgs, NumTemplateArgs,
558 Loc, Entity);
559 return Instantiator(T);
Douglas Gregor99ebf652009-02-27 19:31:52 +0000560}
Douglas Gregor2943aed2009-03-03 04:44:36 +0000561
Douglas Gregora0e500d2009-03-12 16:53:44 +0000562//===----------------------------------------------------------------------===/
563// Template Instantiation for Expressions
564//===----------------------------------------------------------------------===/
Douglas Gregor313a81d2009-03-12 18:36:18 +0000565namespace {
566 class VISIBILITY_HIDDEN TemplateExprInstantiator
567 : public StmtVisitor<TemplateExprInstantiator, Sema::OwningExprResult> {
568 Sema &SemaRef;
569 const TemplateArgument *TemplateArgs;
570 unsigned NumTemplateArgs;
571
572 public:
Douglas Gregorba498172009-03-13 21:01:28 +0000573 typedef Sema::OwningExprResult OwningExprResult;
574
Douglas Gregor313a81d2009-03-12 18:36:18 +0000575 TemplateExprInstantiator(Sema &SemaRef,
576 const TemplateArgument *TemplateArgs,
577 unsigned NumTemplateArgs)
578 : SemaRef(SemaRef), TemplateArgs(TemplateArgs),
579 NumTemplateArgs(NumTemplateArgs) { }
580
581 // FIXME: Once we get closer to completion, replace these
582 // manually-written declarations with automatically-generated ones
583 // from clang/AST/StmtNodes.def.
Douglas Gregorba498172009-03-13 21:01:28 +0000584 OwningExprResult VisitIntegerLiteral(IntegerLiteral *E);
585 OwningExprResult VisitDeclRefExpr(DeclRefExpr *E);
586 OwningExprResult VisitParenExpr(ParenExpr *E);
587 OwningExprResult VisitBinaryOperator(BinaryOperator *E);
588 OwningExprResult VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E);
589 OwningExprResult VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *E);
590 OwningExprResult VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E);
Douglas Gregor313a81d2009-03-12 18:36:18 +0000591
592 // Base case. I'm supposed to ignore this.
Douglas Gregordf032512009-03-12 22:46:12 +0000593 Sema::OwningExprResult VisitStmt(Stmt *) {
594 assert(false && "Cannot instantiate this kind of expression");
595 return SemaRef.ExprError();
596 }
Douglas Gregor313a81d2009-03-12 18:36:18 +0000597 };
598}
599
600Sema::OwningExprResult
601TemplateExprInstantiator::VisitIntegerLiteral(IntegerLiteral *E) {
602 // FIXME: Can't we just re-use the expression node?
603 return SemaRef.Owned(new (SemaRef.Context) IntegerLiteral(E->getValue(),
604 E->getType(),
605 E->getLocation()));
606}
607
608Sema::OwningExprResult
609TemplateExprInstantiator::VisitDeclRefExpr(DeclRefExpr *E) {
610 Decl *D = E->getDecl();
611 if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(D)) {
612 assert(NTTP->getDepth() == 0 && "No nested templates yet");
Douglas Gregorc971f862009-03-12 22:20:26 +0000613 const TemplateArgument &Arg = TemplateArgs[NTTP->getPosition()];
Douglas Gregor313a81d2009-03-12 18:36:18 +0000614 return SemaRef.Owned(new (SemaRef.Context) IntegerLiteral(
Douglas Gregorc971f862009-03-12 22:20:26 +0000615 *Arg.getAsIntegral(),
616 Arg.getIntegralType(),
617 E->getSourceRange().getBegin()));
Douglas Gregor313a81d2009-03-12 18:36:18 +0000618 } else
619 assert(false && "Can't handle arbitrary declaration references");
620
621 return SemaRef.ExprError();
622}
623
624Sema::OwningExprResult
625TemplateExprInstantiator::VisitParenExpr(ParenExpr *E) {
626 Sema::OwningExprResult SubExpr
627 = SemaRef.InstantiateExpr(E->getSubExpr(), TemplateArgs, NumTemplateArgs);
628 if (SubExpr.isInvalid())
629 return SemaRef.ExprError();
630
631 return SemaRef.Owned(new (SemaRef.Context) ParenExpr(
632 E->getLParen(), E->getRParen(),
633 (Expr *)SubExpr.release()));
634}
635
Douglas Gregora0e500d2009-03-12 16:53:44 +0000636Sema::OwningExprResult
Douglas Gregordf032512009-03-12 22:46:12 +0000637TemplateExprInstantiator::VisitBinaryOperator(BinaryOperator *E) {
638 Sema::OwningExprResult LHS = Visit(E->getLHS());
639 if (LHS.isInvalid())
640 return SemaRef.ExprError();
641
642 Sema::OwningExprResult RHS = Visit(E->getRHS());
643 if (RHS.isInvalid())
644 return SemaRef.ExprError();
645
646 Sema::OwningExprResult Result
647 = SemaRef.CreateBuiltinBinOp(E->getOperatorLoc(),
648 E->getOpcode(),
649 (Expr *)LHS.get(),
650 (Expr *)RHS.get());
651 if (Result.isInvalid())
652 return SemaRef.ExprError();
653
654 LHS.release();
655 RHS.release();
656 return move(Result);
657}
658
659Sema::OwningExprResult
Douglas Gregor3fd95ce2009-03-13 00:33:25 +0000660TemplateExprInstantiator::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor063daf62009-03-13 18:40:31 +0000661 // FIXME: Only handles binary operators at the moment.
662
Douglas Gregor3fd95ce2009-03-13 00:33:25 +0000663 Sema::OwningExprResult LHS = Visit(E->getArg(0));
664 if (LHS.isInvalid())
665 return SemaRef.ExprError();
666
667 Sema::OwningExprResult RHS = Visit(E->getArg(1));
668 if (RHS.isInvalid())
669 return SemaRef.ExprError();
670
Douglas Gregor063daf62009-03-13 18:40:31 +0000671 Expr *lhs = (Expr *)LHS.get(), *rhs = (Expr *)RHS.get();
672 Expr *Args[2] = { lhs, rhs };
673
674 if (!E->isTypeDependent()) {
675 // Since our original expression was not type-dependent, we do not
676 // perform lookup again at instantiation time (C++ [temp.dep]p1).
677 // Instead, we just build the new overloaded operator call
678 // expression.
679 LHS.release();
680 RHS.release();
681 return SemaRef.Owned(new (SemaRef.Context) CXXOperatorCallExpr(
682 SemaRef.Context,
683 E->getOperator(),
684 E->getCallee(),
685 Args, 2, E->getType(),
686 E->getOperatorLoc()));
687 }
688
689 BinaryOperator::Opcode Opc =
690 BinaryOperator::getOverloadedOpcode(E->getOperator());
691 Sema::OwningExprResult Result(SemaRef);
692 if (!lhs->getType()->isOverloadableType() &&
693 !rhs->getType()->isOverloadableType()) {
694 // Neither LHS nor RHS is an overloadable type, so try create a
695 // built-in binary operation.
696 Result = SemaRef.CreateBuiltinBinOp(E->getOperatorLoc(), Opc,
697 lhs, rhs);
698 } else {
699 // Compute the set of functions that were found at template
700 // definition time.
701 Sema::FunctionSet Functions;
702 DeclRefExpr *DRE = cast<DeclRefExpr>(E->getCallee());
703 OverloadedFunctionDecl *Overloads
704 = cast<OverloadedFunctionDecl>(DRE->getDecl());
Douglas Gregorba498172009-03-13 21:01:28 +0000705
706 // FIXME: Do we have to check
707 // IsAcceptableNonMemberOperatorCandidate for each of these?
Douglas Gregor063daf62009-03-13 18:40:31 +0000708 for (OverloadedFunctionDecl::function_iterator
709 F = Overloads->function_begin(),
710 FEnd = Overloads->function_end();
711 F != FEnd; ++F)
712 Functions.insert(*F);
713
714 // Add any functions found via argument-dependent lookup.
715 DeclarationName OpName
716 = SemaRef.Context.DeclarationNames.getCXXOperatorName(E->getOperator());
717 SemaRef.ArgumentDependentLookup(OpName, Args, 2, Functions);
718
719 // Create the overloaded operator.
720 Result = SemaRef.CreateOverloadedBinOp(E->getOperatorLoc(), Opc,
721 Functions, lhs, rhs);
722 }
723
Douglas Gregor3fd95ce2009-03-13 00:33:25 +0000724 if (Result.isInvalid())
725 return SemaRef.ExprError();
726
727 LHS.release();
728 RHS.release();
729 return move(Result);
730}
731
732Sema::OwningExprResult
Douglas Gregorba498172009-03-13 21:01:28 +0000733TemplateExprInstantiator::VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
734 bool isSizeOf = E->isSizeOf();
735
736 if (E->isArgumentType()) {
737 QualType T = E->getArgumentType();
738 if (T->isDependentType()) {
739 T = SemaRef.InstantiateType(T, TemplateArgs, NumTemplateArgs,
740 /*FIXME*/E->getOperatorLoc(),
741 &SemaRef.PP.getIdentifierTable().get("sizeof"));
742 if (T.isNull())
743 return SemaRef.ExprError();
744 }
745
746 return SemaRef.CreateSizeOfAlignOfExpr(T, E->getOperatorLoc(), isSizeOf,
747 E->getSourceRange());
748 }
749
750 Sema::OwningExprResult Arg = Visit(E->getArgumentExpr());
751 if (Arg.isInvalid())
752 return SemaRef.ExprError();
753
754 Sema::OwningExprResult Result
755 = SemaRef.CreateSizeOfAlignOfExpr((Expr *)Arg.get(), E->getOperatorLoc(),
756 isSizeOf, E->getSourceRange());
757 if (Result.isInvalid())
758 return SemaRef.ExprError();
759
760 Arg.release();
761 return move(Result);
762}
763
764Sema::OwningExprResult
765TemplateExprInstantiator::VisitCXXTemporaryObjectExpr(
766 CXXTemporaryObjectExpr *E) {
767 QualType T = E->getType();
768 if (T->isDependentType()) {
769 T = SemaRef.InstantiateType(T, TemplateArgs, NumTemplateArgs,
770 E->getTypeBeginLoc(), DeclarationName());
771 if (T.isNull())
772 return SemaRef.ExprError();
773 }
774
775 llvm::SmallVector<Expr *, 16> Args;
776 Args.reserve(E->getNumArgs());
777 bool Invalid = false;
778 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
779 ArgEnd = E->arg_end();
780 Arg != ArgEnd; ++Arg) {
781 OwningExprResult InstantiatedArg = Visit(*Arg);
782 if (InstantiatedArg.isInvalid()) {
783 Invalid = true;
784 break;
785 }
786
787 Args.push_back((Expr *)InstantiatedArg.release());
788 }
789
790 if (!Invalid) {
791 SourceLocation CommaLoc;
792 // FIXME: HACK!
793 if (Args.size() > 1)
794 CommaLoc
795 = SemaRef.PP.getLocForEndOfToken(Args[0]->getSourceRange().getEnd());
796 Sema::ExprResult Result
797 = SemaRef.ActOnCXXTypeConstructExpr(SourceRange(E->getTypeBeginLoc()
798 /*, FIXME*/),
799 T.getAsOpaquePtr(),
800 /*FIXME*/E->getTypeBeginLoc(),
801 (void**)&Args[0], Args.size(),
802 /*HACK*/&CommaLoc,
803 E->getSourceRange().getEnd());
804 if (!Result.isInvalid())
805 return SemaRef.Owned(Result);
806 }
807
808 // Clean up the instantiated arguments.
809 // FIXME: Would rather do this with RAII.
810 for (unsigned Idx = 0; Idx < Args.size(); ++Idx)
811 SemaRef.DeleteExpr(Args[Idx]);
812
813 return SemaRef.ExprError();
814}
815
816Sema::OwningExprResult
Douglas Gregora0e500d2009-03-12 16:53:44 +0000817Sema::InstantiateExpr(Expr *E, const TemplateArgument *TemplateArgs,
818 unsigned NumTemplateArgs) {
Douglas Gregor313a81d2009-03-12 18:36:18 +0000819 TemplateExprInstantiator Instantiator(*this, TemplateArgs, NumTemplateArgs);
820 return Instantiator.Visit(E);
Douglas Gregora0e500d2009-03-12 16:53:44 +0000821}
822
Douglas Gregor2943aed2009-03-03 04:44:36 +0000823/// \brief Instantiate the base class specifiers of the given class
824/// template specialization.
825///
826/// Produces a diagnostic and returns true on error, returns false and
827/// attaches the instantiated base classes to the class template
828/// specialization if successful.
829bool
830Sema::InstantiateBaseSpecifiers(
831 ClassTemplateSpecializationDecl *ClassTemplateSpec,
832 ClassTemplateDecl *ClassTemplate) {
833 bool Invalid = false;
834 llvm::SmallVector<CXXBaseSpecifier*, 8> InstantiatedBases;
835 for (ClassTemplateSpecializationDecl::base_class_iterator
836 Base = ClassTemplate->getTemplatedDecl()->bases_begin(),
837 BaseEnd = ClassTemplate->getTemplatedDecl()->bases_end();
Douglas Gregor27b152f2009-03-10 18:52:44 +0000838 Base != BaseEnd; ++Base) {
Douglas Gregor2943aed2009-03-03 04:44:36 +0000839 if (!Base->getType()->isDependentType()) {
840 // FIXME: Allocate via ASTContext
841 InstantiatedBases.push_back(new CXXBaseSpecifier(*Base));
842 continue;
843 }
844
845 QualType BaseType = InstantiateType(Base->getType(),
846 ClassTemplateSpec->getTemplateArgs(),
847 ClassTemplateSpec->getNumTemplateArgs(),
848 Base->getSourceRange().getBegin(),
849 DeclarationName());
850 if (BaseType.isNull()) {
851 Invalid = true;
852 continue;
853 }
854
855 if (CXXBaseSpecifier *InstantiatedBase
856 = CheckBaseSpecifier(ClassTemplateSpec,
857 Base->getSourceRange(),
858 Base->isVirtual(),
859 Base->getAccessSpecifierAsWritten(),
860 BaseType,
861 /*FIXME: Not totally accurate */
862 Base->getSourceRange().getBegin()))
863 InstantiatedBases.push_back(InstantiatedBase);
864 else
865 Invalid = true;
866 }
867
Douglas Gregor27b152f2009-03-10 18:52:44 +0000868 if (!Invalid &&
869 AttachBaseSpecifiers(ClassTemplateSpec, &InstantiatedBases[0],
Douglas Gregor2943aed2009-03-03 04:44:36 +0000870 InstantiatedBases.size()))
871 Invalid = true;
872
873 return Invalid;
874}
875
876bool
877Sema::InstantiateClassTemplateSpecialization(
878 ClassTemplateSpecializationDecl *ClassTemplateSpec,
879 bool ExplicitInstantiation) {
880 // Perform the actual instantiation on the canonical declaration.
881 ClassTemplateSpec = cast<ClassTemplateSpecializationDecl>(
882 Context.getCanonicalDecl(ClassTemplateSpec));
883
884 // We can only instantiate something that hasn't already been
885 // instantiated or specialized. Fail without any diagnostics: our
886 // caller will provide an error message.
887 if (ClassTemplateSpec->getSpecializationKind() != TSK_Undeclared)
888 return true;
889
890 // FIXME: Push this class template instantiation onto the
891 // instantiation stack, checking for recursion that exceeds a
892 // certain depth.
893
894 // FIXME: Perform class template partial specialization to select
895 // the best template.
896 ClassTemplateDecl *Template = ClassTemplateSpec->getSpecializedTemplate();
897
898 if (!Template->getTemplatedDecl()->getDefinition(Context)) {
899 Diag(ClassTemplateSpec->getLocation(),
900 diag::err_template_implicit_instantiate_undefined)
901 << Context.getTypeDeclType(ClassTemplateSpec);
902 Diag(Template->getTemplatedDecl()->getLocation(),
903 diag::note_template_decl_here);
904 return true;
905 }
906
907 // Note that this is an instantiation.
908 ClassTemplateSpec->setSpecializationKind(
909 ExplicitInstantiation? TSK_ExplicitInstantiation
910 : TSK_ImplicitInstantiation);
911
912
913 bool Invalid = false;
914
Douglas Gregor26dce442009-03-10 00:06:19 +0000915 InstantiatingTemplate Inst(*this, ClassTemplateSpec->getLocation(),
916 ClassTemplateSpec);
917 if (Inst)
918 return true;
919
Douglas Gregor2943aed2009-03-03 04:44:36 +0000920 // Enter the scope of this instantiation. We don't use
921 // PushDeclContext because we don't have a scope.
922 DeclContext *PreviousContext = CurContext;
923 CurContext = ClassTemplateSpec;
924
925 // Start the definition of this instantiation.
926 ClassTemplateSpec->startDefinition();
927
Douglas Gregor2943aed2009-03-03 04:44:36 +0000928
929 // Instantiate the base class specifiers.
930 if (InstantiateBaseSpecifiers(ClassTemplateSpec, Template))
931 Invalid = true;
932
Douglas Gregor4fdf1fa2009-03-11 16:48:53 +0000933 // FIXME: Create the injected-class-name for the
934 // instantiation. Should this be a typedef or something like it?
935
936 RecordDecl *Pattern = Template->getTemplatedDecl();
Douglas Gregor3cf538d2009-03-11 18:59:21 +0000937 llvm::SmallVector<DeclTy *, 32> Fields;
Douglas Gregor4fdf1fa2009-03-11 16:48:53 +0000938 for (RecordDecl::decl_iterator Member = Pattern->decls_begin(),
939 MemberEnd = Pattern->decls_end();
940 Member != MemberEnd; ++Member) {
941 if (TypedefDecl *Typedef = dyn_cast<TypedefDecl>(*Member)) {
942 // FIXME: Simplified instantiation of typedefs needs to be made
943 // "real".
944 QualType T = Typedef->getUnderlyingType();
945 if (T->isDependentType()) {
946 T = InstantiateType(T, ClassTemplateSpec->getTemplateArgs(),
947 ClassTemplateSpec->getNumTemplateArgs(),
948 Typedef->getLocation(),
949 Typedef->getDeclName());
950 if (T.isNull()) {
951 Invalid = true;
952 T = Context.IntTy;
953 }
954 }
955
956 // Create the new typedef
957 TypedefDecl *New
958 = TypedefDecl::Create(Context, ClassTemplateSpec,
959 Typedef->getLocation(),
960 Typedef->getIdentifier(),
961 T);
962 ClassTemplateSpec->addDecl(New);
Douglas Gregor3cf538d2009-03-11 18:59:21 +0000963 }
964 else if (FieldDecl *Field = dyn_cast<FieldDecl>(*Member)) {
965 // FIXME: Simplified instantiation of fields needs to be made
966 // "real".
Douglas Gregora0e500d2009-03-12 16:53:44 +0000967 bool InvalidDecl = false;
Douglas Gregor3cf538d2009-03-11 18:59:21 +0000968 QualType T = Field->getType();
969 if (T->isDependentType()) {
970 T = InstantiateType(T, ClassTemplateSpec->getTemplateArgs(),
971 ClassTemplateSpec->getNumTemplateArgs(),
972 Field->getLocation(),
973 Field->getDeclName());
974 if (!T.isNull() && T->isFunctionType()) {
975 // C++ [temp.arg.type]p3:
976 // If a declaration acquires a function type through a type
977 // dependent on a template-parameter and this causes a
978 // declaration that does not use the syntactic form of a
979 // function declarator to have function type, the program is
980 // ill-formed.
981 Diag(Field->getLocation(), diag::err_field_instantiates_to_function)
982 << T;
983 T = QualType();
Douglas Gregora0e500d2009-03-12 16:53:44 +0000984 InvalidDecl = true;
Douglas Gregor3cf538d2009-03-11 18:59:21 +0000985 }
986 }
987
Douglas Gregora0e500d2009-03-12 16:53:44 +0000988 Expr *BitWidth = Field->getBitWidth();
989 if (InvalidDecl)
990 BitWidth = 0;
991 if (BitWidth &&
992 (BitWidth->isTypeDependent() || BitWidth->isValueDependent())) {
993 OwningExprResult InstantiatedBitWidth
994 = InstantiateExpr(BitWidth,
995 ClassTemplateSpec->getTemplateArgs(),
996 ClassTemplateSpec->getNumTemplateArgs());
997 if (InstantiatedBitWidth.isInvalid()) {
998 Invalid = InvalidDecl = true;
999 BitWidth = 0;
1000 } else
1001 BitWidth = (Expr *)InstantiatedBitWidth.release();
1002 }
1003
Douglas Gregor3cf538d2009-03-11 18:59:21 +00001004 FieldDecl *New = CheckFieldDecl(Field->getDeclName(), T,
1005 ClassTemplateSpec,
1006 Field->getLocation(),
1007 Field->isMutable(),
Douglas Gregora0e500d2009-03-12 16:53:44 +00001008 BitWidth,
Douglas Gregor4dd55f52009-03-11 20:50:30 +00001009 Field->getAccess(),
Douglas Gregor3cf538d2009-03-11 18:59:21 +00001010 0);
1011 if (New) {
1012 ClassTemplateSpec->addDecl(New);
1013 Fields.push_back(New);
1014
Douglas Gregora0e500d2009-03-12 16:53:44 +00001015 if (InvalidDecl)
1016 New->setInvalidDecl();
1017
Douglas Gregor3cf538d2009-03-11 18:59:21 +00001018 if (New->isInvalidDecl())
1019 Invalid = true;
1020 }
Douglas Gregor4fdf1fa2009-03-11 16:48:53 +00001021 }
1022 }
1023
Douglas Gregor3cf538d2009-03-11 18:59:21 +00001024 // Finish checking fields.
1025 ActOnFields(0, ClassTemplateSpec->getLocation(), ClassTemplateSpec,
1026 &Fields[0], Fields.size(), SourceLocation(), SourceLocation(),
1027 0);
1028
Douglas Gregor2943aed2009-03-03 04:44:36 +00001029 // Add any implicitly-declared members that we might need.
1030 AddImplicitlyDeclaredMembersToClass(ClassTemplateSpec);
1031
Douglas Gregor2943aed2009-03-03 04:44:36 +00001032 // Exit the scope of this instantiation.
1033 CurContext = PreviousContext;
1034
1035 return Invalid;
1036}