Douglas Gregor | 7429654 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 1 | //===------- 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" |
Douglas Gregor | 841324a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 14 | #include "TreeTransform.h" |
Douglas Gregor | dc18e89 | 2009-05-26 20:50:29 +0000 | [diff] [blame] | 15 | #include "clang/AST/ASTConsumer.h" |
Douglas Gregor | 7429654 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 16 | #include "clang/AST/ASTContext.h" |
| 17 | #include "clang/AST/Expr.h" |
Douglas Gregor | 7429654 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 18 | #include "clang/AST/DeclTemplate.h" |
| 19 | #include "clang/Parse/DeclSpec.h" |
| 20 | #include "clang/Basic/LangOptions.h" |
Douglas Gregor | f57dcd0 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 21 | #include "llvm/Support/Compiler.h" |
Douglas Gregor | 7429654 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 22 | |
| 23 | using namespace clang; |
| 24 | |
Douglas Gregor | fee85d6 | 2009-03-10 18:03:33 +0000 | [diff] [blame] | 25 | //===----------------------------------------------------------------------===/ |
| 26 | // Template Instantiation Support |
| 27 | //===----------------------------------------------------------------------===/ |
| 28 | |
Douglas Gregor | 8dbd038 | 2009-08-28 20:31:08 +0000 | [diff] [blame^] | 29 | /// \brief Retrieve the template argument list(s) that should be used to |
| 30 | /// instantiate the definition of the given declaration. |
Douglas Gregor | 5b8beb3 | 2009-08-28 17:37:35 +0000 | [diff] [blame] | 31 | MultiLevelTemplateArgumentList |
Douglas Gregor | 5f62c5e | 2009-05-14 23:26:13 +0000 | [diff] [blame] | 32 | Sema::getTemplateInstantiationArgs(NamedDecl *D) { |
Douglas Gregor | 5b8beb3 | 2009-08-28 17:37:35 +0000 | [diff] [blame] | 33 | // Accumulate the set of template argument lists in this structure. |
| 34 | MultiLevelTemplateArgumentList Result; |
| 35 | |
| 36 | DeclContext *Ctx = dyn_cast<DeclContext>(D); |
| 37 | if (!Ctx) |
| 38 | Ctx = D->getDeclContext(); |
| 39 | |
| 40 | for (; !Ctx->isFileContext(); Ctx = Ctx->getParent()) { |
| 41 | // Add template arguments from a class template instantiation. |
| 42 | if (ClassTemplateSpecializationDecl *Spec |
| 43 | = dyn_cast<ClassTemplateSpecializationDecl>(Ctx)) { |
| 44 | // We're done when we hit an explicit specialization. |
| 45 | if (Spec->getSpecializationKind() == TSK_ExplicitSpecialization) |
| 46 | break; |
Douglas Gregor | 6f5e054 | 2009-06-26 00:10:03 +0000 | [diff] [blame] | 47 | |
Douglas Gregor | 5b8beb3 | 2009-08-28 17:37:35 +0000 | [diff] [blame] | 48 | Result.addOuterTemplateArguments(&Spec->getTemplateInstantiationArgs()); |
| 49 | continue; |
| 50 | } |
| 51 | |
| 52 | // Add template arguments from a function template specialization. |
| 53 | if (FunctionDecl *Function = dyn_cast<FunctionDecl>(Ctx)) { |
| 54 | // FIXME: Check whether this is an explicit specialization. |
| 55 | if (const TemplateArgumentList *TemplateArgs |
| 56 | = Function->getTemplateSpecializationArgs()) |
| 57 | Result.addOuterTemplateArguments(TemplateArgs); |
| 58 | |
| 59 | continue; |
| 60 | } |
Douglas Gregor | 5f62c5e | 2009-05-14 23:26:13 +0000 | [diff] [blame] | 61 | } |
Douglas Gregor | 5b8beb3 | 2009-08-28 17:37:35 +0000 | [diff] [blame] | 62 | |
| 63 | return Result; |
Douglas Gregor | 5f62c5e | 2009-05-14 23:26:13 +0000 | [diff] [blame] | 64 | } |
| 65 | |
Douglas Gregor | 375733c | 2009-03-10 00:06:19 +0000 | [diff] [blame] | 66 | Sema::InstantiatingTemplate:: |
| 67 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
Douglas Gregor | b12249d | 2009-05-18 17:01:57 +0000 | [diff] [blame] | 68 | Decl *Entity, |
Douglas Gregor | 375733c | 2009-03-10 00:06:19 +0000 | [diff] [blame] | 69 | SourceRange InstantiationRange) |
| 70 | : SemaRef(SemaRef) { |
Douglas Gregor | 56d25a7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 71 | |
| 72 | Invalid = CheckInstantiationDepth(PointOfInstantiation, |
| 73 | InstantiationRange); |
| 74 | if (!Invalid) { |
Douglas Gregor | 375733c | 2009-03-10 00:06:19 +0000 | [diff] [blame] | 75 | ActiveTemplateInstantiation Inst; |
Douglas Gregor | 56d25a7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 76 | Inst.Kind = ActiveTemplateInstantiation::TemplateInstantiation; |
Douglas Gregor | 375733c | 2009-03-10 00:06:19 +0000 | [diff] [blame] | 77 | Inst.PointOfInstantiation = PointOfInstantiation; |
Douglas Gregor | 56d25a7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 78 | Inst.Entity = reinterpret_cast<uintptr_t>(Entity); |
Douglas Gregor | 95ba128 | 2009-03-12 18:36:18 +0000 | [diff] [blame] | 79 | Inst.TemplateArgs = 0; |
| 80 | Inst.NumTemplateArgs = 0; |
Douglas Gregor | 56d25a7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 81 | Inst.InstantiationRange = InstantiationRange; |
| 82 | SemaRef.ActiveTemplateInstantiations.push_back(Inst); |
| 83 | Invalid = false; |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | Sema::InstantiatingTemplate::InstantiatingTemplate(Sema &SemaRef, |
| 88 | SourceLocation PointOfInstantiation, |
| 89 | TemplateDecl *Template, |
| 90 | const TemplateArgument *TemplateArgs, |
| 91 | unsigned NumTemplateArgs, |
| 92 | SourceRange InstantiationRange) |
| 93 | : SemaRef(SemaRef) { |
| 94 | |
| 95 | Invalid = CheckInstantiationDepth(PointOfInstantiation, |
| 96 | InstantiationRange); |
| 97 | if (!Invalid) { |
| 98 | ActiveTemplateInstantiation Inst; |
| 99 | Inst.Kind |
| 100 | = ActiveTemplateInstantiation::DefaultTemplateArgumentInstantiation; |
| 101 | Inst.PointOfInstantiation = PointOfInstantiation; |
| 102 | Inst.Entity = reinterpret_cast<uintptr_t>(Template); |
| 103 | Inst.TemplateArgs = TemplateArgs; |
| 104 | Inst.NumTemplateArgs = NumTemplateArgs; |
Douglas Gregor | 375733c | 2009-03-10 00:06:19 +0000 | [diff] [blame] | 105 | Inst.InstantiationRange = InstantiationRange; |
| 106 | SemaRef.ActiveTemplateInstantiations.push_back(Inst); |
| 107 | Invalid = false; |
| 108 | } |
| 109 | } |
| 110 | |
Douglas Gregor | c5e01af | 2009-06-10 23:47:09 +0000 | [diff] [blame] | 111 | Sema::InstantiatingTemplate::InstantiatingTemplate(Sema &SemaRef, |
| 112 | SourceLocation PointOfInstantiation, |
Douglas Gregor | 4c8b2b3 | 2009-07-01 22:01:06 +0000 | [diff] [blame] | 113 | FunctionTemplateDecl *FunctionTemplate, |
| 114 | const TemplateArgument *TemplateArgs, |
| 115 | unsigned NumTemplateArgs, |
| 116 | ActiveTemplateInstantiation::InstantiationKind Kind, |
| 117 | SourceRange InstantiationRange) |
| 118 | : SemaRef(SemaRef) { |
| 119 | |
| 120 | Invalid = CheckInstantiationDepth(PointOfInstantiation, |
| 121 | InstantiationRange); |
| 122 | if (!Invalid) { |
| 123 | ActiveTemplateInstantiation Inst; |
| 124 | Inst.Kind = Kind; |
| 125 | Inst.PointOfInstantiation = PointOfInstantiation; |
| 126 | Inst.Entity = reinterpret_cast<uintptr_t>(FunctionTemplate); |
| 127 | Inst.TemplateArgs = TemplateArgs; |
| 128 | Inst.NumTemplateArgs = NumTemplateArgs; |
| 129 | Inst.InstantiationRange = InstantiationRange; |
| 130 | SemaRef.ActiveTemplateInstantiations.push_back(Inst); |
| 131 | Invalid = false; |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | Sema::InstantiatingTemplate::InstantiatingTemplate(Sema &SemaRef, |
| 136 | SourceLocation PointOfInstantiation, |
Douglas Gregor | c5e01af | 2009-06-10 23:47:09 +0000 | [diff] [blame] | 137 | ClassTemplatePartialSpecializationDecl *PartialSpec, |
| 138 | const TemplateArgument *TemplateArgs, |
| 139 | unsigned NumTemplateArgs, |
| 140 | SourceRange InstantiationRange) |
| 141 | : SemaRef(SemaRef) { |
| 142 | |
| 143 | Invalid = CheckInstantiationDepth(PointOfInstantiation, |
| 144 | InstantiationRange); |
| 145 | if (!Invalid) { |
| 146 | ActiveTemplateInstantiation Inst; |
| 147 | Inst.Kind |
Douglas Gregor | 4c8b2b3 | 2009-07-01 22:01:06 +0000 | [diff] [blame] | 148 | = ActiveTemplateInstantiation::DeducedTemplateArgumentSubstitution; |
Douglas Gregor | c5e01af | 2009-06-10 23:47:09 +0000 | [diff] [blame] | 149 | Inst.PointOfInstantiation = PointOfInstantiation; |
| 150 | Inst.Entity = reinterpret_cast<uintptr_t>(PartialSpec); |
| 151 | Inst.TemplateArgs = TemplateArgs; |
| 152 | Inst.NumTemplateArgs = NumTemplateArgs; |
| 153 | Inst.InstantiationRange = InstantiationRange; |
| 154 | SemaRef.ActiveTemplateInstantiations.push_back(Inst); |
| 155 | Invalid = false; |
| 156 | } |
| 157 | } |
| 158 | |
Douglas Gregor | b12249d | 2009-05-18 17:01:57 +0000 | [diff] [blame] | 159 | void Sema::InstantiatingTemplate::Clear() { |
| 160 | if (!Invalid) { |
Douglas Gregor | 375733c | 2009-03-10 00:06:19 +0000 | [diff] [blame] | 161 | SemaRef.ActiveTemplateInstantiations.pop_back(); |
Douglas Gregor | b12249d | 2009-05-18 17:01:57 +0000 | [diff] [blame] | 162 | Invalid = true; |
| 163 | } |
Douglas Gregor | 375733c | 2009-03-10 00:06:19 +0000 | [diff] [blame] | 164 | } |
| 165 | |
Douglas Gregor | 56d25a7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 166 | bool Sema::InstantiatingTemplate::CheckInstantiationDepth( |
| 167 | SourceLocation PointOfInstantiation, |
| 168 | SourceRange InstantiationRange) { |
| 169 | if (SemaRef.ActiveTemplateInstantiations.size() |
| 170 | <= SemaRef.getLangOptions().InstantiationDepth) |
| 171 | return false; |
| 172 | |
| 173 | SemaRef.Diag(PointOfInstantiation, |
| 174 | diag::err_template_recursion_depth_exceeded) |
| 175 | << SemaRef.getLangOptions().InstantiationDepth |
| 176 | << InstantiationRange; |
| 177 | SemaRef.Diag(PointOfInstantiation, diag::note_template_recursion_depth) |
| 178 | << SemaRef.getLangOptions().InstantiationDepth; |
| 179 | return true; |
| 180 | } |
| 181 | |
Douglas Gregor | fee85d6 | 2009-03-10 18:03:33 +0000 | [diff] [blame] | 182 | /// \brief Prints the current instantiation stack through a series of |
| 183 | /// notes. |
| 184 | void Sema::PrintInstantiationStack() { |
Douglas Gregor | 4c8b2b3 | 2009-07-01 22:01:06 +0000 | [diff] [blame] | 185 | // FIXME: In all of these cases, we need to show the template arguments |
Douglas Gregor | fee85d6 | 2009-03-10 18:03:33 +0000 | [diff] [blame] | 186 | for (llvm::SmallVector<ActiveTemplateInstantiation, 16>::reverse_iterator |
| 187 | Active = ActiveTemplateInstantiations.rbegin(), |
| 188 | ActiveEnd = ActiveTemplateInstantiations.rend(); |
| 189 | Active != ActiveEnd; |
| 190 | ++Active) { |
Douglas Gregor | 56d25a7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 191 | switch (Active->Kind) { |
| 192 | case ActiveTemplateInstantiation::TemplateInstantiation: { |
Douglas Gregor | b12249d | 2009-05-18 17:01:57 +0000 | [diff] [blame] | 193 | Decl *D = reinterpret_cast<Decl *>(Active->Entity); |
| 194 | if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(D)) { |
| 195 | unsigned DiagID = diag::note_template_member_class_here; |
| 196 | if (isa<ClassTemplateSpecializationDecl>(Record)) |
| 197 | DiagID = diag::note_template_class_instantiation_here; |
| 198 | Diags.Report(FullSourceLoc(Active->PointOfInstantiation, SourceMgr), |
| 199 | DiagID) |
| 200 | << Context.getTypeDeclType(Record) |
| 201 | << Active->InstantiationRange; |
Douglas Gregor | 181fe79 | 2009-07-24 20:34:43 +0000 | [diff] [blame] | 202 | } else if (FunctionDecl *Function = dyn_cast<FunctionDecl>(D)) { |
Douglas Gregor | 6f5e054 | 2009-06-26 00:10:03 +0000 | [diff] [blame] | 203 | unsigned DiagID; |
| 204 | if (Function->getPrimaryTemplate()) |
| 205 | DiagID = diag::note_function_template_spec_here; |
| 206 | else |
| 207 | DiagID = diag::note_template_member_function_here; |
Douglas Gregor | b12249d | 2009-05-18 17:01:57 +0000 | [diff] [blame] | 208 | Diags.Report(FullSourceLoc(Active->PointOfInstantiation, SourceMgr), |
| 209 | DiagID) |
| 210 | << Function |
| 211 | << Active->InstantiationRange; |
Douglas Gregor | 181fe79 | 2009-07-24 20:34:43 +0000 | [diff] [blame] | 212 | } else { |
| 213 | Diags.Report(FullSourceLoc(Active->PointOfInstantiation, SourceMgr), |
| 214 | diag::note_template_static_data_member_def_here) |
| 215 | << cast<VarDecl>(D) |
| 216 | << Active->InstantiationRange; |
Douglas Gregor | b12249d | 2009-05-18 17:01:57 +0000 | [diff] [blame] | 217 | } |
Douglas Gregor | 56d25a7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 218 | break; |
| 219 | } |
| 220 | |
| 221 | case ActiveTemplateInstantiation::DefaultTemplateArgumentInstantiation: { |
| 222 | TemplateDecl *Template = cast<TemplateDecl>((Decl *)Active->Entity); |
| 223 | std::string TemplateArgsStr |
Douglas Gregor | dd13e84 | 2009-03-30 22:58:21 +0000 | [diff] [blame] | 224 | = TemplateSpecializationType::PrintTemplateArgumentList( |
Douglas Gregor | 4c8b2b3 | 2009-07-01 22:01:06 +0000 | [diff] [blame] | 225 | Active->TemplateArgs, |
Douglas Gregor | 3bf3bbc | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 226 | Active->NumTemplateArgs, |
| 227 | Context.PrintingPolicy); |
Douglas Gregor | 56d25a7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 228 | Diags.Report(FullSourceLoc(Active->PointOfInstantiation, SourceMgr), |
| 229 | diag::note_default_arg_instantiation_here) |
| 230 | << (Template->getNameAsString() + TemplateArgsStr) |
| 231 | << Active->InstantiationRange; |
| 232 | break; |
| 233 | } |
Douglas Gregor | c5e01af | 2009-06-10 23:47:09 +0000 | [diff] [blame] | 234 | |
Douglas Gregor | 4c8b2b3 | 2009-07-01 22:01:06 +0000 | [diff] [blame] | 235 | case ActiveTemplateInstantiation::ExplicitTemplateArgumentSubstitution: { |
| 236 | FunctionTemplateDecl *FnTmpl |
| 237 | = cast<FunctionTemplateDecl>((Decl *)Active->Entity); |
Douglas Gregor | c5e01af | 2009-06-10 23:47:09 +0000 | [diff] [blame] | 238 | Diags.Report(FullSourceLoc(Active->PointOfInstantiation, SourceMgr), |
Douglas Gregor | 4c8b2b3 | 2009-07-01 22:01:06 +0000 | [diff] [blame] | 239 | diag::note_explicit_template_arg_substitution_here) |
| 240 | << FnTmpl << Active->InstantiationRange; |
Douglas Gregor | c5e01af | 2009-06-10 23:47:09 +0000 | [diff] [blame] | 241 | break; |
| 242 | } |
Douglas Gregor | 4c8b2b3 | 2009-07-01 22:01:06 +0000 | [diff] [blame] | 243 | |
| 244 | case ActiveTemplateInstantiation::DeducedTemplateArgumentSubstitution: |
| 245 | if (ClassTemplatePartialSpecializationDecl *PartialSpec |
| 246 | = dyn_cast<ClassTemplatePartialSpecializationDecl>( |
| 247 | (Decl *)Active->Entity)) { |
| 248 | Diags.Report(FullSourceLoc(Active->PointOfInstantiation, SourceMgr), |
| 249 | diag::note_partial_spec_deduct_instantiation_here) |
| 250 | << Context.getTypeDeclType(PartialSpec) |
| 251 | << Active->InstantiationRange; |
| 252 | } else { |
| 253 | FunctionTemplateDecl *FnTmpl |
| 254 | = cast<FunctionTemplateDecl>((Decl *)Active->Entity); |
| 255 | Diags.Report(FullSourceLoc(Active->PointOfInstantiation, SourceMgr), |
| 256 | diag::note_function_template_deduction_instantiation_here) |
| 257 | << FnTmpl << Active->InstantiationRange; |
| 258 | } |
| 259 | break; |
Douglas Gregor | c5e01af | 2009-06-10 23:47:09 +0000 | [diff] [blame] | 260 | |
Douglas Gregor | 56d25a7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 261 | } |
Douglas Gregor | fee85d6 | 2009-03-10 18:03:33 +0000 | [diff] [blame] | 262 | } |
| 263 | } |
| 264 | |
Douglas Gregor | 95d6c95 | 2009-06-14 07:33:30 +0000 | [diff] [blame] | 265 | bool Sema::isSFINAEContext() const { |
| 266 | using llvm::SmallVector; |
| 267 | for (SmallVector<ActiveTemplateInstantiation, 16>::const_reverse_iterator |
| 268 | Active = ActiveTemplateInstantiations.rbegin(), |
| 269 | ActiveEnd = ActiveTemplateInstantiations.rend(); |
| 270 | Active != ActiveEnd; |
| 271 | ++Active) { |
| 272 | |
| 273 | switch(Active->Kind) { |
Douglas Gregor | 4c8b2b3 | 2009-07-01 22:01:06 +0000 | [diff] [blame] | 274 | case ActiveTemplateInstantiation::TemplateInstantiation: |
| 275 | // This is a template instantiation, so there is no SFINAE. |
| 276 | return false; |
| 277 | |
Douglas Gregor | 95d6c95 | 2009-06-14 07:33:30 +0000 | [diff] [blame] | 278 | case ActiveTemplateInstantiation::DefaultTemplateArgumentInstantiation: |
| 279 | // A default template argument instantiation may or may not be a |
| 280 | // SFINAE context; look further up the stack. |
| 281 | break; |
Douglas Gregor | 4c8b2b3 | 2009-07-01 22:01:06 +0000 | [diff] [blame] | 282 | |
| 283 | case ActiveTemplateInstantiation::ExplicitTemplateArgumentSubstitution: |
| 284 | case ActiveTemplateInstantiation::DeducedTemplateArgumentSubstitution: |
| 285 | // We're either substitution explicitly-specified template arguments |
| 286 | // or deduced template arguments, so SFINAE applies. |
| 287 | return true; |
Douglas Gregor | 95d6c95 | 2009-06-14 07:33:30 +0000 | [diff] [blame] | 288 | } |
| 289 | } |
| 290 | |
| 291 | return false; |
| 292 | } |
| 293 | |
Douglas Gregor | 7429654 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 294 | //===----------------------------------------------------------------------===/ |
| 295 | // Template Instantiation for Types |
| 296 | //===----------------------------------------------------------------------===/ |
Douglas Gregor | f57dcd0 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 297 | namespace { |
Douglas Gregor | 841324a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 298 | class VISIBILITY_HIDDEN TemplateInstantiator |
| 299 | : public TreeTransform<TemplateInstantiator> |
| 300 | { |
Douglas Gregor | 8dbd038 | 2009-08-28 20:31:08 +0000 | [diff] [blame^] | 301 | const MultiLevelTemplateArgumentList &TemplateArgs; |
Douglas Gregor | f57dcd0 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 302 | SourceLocation Loc; |
| 303 | DeclarationName Entity; |
Douglas Gregor | 7429654 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 304 | |
Douglas Gregor | f57dcd0 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 305 | public: |
Douglas Gregor | 23a44be | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 306 | typedef TreeTransform<TemplateInstantiator> inherited; |
| 307 | |
Douglas Gregor | 841324a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 308 | TemplateInstantiator(Sema &SemaRef, |
Douglas Gregor | 8dbd038 | 2009-08-28 20:31:08 +0000 | [diff] [blame^] | 309 | const MultiLevelTemplateArgumentList &TemplateArgs, |
Douglas Gregor | 841324a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 310 | SourceLocation Loc, |
| 311 | DeclarationName Entity) |
Douglas Gregor | 23a44be | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 312 | : inherited(SemaRef), TemplateArgs(TemplateArgs), Loc(Loc), |
| 313 | Entity(Entity) { } |
Douglas Gregor | f57dcd0 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 314 | |
Douglas Gregor | 841324a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 315 | /// \brief Determine whether the given type \p T has already been |
| 316 | /// transformed. |
| 317 | /// |
| 318 | /// For the purposes of template instantiation, a type has already been |
| 319 | /// transformed if it is NULL or if it is not dependent. |
| 320 | bool AlreadyTransformed(QualType T) { |
| 321 | return T.isNull() || !T->isDependentType(); |
Douglas Gregor | 9017791 | 2009-05-13 18:28:20 +0000 | [diff] [blame] | 322 | } |
Douglas Gregor | 841324a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 323 | |
| 324 | /// \brief Returns the location of the entity being instantiated, if known. |
| 325 | SourceLocation getBaseLocation() { return Loc; } |
| 326 | |
| 327 | /// \brief Returns the name of the entity being instantiated, if any. |
| 328 | DeclarationName getBaseEntity() { return Entity; } |
| 329 | |
Douglas Gregor | 841324a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 330 | /// \brief Transform the given declaration by instantiating a reference to |
| 331 | /// this declaration. |
| 332 | Decl *TransformDecl(Decl *D); |
Douglas Gregor | 9d87976 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 333 | |
Douglas Gregor | 23a44be | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 334 | /// \brief Transform the definition of the given declaration by |
| 335 | /// instantiating it. |
| 336 | Decl *TransformDefinition(Decl *D); |
| 337 | |
| 338 | /// \brief Rebuild the exception declaration and register the declaration |
| 339 | /// as an instantiated local. |
| 340 | VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T, |
| 341 | DeclaratorInfo *Declarator, |
| 342 | IdentifierInfo *Name, |
| 343 | SourceLocation Loc, SourceRange TypeRange); |
Douglas Gregor | 9d87976 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 344 | |
| 345 | Sema::OwningExprResult TransformDeclRefExpr(DeclRefExpr *E); |
| 346 | |
Douglas Gregor | 841324a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 347 | /// \brief Transforms a template type parameter type by performing |
| 348 | /// substitution of the corresponding template type argument. |
| 349 | QualType TransformTemplateTypeParmType(const TemplateTypeParmType *T); |
| 350 | }; |
Douglas Gregor | 1d38113 | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 351 | } |
| 352 | |
Douglas Gregor | 841324a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 353 | Decl *TemplateInstantiator::TransformDecl(Decl *D) { |
Douglas Gregor | 214d046 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 354 | if (TemplateTemplateParmDecl *TTP |
| 355 | = dyn_cast_or_null<TemplateTemplateParmDecl>(D)) { |
Douglas Gregor | 8dbd038 | 2009-08-28 20:31:08 +0000 | [diff] [blame^] | 356 | if (TTP->getDepth() < TemplateArgs.getNumLevels()) { |
| 357 | assert(TemplateArgs(TTP->getDepth(), TTP->getPosition()).getAsDecl() && |
| 358 | "Wrong kind of template template argument"); |
| 359 | return cast<TemplateDecl>(TemplateArgs(TTP->getDepth(), |
| 360 | TTP->getPosition()).getAsDecl()); |
| 361 | } |
| 362 | |
| 363 | // If the corresponding template argument is NULL or non-existent, it's |
| 364 | // because we are performing instantiation from explicitly-specified |
| 365 | // template arguments in a function template, but there were some |
| 366 | // arguments left unspecified. |
| 367 | if (!TemplateArgs.hasTemplateArgument(TTP->getDepth(), |
| 368 | TTP->getPosition())) |
| 369 | return D; |
| 370 | |
| 371 | // FIXME: Implement depth reduction of template template parameters |
| 372 | assert(false && |
| 373 | "Reducing depth of template template parameters is not yet implemented"); |
Douglas Gregor | 214d046 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 374 | } |
| 375 | |
John McCall | 0ba26ee | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 376 | return SemaRef.FindInstantiatedDecl(cast_or_null<NamedDecl>(D)); |
Douglas Gregor | 841324a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 377 | } |
| 378 | |
Douglas Gregor | 23a44be | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 379 | Decl *TemplateInstantiator::TransformDefinition(Decl *D) { |
John McCall | 0ba26ee | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 380 | Decl *Inst = getSema().SubstDecl(D, getSema().CurContext, TemplateArgs); |
Douglas Gregor | 23a44be | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 381 | if (!Inst) |
| 382 | return 0; |
| 383 | |
| 384 | getSema().CurrentInstantiationScope->InstantiatedLocal(D, Inst); |
| 385 | return Inst; |
| 386 | } |
| 387 | |
| 388 | VarDecl * |
| 389 | TemplateInstantiator::RebuildExceptionDecl(VarDecl *ExceptionDecl, |
| 390 | QualType T, |
| 391 | DeclaratorInfo *Declarator, |
| 392 | IdentifierInfo *Name, |
| 393 | SourceLocation Loc, |
| 394 | SourceRange TypeRange) { |
| 395 | VarDecl *Var = inherited::RebuildExceptionDecl(ExceptionDecl, T, Declarator, |
| 396 | Name, Loc, TypeRange); |
| 397 | if (Var && !Var->isInvalidDecl()) |
| 398 | getSema().CurrentInstantiationScope->InstantiatedLocal(ExceptionDecl, Var); |
| 399 | return Var; |
| 400 | } |
| 401 | |
Douglas Gregor | 9d87976 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 402 | Sema::OwningExprResult |
| 403 | TemplateInstantiator::TransformDeclRefExpr(DeclRefExpr *E) { |
| 404 | // FIXME: Clean this up a bit |
| 405 | NamedDecl *D = E->getDecl(); |
| 406 | if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(D)) { |
Douglas Gregor | 8dbd038 | 2009-08-28 20:31:08 +0000 | [diff] [blame^] | 407 | if (NTTP->getDepth() >= TemplateArgs.getNumLevels()) { |
| 408 | assert(false && "Cannot reduce non-type template parameter depth yet"); |
| 409 | return getSema().ExprError(); |
| 410 | } |
Douglas Gregor | 9d87976 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 411 | |
| 412 | // If the corresponding template argument is NULL or non-existent, it's |
| 413 | // because we are performing instantiation from explicitly-specified |
| 414 | // template arguments in a function template, but there were some |
| 415 | // arguments left unspecified. |
Douglas Gregor | 8dbd038 | 2009-08-28 20:31:08 +0000 | [diff] [blame^] | 416 | if (!TemplateArgs.hasTemplateArgument(NTTP->getDepth(), |
| 417 | NTTP->getPosition())) |
| 418 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | 9d87976 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 419 | |
Douglas Gregor | 8dbd038 | 2009-08-28 20:31:08 +0000 | [diff] [blame^] | 420 | const TemplateArgument &Arg = TemplateArgs(NTTP->getDepth(), |
| 421 | NTTP->getPosition()); |
Douglas Gregor | 9d87976 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 422 | |
| 423 | // The template argument itself might be an expression, in which |
| 424 | // case we just return that expression. |
| 425 | if (Arg.getKind() == TemplateArgument::Expression) |
Douglas Gregor | 8dbd038 | 2009-08-28 20:31:08 +0000 | [diff] [blame^] | 426 | return SemaRef.Owned(Arg.getAsExpr()->Retain()); |
Douglas Gregor | 9d87976 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 427 | |
| 428 | if (Arg.getKind() == TemplateArgument::Declaration) { |
| 429 | ValueDecl *VD = cast<ValueDecl>(Arg.getAsDecl()); |
| 430 | |
Douglas Gregor | 8dbd038 | 2009-08-28 20:31:08 +0000 | [diff] [blame^] | 431 | VD = cast_or_null<ValueDecl>(getSema().FindInstantiatedDecl(VD)); |
| 432 | if (!VD) |
| 433 | return SemaRef.ExprError(); |
| 434 | |
Douglas Gregor | 9d87976 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 435 | return SemaRef.BuildDeclRefExpr(VD, VD->getType(), E->getLocation(), |
Douglas Gregor | 8dbd038 | 2009-08-28 20:31:08 +0000 | [diff] [blame^] | 436 | /*FIXME:*/false, /*FIXME:*/false); |
Douglas Gregor | 9d87976 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 437 | } |
| 438 | |
| 439 | assert(Arg.getKind() == TemplateArgument::Integral); |
| 440 | QualType T = Arg.getIntegralType(); |
| 441 | if (T->isCharType() || T->isWideCharType()) |
| 442 | return SemaRef.Owned(new (SemaRef.Context) CharacterLiteral( |
Douglas Gregor | 8dbd038 | 2009-08-28 20:31:08 +0000 | [diff] [blame^] | 443 | Arg.getAsIntegral()->getZExtValue(), |
| 444 | T->isWideCharType(), |
| 445 | T, |
| 446 | E->getSourceRange().getBegin())); |
Douglas Gregor | 9d87976 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 447 | if (T->isBooleanType()) |
| 448 | return SemaRef.Owned(new (SemaRef.Context) CXXBoolLiteralExpr( |
Douglas Gregor | 8dbd038 | 2009-08-28 20:31:08 +0000 | [diff] [blame^] | 449 | Arg.getAsIntegral()->getBoolValue(), |
| 450 | T, |
| 451 | E->getSourceRange().getBegin())); |
Douglas Gregor | 9d87976 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 452 | |
| 453 | assert(Arg.getAsIntegral()->getBitWidth() == SemaRef.Context.getIntWidth(T)); |
| 454 | return SemaRef.Owned(new (SemaRef.Context) IntegerLiteral( |
Douglas Gregor | 8dbd038 | 2009-08-28 20:31:08 +0000 | [diff] [blame^] | 455 | *Arg.getAsIntegral(), |
| 456 | T, |
| 457 | E->getSourceRange().getBegin())); |
Douglas Gregor | 9d87976 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | if (OverloadedFunctionDecl *Ovl = dyn_cast<OverloadedFunctionDecl>(D)) { |
| 461 | // FIXME: instantiate each decl in the overload set |
| 462 | return SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Ovl, |
Douglas Gregor | 8dbd038 | 2009-08-28 20:31:08 +0000 | [diff] [blame^] | 463 | SemaRef.Context.OverloadTy, |
| 464 | E->getLocation(), |
| 465 | false, false)); |
Douglas Gregor | 9d87976 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 466 | } |
| 467 | |
John McCall | 0ba26ee | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 468 | NamedDecl *InstD = SemaRef.FindInstantiatedDecl(D); |
Douglas Gregor | 9d87976 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 469 | if (!InstD) |
| 470 | return SemaRef.ExprError(); |
| 471 | |
| 472 | // FIXME: nested-name-specifier for QualifiedDeclRefExpr |
| 473 | return SemaRef.BuildDeclarationNameExpr(E->getLocation(), InstD, |
| 474 | /*FIXME:*/false, |
| 475 | /*FIXME:*/0, |
| 476 | /*FIXME:*/false); |
| 477 | } |
| 478 | |
Douglas Gregor | f57dcd0 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 479 | QualType |
Douglas Gregor | 841324a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 480 | TemplateInstantiator::TransformTemplateTypeParmType( |
| 481 | const TemplateTypeParmType *T) { |
Douglas Gregor | 8dbd038 | 2009-08-28 20:31:08 +0000 | [diff] [blame^] | 482 | if (T->getDepth() < TemplateArgs.getNumLevels()) { |
Douglas Gregor | 7429654 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 483 | // Replace the template type parameter with its corresponding |
| 484 | // template argument. |
Douglas Gregor | ecd63b8 | 2009-07-01 00:28:38 +0000 | [diff] [blame] | 485 | |
| 486 | // If the corresponding template argument is NULL or doesn't exist, it's |
| 487 | // because we are performing instantiation from explicitly-specified |
| 488 | // template arguments in a function template class, but there were some |
| 489 | // arguments left unspecified. |
Douglas Gregor | 8dbd038 | 2009-08-28 20:31:08 +0000 | [diff] [blame^] | 490 | if (!TemplateArgs.hasTemplateArgument(T->getDepth(), T->getIndex())) |
| 491 | return QualType(T, 0); |
| 492 | |
| 493 | assert(TemplateArgs(T->getDepth(), T->getIndex()).getKind() |
| 494 | == TemplateArgument::Type && |
Douglas Gregor | 7429654 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 495 | "Template argument kind mismatch"); |
Douglas Gregor | 8dbd038 | 2009-08-28 20:31:08 +0000 | [diff] [blame^] | 496 | |
| 497 | return TemplateArgs(T->getDepth(), T->getIndex()).getAsType(); |
Douglas Gregor | 7429654 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | // The template type parameter comes from an inner template (e.g., |
| 501 | // the template parameter list of a member template inside the |
| 502 | // template we are instantiating). Create a new template type |
| 503 | // parameter with the template "level" reduced by one. |
Douglas Gregor | 8dbd038 | 2009-08-28 20:31:08 +0000 | [diff] [blame^] | 504 | return getSema().Context.getTemplateTypeParmType( |
| 505 | T->getDepth() - TemplateArgs.getNumLevels(), |
Douglas Gregor | 841324a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 506 | T->getIndex(), |
| 507 | T->isParameterPack(), |
| 508 | T->getName()); |
Douglas Gregor | f57dcd0 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 509 | } |
Douglas Gregor | 7429654 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 510 | |
John McCall | 0ba26ee | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 511 | /// \brief Perform substitution on the type T with a given set of template |
| 512 | /// arguments. |
Douglas Gregor | 7429654 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 513 | /// |
| 514 | /// This routine substitutes the given template arguments into the |
| 515 | /// type T and produces the instantiated type. |
| 516 | /// |
| 517 | /// \param T the type into which the template arguments will be |
| 518 | /// substituted. If this type is not dependent, it will be returned |
| 519 | /// immediately. |
| 520 | /// |
| 521 | /// \param TemplateArgs the template arguments that will be |
| 522 | /// substituted for the top-level template parameters within T. |
| 523 | /// |
Douglas Gregor | 7429654 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 524 | /// \param Loc the location in the source code where this substitution |
| 525 | /// is being performed. It will typically be the location of the |
| 526 | /// declarator (if we're instantiating the type of some declaration) |
| 527 | /// or the location of the type in the source code (if, e.g., we're |
| 528 | /// instantiating the type of a cast expression). |
| 529 | /// |
| 530 | /// \param Entity the name of the entity associated with a declaration |
| 531 | /// being instantiated (if any). May be empty to indicate that there |
| 532 | /// is no such entity (if, e.g., this is a type that occurs as part of |
| 533 | /// a cast expression) or that the entity has no name (e.g., an |
| 534 | /// unnamed function parameter). |
| 535 | /// |
| 536 | /// \returns If the instantiation succeeds, the instantiated |
| 537 | /// type. Otherwise, produces diagnostics and returns a NULL type. |
John McCall | 0ba26ee | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 538 | QualType Sema::SubstType(QualType T, |
Douglas Gregor | 8dbd038 | 2009-08-28 20:31:08 +0000 | [diff] [blame^] | 539 | const MultiLevelTemplateArgumentList &TemplateArgs, |
John McCall | 0ba26ee | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 540 | SourceLocation Loc, DeclarationName Entity) { |
Douglas Gregor | 56d25a7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 541 | assert(!ActiveTemplateInstantiations.empty() && |
| 542 | "Cannot perform an instantiation without some context on the " |
| 543 | "instantiation stack"); |
| 544 | |
Douglas Gregor | 7429654 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 545 | // If T is not a dependent type, there is nothing to do. |
| 546 | if (!T->isDependentType()) |
| 547 | return T; |
| 548 | |
Douglas Gregor | 841324a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 549 | TemplateInstantiator Instantiator(*this, TemplateArgs, Loc, Entity); |
| 550 | return Instantiator.TransformType(T); |
Douglas Gregor | 7429654 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 551 | } |
Douglas Gregor | ed3a398 | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 552 | |
John McCall | 0ba26ee | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 553 | /// \brief Perform substitution on the base class specifiers of the |
| 554 | /// given class template specialization. |
Douglas Gregor | ed3a398 | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 555 | /// |
| 556 | /// Produces a diagnostic and returns true on error, returns false and |
| 557 | /// attaches the instantiated base classes to the class template |
| 558 | /// specialization if successful. |
| 559 | bool |
John McCall | 0ba26ee | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 560 | Sema::SubstBaseSpecifiers(CXXRecordDecl *Instantiation, |
| 561 | CXXRecordDecl *Pattern, |
Douglas Gregor | 8dbd038 | 2009-08-28 20:31:08 +0000 | [diff] [blame^] | 562 | const MultiLevelTemplateArgumentList &TemplateArgs) { |
Douglas Gregor | ed3a398 | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 563 | bool Invalid = false; |
Douglas Gregor | 4ac20ef | 2009-05-29 18:27:38 +0000 | [diff] [blame] | 564 | llvm::SmallVector<CXXBaseSpecifier*, 4> InstantiatedBases; |
Douglas Gregor | cc88797 | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 565 | for (ClassTemplateSpecializationDecl::base_class_iterator |
| 566 | Base = Pattern->bases_begin(), BaseEnd = Pattern->bases_end(); |
Douglas Gregor | d9572a1 | 2009-03-10 18:52:44 +0000 | [diff] [blame] | 567 | Base != BaseEnd; ++Base) { |
Douglas Gregor | ed3a398 | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 568 | if (!Base->getType()->isDependentType()) { |
Fariborz Jahanian | 1373b6f | 2009-07-22 17:41:53 +0000 | [diff] [blame] | 569 | InstantiatedBases.push_back(new (Context) CXXBaseSpecifier(*Base)); |
Douglas Gregor | ed3a398 | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 570 | continue; |
| 571 | } |
| 572 | |
John McCall | 0ba26ee | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 573 | QualType BaseType = SubstType(Base->getType(), |
| 574 | TemplateArgs, |
| 575 | Base->getSourceRange().getBegin(), |
| 576 | DeclarationName()); |
Douglas Gregor | ed3a398 | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 577 | if (BaseType.isNull()) { |
| 578 | Invalid = true; |
| 579 | continue; |
| 580 | } |
| 581 | |
| 582 | if (CXXBaseSpecifier *InstantiatedBase |
Douglas Gregor | cc88797 | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 583 | = CheckBaseSpecifier(Instantiation, |
Douglas Gregor | ed3a398 | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 584 | Base->getSourceRange(), |
| 585 | Base->isVirtual(), |
| 586 | Base->getAccessSpecifierAsWritten(), |
| 587 | BaseType, |
| 588 | /*FIXME: Not totally accurate */ |
| 589 | Base->getSourceRange().getBegin())) |
| 590 | InstantiatedBases.push_back(InstantiatedBase); |
| 591 | else |
| 592 | Invalid = true; |
| 593 | } |
| 594 | |
Douglas Gregor | d9572a1 | 2009-03-10 18:52:44 +0000 | [diff] [blame] | 595 | if (!Invalid && |
Jay Foad | 9e6bef4 | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 596 | AttachBaseSpecifiers(Instantiation, InstantiatedBases.data(), |
Douglas Gregor | ed3a398 | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 597 | InstantiatedBases.size())) |
| 598 | Invalid = true; |
| 599 | |
| 600 | return Invalid; |
| 601 | } |
| 602 | |
Douglas Gregor | cc88797 | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 603 | /// \brief Instantiate the definition of a class from a given pattern. |
| 604 | /// |
| 605 | /// \param PointOfInstantiation The point of instantiation within the |
| 606 | /// source code. |
| 607 | /// |
| 608 | /// \param Instantiation is the declaration whose definition is being |
| 609 | /// instantiated. This will be either a class template specialization |
| 610 | /// or a member class of a class template specialization. |
| 611 | /// |
| 612 | /// \param Pattern is the pattern from which the instantiation |
| 613 | /// occurs. This will be either the declaration of a class template or |
| 614 | /// the declaration of a member class of a class template. |
| 615 | /// |
| 616 | /// \param TemplateArgs The template arguments to be substituted into |
| 617 | /// the pattern. |
| 618 | /// |
Douglas Gregor | b35c799 | 2009-08-24 15:23:48 +0000 | [diff] [blame] | 619 | /// \param ExplicitInstantiation whether this is an explicit instantiation |
| 620 | /// (otherwise, it is an implicit instantiation). |
| 621 | /// |
| 622 | /// \param Complain whether to complain if the class cannot be instantiated due |
| 623 | /// to the lack of a definition. |
| 624 | /// |
Douglas Gregor | cc88797 | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 625 | /// \returns true if an error occurred, false otherwise. |
| 626 | bool |
| 627 | Sema::InstantiateClass(SourceLocation PointOfInstantiation, |
| 628 | CXXRecordDecl *Instantiation, CXXRecordDecl *Pattern, |
Douglas Gregor | 8dbd038 | 2009-08-28 20:31:08 +0000 | [diff] [blame^] | 629 | const MultiLevelTemplateArgumentList &TemplateArgs, |
Douglas Gregor | b35c799 | 2009-08-24 15:23:48 +0000 | [diff] [blame] | 630 | bool ExplicitInstantiation, |
| 631 | bool Complain) { |
Douglas Gregor | cc88797 | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 632 | bool Invalid = false; |
John McCall | d64b41e | 2009-08-20 01:44:21 +0000 | [diff] [blame] | 633 | |
Douglas Gregor | cc88797 | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 634 | CXXRecordDecl *PatternDef |
| 635 | = cast_or_null<CXXRecordDecl>(Pattern->getDefinition(Context)); |
| 636 | if (!PatternDef) { |
Douglas Gregor | b35c799 | 2009-08-24 15:23:48 +0000 | [diff] [blame] | 637 | if (!Complain) { |
| 638 | // Say nothing |
| 639 | } else if (Pattern == Instantiation->getInstantiatedFromMemberClass()) { |
Douglas Gregor | cc88797 | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 640 | Diag(PointOfInstantiation, |
| 641 | diag::err_implicit_instantiate_member_undefined) |
| 642 | << Context.getTypeDeclType(Instantiation); |
| 643 | Diag(Pattern->getLocation(), diag::note_member_of_template_here); |
| 644 | } else { |
Douglas Gregor | fd79ac6 | 2009-05-13 00:25:59 +0000 | [diff] [blame] | 645 | Diag(PointOfInstantiation, diag::err_template_instantiate_undefined) |
| 646 | << ExplicitInstantiation |
Douglas Gregor | cc88797 | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 647 | << Context.getTypeDeclType(Instantiation); |
| 648 | Diag(Pattern->getLocation(), diag::note_template_decl_here); |
| 649 | } |
| 650 | return true; |
| 651 | } |
| 652 | Pattern = PatternDef; |
| 653 | |
Douglas Gregor | 42c4852 | 2009-03-25 21:23:52 +0000 | [diff] [blame] | 654 | InstantiatingTemplate Inst(*this, PointOfInstantiation, Instantiation); |
Douglas Gregor | cc88797 | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 655 | if (Inst) |
| 656 | return true; |
| 657 | |
| 658 | // Enter the scope of this instantiation. We don't use |
| 659 | // PushDeclContext because we don't have a scope. |
| 660 | DeclContext *PreviousContext = CurContext; |
| 661 | CurContext = Instantiation; |
| 662 | |
| 663 | // Start the definition of this instantiation. |
| 664 | Instantiation->startDefinition(); |
| 665 | |
John McCall | 0ba26ee | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 666 | // Do substitution on the base class specifiers. |
| 667 | if (SubstBaseSpecifiers(Instantiation, Pattern, TemplateArgs)) |
Douglas Gregor | cc88797 | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 668 | Invalid = true; |
| 669 | |
Douglas Gregor | 4ac20ef | 2009-05-29 18:27:38 +0000 | [diff] [blame] | 670 | llvm::SmallVector<DeclPtrTy, 4> Fields; |
Argiris Kirtzidis | ab6e38a | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 671 | for (RecordDecl::decl_iterator Member = Pattern->decls_begin(), |
| 672 | MemberEnd = Pattern->decls_end(); |
Douglas Gregor | c55b0b0 | 2009-04-09 21:40:53 +0000 | [diff] [blame] | 673 | Member != MemberEnd; ++Member) { |
John McCall | 0ba26ee | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 674 | Decl *NewMember = SubstDecl(*Member, Instantiation, TemplateArgs); |
Douglas Gregor | cc88797 | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 675 | if (NewMember) { |
| 676 | if (NewMember->isInvalidDecl()) |
| 677 | Invalid = true; |
| 678 | else if (FieldDecl *Field = dyn_cast<FieldDecl>(NewMember)) |
Chris Lattner | 5261d0c | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 679 | Fields.push_back(DeclPtrTy::make(Field)); |
Douglas Gregor | cc88797 | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 680 | } else { |
| 681 | // FIXME: Eventually, a NULL return will mean that one of the |
Mike Stump | e127ae3 | 2009-05-16 07:39:55 +0000 | [diff] [blame] | 682 | // instantiations was a semantic disaster, and we'll want to set Invalid = |
| 683 | // true. For now, we expect to skip some members that we can't yet handle. |
Douglas Gregor | cc88797 | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 684 | } |
| 685 | } |
| 686 | |
| 687 | // Finish checking fields. |
Chris Lattner | 5261d0c | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 688 | ActOnFields(0, Instantiation->getLocation(), DeclPtrTy::make(Instantiation), |
Jay Foad | 9e6bef4 | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 689 | Fields.data(), Fields.size(), SourceLocation(), SourceLocation(), |
Douglas Gregor | cc88797 | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 690 | 0); |
| 691 | |
| 692 | // Add any implicitly-declared members that we might need. |
| 693 | AddImplicitlyDeclaredMembersToClass(Instantiation); |
| 694 | |
| 695 | // Exit the scope of this instantiation. |
| 696 | CurContext = PreviousContext; |
| 697 | |
Douglas Gregor | dc18e89 | 2009-05-26 20:50:29 +0000 | [diff] [blame] | 698 | if (!Invalid) |
| 699 | Consumer.HandleTagDeclDefinition(Instantiation); |
| 700 | |
Douglas Gregor | df9f5d1 | 2009-05-13 20:28:22 +0000 | [diff] [blame] | 701 | // If this is an explicit instantiation, instantiate our members, too. |
Douglas Gregor | b12249d | 2009-05-18 17:01:57 +0000 | [diff] [blame] | 702 | if (!Invalid && ExplicitInstantiation) { |
| 703 | Inst.Clear(); |
Douglas Gregor | df9f5d1 | 2009-05-13 20:28:22 +0000 | [diff] [blame] | 704 | InstantiateClassMembers(PointOfInstantiation, Instantiation, TemplateArgs); |
Douglas Gregor | b12249d | 2009-05-18 17:01:57 +0000 | [diff] [blame] | 705 | } |
Douglas Gregor | df9f5d1 | 2009-05-13 20:28:22 +0000 | [diff] [blame] | 706 | |
Douglas Gregor | cc88797 | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 707 | return Invalid; |
| 708 | } |
| 709 | |
Douglas Gregor | ed3a398 | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 710 | bool |
| 711 | Sema::InstantiateClassTemplateSpecialization( |
| 712 | ClassTemplateSpecializationDecl *ClassTemplateSpec, |
Douglas Gregor | b35c799 | 2009-08-24 15:23:48 +0000 | [diff] [blame] | 713 | bool ExplicitInstantiation, |
| 714 | bool Complain) { |
Douglas Gregor | ed3a398 | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 715 | // Perform the actual instantiation on the canonical declaration. |
| 716 | ClassTemplateSpec = cast<ClassTemplateSpecializationDecl>( |
Argiris Kirtzidis | 17c7cab | 2009-07-18 00:34:25 +0000 | [diff] [blame] | 717 | ClassTemplateSpec->getCanonicalDecl()); |
Douglas Gregor | ed3a398 | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 718 | |
| 719 | // We can only instantiate something that hasn't already been |
| 720 | // instantiated or specialized. Fail without any diagnostics: our |
| 721 | // caller will provide an error message. |
| 722 | if (ClassTemplateSpec->getSpecializationKind() != TSK_Undeclared) |
| 723 | return true; |
| 724 | |
Douglas Gregor | ed3a398 | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 725 | ClassTemplateDecl *Template = ClassTemplateSpec->getSpecializedTemplate(); |
Douglas Gregor | 8dbd038 | 2009-08-28 20:31:08 +0000 | [diff] [blame^] | 726 | CXXRecordDecl *Pattern = 0; |
Douglas Gregor | 58944ac | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 727 | |
Douglas Gregor | 21530c5 | 2009-06-12 22:31:52 +0000 | [diff] [blame] | 728 | // C++ [temp.class.spec.match]p1: |
| 729 | // When a class template is used in a context that requires an |
| 730 | // instantiation of the class, it is necessary to determine |
| 731 | // whether the instantiation is to be generated using the primary |
| 732 | // template or one of the partial specializations. This is done by |
| 733 | // matching the template arguments of the class template |
| 734 | // specialization with the template argument lists of the partial |
| 735 | // specializations. |
Douglas Gregor | ab9f71a | 2009-06-05 00:53:49 +0000 | [diff] [blame] | 736 | typedef std::pair<ClassTemplatePartialSpecializationDecl *, |
| 737 | TemplateArgumentList *> MatchResult; |
| 738 | llvm::SmallVector<MatchResult, 4> Matched; |
Douglas Gregor | 58944ac | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 739 | for (llvm::FoldingSet<ClassTemplatePartialSpecializationDecl>::iterator |
| 740 | Partial = Template->getPartialSpecializations().begin(), |
| 741 | PartialEnd = Template->getPartialSpecializations().end(); |
| 742 | Partial != PartialEnd; |
| 743 | ++Partial) { |
Douglas Gregor | 623e2e0 | 2009-06-12 18:26:56 +0000 | [diff] [blame] | 744 | TemplateDeductionInfo Info(Context); |
| 745 | if (TemplateDeductionResult Result |
Douglas Gregor | ab9f71a | 2009-06-05 00:53:49 +0000 | [diff] [blame] | 746 | = DeduceTemplateArguments(&*Partial, |
Douglas Gregor | 623e2e0 | 2009-06-12 18:26:56 +0000 | [diff] [blame] | 747 | ClassTemplateSpec->getTemplateArgs(), |
| 748 | Info)) { |
| 749 | // FIXME: Store the failed-deduction information for use in |
| 750 | // diagnostics, later. |
| 751 | (void)Result; |
| 752 | } else { |
| 753 | Matched.push_back(std::make_pair(&*Partial, Info.take())); |
| 754 | } |
Douglas Gregor | 58944ac | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 755 | } |
| 756 | |
| 757 | if (Matched.size() == 1) { |
Douglas Gregor | 21530c5 | 2009-06-12 22:31:52 +0000 | [diff] [blame] | 758 | // -- If exactly one matching specialization is found, the |
| 759 | // instantiation is generated from that specialization. |
Douglas Gregor | ab9f71a | 2009-06-05 00:53:49 +0000 | [diff] [blame] | 760 | Pattern = Matched[0].first; |
Douglas Gregor | 7b0b83f | 2009-08-02 23:24:31 +0000 | [diff] [blame] | 761 | ClassTemplateSpec->setInstantiationOf(Matched[0].first, Matched[0].second); |
Douglas Gregor | 58944ac | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 762 | } else if (Matched.size() > 1) { |
Douglas Gregor | 21530c5 | 2009-06-12 22:31:52 +0000 | [diff] [blame] | 763 | // -- If more than one matching specialization is found, the |
| 764 | // partial order rules (14.5.4.2) are used to determine |
| 765 | // whether one of the specializations is more specialized |
| 766 | // than the others. If none of the specializations is more |
| 767 | // specialized than all of the other matching |
| 768 | // specializations, then the use of the class template is |
| 769 | // ambiguous and the program is ill-formed. |
Douglas Gregor | 58944ac | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 770 | // FIXME: Implement partial ordering of class template partial |
| 771 | // specializations. |
| 772 | Diag(ClassTemplateSpec->getLocation(), |
| 773 | diag::unsup_template_partial_spec_ordering); |
Douglas Gregor | 8dbd038 | 2009-08-28 20:31:08 +0000 | [diff] [blame^] | 774 | |
| 775 | // FIXME: Temporary hack to fall back to the primary template |
| 776 | ClassTemplateDecl *OrigTemplate = Template; |
| 777 | while (OrigTemplate->getInstantiatedFromMemberTemplate()) |
| 778 | OrigTemplate = OrigTemplate->getInstantiatedFromMemberTemplate(); |
| 779 | |
| 780 | Pattern = OrigTemplate->getTemplatedDecl(); |
Douglas Gregor | 21530c5 | 2009-06-12 22:31:52 +0000 | [diff] [blame] | 781 | } else { |
| 782 | // -- If no matches are found, the instantiation is generated |
| 783 | // from the primary template. |
Douglas Gregor | 8dbd038 | 2009-08-28 20:31:08 +0000 | [diff] [blame^] | 784 | ClassTemplateDecl *OrigTemplate = Template; |
| 785 | while (OrigTemplate->getInstantiatedFromMemberTemplate()) |
| 786 | OrigTemplate = OrigTemplate->getInstantiatedFromMemberTemplate(); |
| 787 | |
| 788 | Pattern = OrigTemplate->getTemplatedDecl(); |
Douglas Gregor | 58944ac | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 789 | } |
Douglas Gregor | ed3a398 | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 790 | |
Douglas Gregor | 8dbd038 | 2009-08-28 20:31:08 +0000 | [diff] [blame^] | 791 | // Note that this is an instantiation. |
Douglas Gregor | ed3a398 | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 792 | ClassTemplateSpec->setSpecializationKind( |
| 793 | ExplicitInstantiation? TSK_ExplicitInstantiation |
| 794 | : TSK_ImplicitInstantiation); |
| 795 | |
Douglas Gregor | ab9f71a | 2009-06-05 00:53:49 +0000 | [diff] [blame] | 796 | bool Result = InstantiateClass(ClassTemplateSpec->getLocation(), |
Douglas Gregor | 8dbd038 | 2009-08-28 20:31:08 +0000 | [diff] [blame^] | 797 | ClassTemplateSpec, Pattern, |
| 798 | getTemplateInstantiationArgs(ClassTemplateSpec), |
Douglas Gregor | b35c799 | 2009-08-24 15:23:48 +0000 | [diff] [blame] | 799 | ExplicitInstantiation, |
| 800 | Complain); |
Douglas Gregor | ab9f71a | 2009-06-05 00:53:49 +0000 | [diff] [blame] | 801 | |
| 802 | for (unsigned I = 0, N = Matched.size(); I != N; ++I) { |
| 803 | // FIXME: Implement TemplateArgumentList::Destroy! |
| 804 | // if (Matched[I].first != Pattern) |
| 805 | // Matched[I].second->Destroy(Context); |
| 806 | } |
| 807 | |
| 808 | return Result; |
Douglas Gregor | ed3a398 | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 809 | } |
Douglas Gregor | 47bde7c | 2009-03-19 17:26:29 +0000 | [diff] [blame] | 810 | |
John McCall | 0ba26ee | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 811 | /// \brief Instantiates the definitions of all of the member |
| 812 | /// of the given class, which is an instantiation of a class template |
| 813 | /// or a member class of a template. |
Douglas Gregor | df9f5d1 | 2009-05-13 20:28:22 +0000 | [diff] [blame] | 814 | void |
| 815 | Sema::InstantiateClassMembers(SourceLocation PointOfInstantiation, |
John McCall | 0ba26ee | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 816 | CXXRecordDecl *Instantiation, |
Douglas Gregor | 8dbd038 | 2009-08-28 20:31:08 +0000 | [diff] [blame^] | 817 | const MultiLevelTemplateArgumentList &TemplateArgs) { |
Argiris Kirtzidis | ab6e38a | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 818 | for (DeclContext::decl_iterator D = Instantiation->decls_begin(), |
| 819 | DEnd = Instantiation->decls_end(); |
Douglas Gregor | df9f5d1 | 2009-05-13 20:28:22 +0000 | [diff] [blame] | 820 | D != DEnd; ++D) { |
| 821 | if (FunctionDecl *Function = dyn_cast<FunctionDecl>(*D)) { |
Argiris Kirtzidis | ccb9efe | 2009-06-30 02:35:26 +0000 | [diff] [blame] | 822 | if (!Function->getBody()) |
Douglas Gregor | b12249d | 2009-05-18 17:01:57 +0000 | [diff] [blame] | 823 | InstantiateFunctionDefinition(PointOfInstantiation, Function); |
Douglas Gregor | df9f5d1 | 2009-05-13 20:28:22 +0000 | [diff] [blame] | 824 | } else if (VarDecl *Var = dyn_cast<VarDecl>(*D)) { |
Douglas Gregor | 181fe79 | 2009-07-24 20:34:43 +0000 | [diff] [blame] | 825 | if (Var->isStaticDataMember()) |
| 826 | InstantiateStaticDataMemberDefinition(PointOfInstantiation, Var); |
Douglas Gregor | df9f5d1 | 2009-05-13 20:28:22 +0000 | [diff] [blame] | 827 | } else if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(*D)) { |
| 828 | if (!Record->isInjectedClassName() && !Record->getDefinition(Context)) { |
| 829 | assert(Record->getInstantiatedFromMemberClass() && |
| 830 | "Missing instantiated-from-template information"); |
Douglas Gregor | b12249d | 2009-05-18 17:01:57 +0000 | [diff] [blame] | 831 | InstantiateClass(PointOfInstantiation, Record, |
Douglas Gregor | df9f5d1 | 2009-05-13 20:28:22 +0000 | [diff] [blame] | 832 | Record->getInstantiatedFromMemberClass(), |
| 833 | TemplateArgs, true); |
| 834 | } |
| 835 | } |
| 836 | } |
| 837 | } |
| 838 | |
| 839 | /// \brief Instantiate the definitions of all of the members of the |
| 840 | /// given class template specialization, which was named as part of an |
| 841 | /// explicit instantiation. |
| 842 | void Sema::InstantiateClassTemplateSpecializationMembers( |
| 843 | SourceLocation PointOfInstantiation, |
| 844 | ClassTemplateSpecializationDecl *ClassTemplateSpec) { |
| 845 | // C++0x [temp.explicit]p7: |
| 846 | // An explicit instantiation that names a class template |
| 847 | // specialization is an explicit instantion of the same kind |
| 848 | // (declaration or definition) of each of its members (not |
| 849 | // including members inherited from base classes) that has not |
| 850 | // been previously explicitly specialized in the translation unit |
| 851 | // containing the explicit instantiation, except as described |
| 852 | // below. |
| 853 | InstantiateClassMembers(PointOfInstantiation, ClassTemplateSpec, |
Douglas Gregor | 8dbd038 | 2009-08-28 20:31:08 +0000 | [diff] [blame^] | 854 | getTemplateInstantiationArgs(ClassTemplateSpec)); |
Douglas Gregor | df9f5d1 | 2009-05-13 20:28:22 +0000 | [diff] [blame] | 855 | } |
| 856 | |
Douglas Gregor | 23a44be | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 857 | Sema::OwningStmtResult |
Douglas Gregor | 8dbd038 | 2009-08-28 20:31:08 +0000 | [diff] [blame^] | 858 | Sema::SubstStmt(Stmt *S, const MultiLevelTemplateArgumentList &TemplateArgs) { |
Douglas Gregor | 23a44be | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 859 | if (!S) |
| 860 | return Owned(S); |
| 861 | |
| 862 | TemplateInstantiator Instantiator(*this, TemplateArgs, |
| 863 | SourceLocation(), |
| 864 | DeclarationName()); |
| 865 | return Instantiator.TransformStmt(S); |
| 866 | } |
| 867 | |
Douglas Gregor | 9d87976 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 868 | Sema::OwningExprResult |
Douglas Gregor | 8dbd038 | 2009-08-28 20:31:08 +0000 | [diff] [blame^] | 869 | Sema::SubstExpr(Expr *E, const MultiLevelTemplateArgumentList &TemplateArgs) { |
Douglas Gregor | 9d87976 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 870 | if (!E) |
| 871 | return Owned(E); |
| 872 | |
| 873 | TemplateInstantiator Instantiator(*this, TemplateArgs, |
| 874 | SourceLocation(), |
| 875 | DeclarationName()); |
| 876 | return Instantiator.TransformExpr(E); |
| 877 | } |
| 878 | |
John McCall | 0ba26ee | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 879 | /// \brief Do template substitution on a nested-name-specifier. |
Douglas Gregor | 1e589cc | 2009-03-26 23:50:42 +0000 | [diff] [blame] | 880 | NestedNameSpecifier * |
John McCall | 0ba26ee | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 881 | Sema::SubstNestedNameSpecifier(NestedNameSpecifier *NNS, |
Douglas Gregor | 8dbd038 | 2009-08-28 20:31:08 +0000 | [diff] [blame^] | 882 | SourceRange Range, |
| 883 | const MultiLevelTemplateArgumentList &TemplateArgs) { |
Douglas Gregor | 12431cb | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 884 | TemplateInstantiator Instantiator(*this, TemplateArgs, Range.getBegin(), |
| 885 | DeclarationName()); |
| 886 | return Instantiator.TransformNestedNameSpecifier(NNS, Range); |
Douglas Gregor | 47bde7c | 2009-03-19 17:26:29 +0000 | [diff] [blame] | 887 | } |
Douglas Gregor | 15a9285 | 2009-03-31 18:38:02 +0000 | [diff] [blame] | 888 | |
| 889 | TemplateName |
John McCall | 0ba26ee | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 890 | Sema::SubstTemplateName(TemplateName Name, SourceLocation Loc, |
Douglas Gregor | 8dbd038 | 2009-08-28 20:31:08 +0000 | [diff] [blame^] | 891 | const MultiLevelTemplateArgumentList &TemplateArgs) { |
Douglas Gregor | 214d046 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 892 | TemplateInstantiator Instantiator(*this, TemplateArgs, Loc, |
| 893 | DeclarationName()); |
| 894 | return Instantiator.TransformTemplateName(Name); |
Douglas Gregor | 15a9285 | 2009-03-31 18:38:02 +0000 | [diff] [blame] | 895 | } |
Douglas Gregor | b320b9e | 2009-06-11 00:06:24 +0000 | [diff] [blame] | 896 | |
John McCall | 0ba26ee | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 897 | TemplateArgument Sema::Subst(TemplateArgument Arg, |
Douglas Gregor | 8dbd038 | 2009-08-28 20:31:08 +0000 | [diff] [blame^] | 898 | const MultiLevelTemplateArgumentList &TemplateArgs) { |
Douglas Gregor | 2999faa | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 899 | TemplateInstantiator Instantiator(*this, TemplateArgs, SourceLocation(), |
| 900 | DeclarationName()); |
| 901 | return Instantiator.TransformTemplateArgument(Arg); |
Douglas Gregor | b320b9e | 2009-06-11 00:06:24 +0000 | [diff] [blame] | 902 | } |