Douglas Gregor | 99ebf65 | 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 | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 14 | #include "TreeTransform.h" |
Douglas Gregor | aba43bb | 2009-05-26 20:50:29 +0000 | [diff] [blame] | 15 | #include "clang/AST/ASTConsumer.h" |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 16 | #include "clang/AST/ASTContext.h" |
| 17 | #include "clang/AST/Expr.h" |
Douglas Gregor | 99ebf65 | 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 | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 21 | #include "llvm/Support/Compiler.h" |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 22 | |
| 23 | using namespace clang; |
| 24 | |
Douglas Gregor | ee1828a | 2009-03-10 18:03:33 +0000 | [diff] [blame] | 25 | //===----------------------------------------------------------------------===/ |
| 26 | // Template Instantiation Support |
| 27 | //===----------------------------------------------------------------------===/ |
| 28 | |
Douglas Gregor | d6350ae | 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 | d110243 | 2009-08-28 17:37:35 +0000 | [diff] [blame] | 31 | MultiLevelTemplateArgumentList |
Douglas Gregor | 54dabfc | 2009-05-14 23:26:13 +0000 | [diff] [blame] | 32 | Sema::getTemplateInstantiationArgs(NamedDecl *D) { |
Douglas Gregor | d110243 | 2009-08-28 17:37:35 +0000 | [diff] [blame] | 33 | // Accumulate the set of template argument lists in this structure. |
| 34 | MultiLevelTemplateArgumentList Result; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 35 | |
Douglas Gregor | d110243 | 2009-08-28 17:37:35 +0000 | [diff] [blame] | 36 | DeclContext *Ctx = dyn_cast<DeclContext>(D); |
| 37 | if (!Ctx) |
| 38 | Ctx = D->getDeclContext(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 39 | |
John McCall | f181d8a | 2009-08-29 03:16:09 +0000 | [diff] [blame] | 40 | while (!Ctx->isFileContext()) { |
Douglas Gregor | d110243 | 2009-08-28 17:37:35 +0000 | [diff] [blame] | 41 | // Add template arguments from a class template instantiation. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 42 | if (ClassTemplateSpecializationDecl *Spec |
Douglas Gregor | d110243 | 2009-08-28 17:37:35 +0000 | [diff] [blame] | 43 | = dyn_cast<ClassTemplateSpecializationDecl>(Ctx)) { |
| 44 | // We're done when we hit an explicit specialization. |
| 45 | if (Spec->getSpecializationKind() == TSK_ExplicitSpecialization) |
| 46 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 47 | |
Douglas Gregor | d110243 | 2009-08-28 17:37:35 +0000 | [diff] [blame] | 48 | Result.addOuterTemplateArguments(&Spec->getTemplateInstantiationArgs()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 49 | } |
| 50 | |
Douglas Gregor | d110243 | 2009-08-28 17:37:35 +0000 | [diff] [blame] | 51 | // Add template arguments from a function template specialization. |
John McCall | f181d8a | 2009-08-29 03:16:09 +0000 | [diff] [blame] | 52 | else if (FunctionDecl *Function = dyn_cast<FunctionDecl>(Ctx)) { |
Douglas Gregor | d110243 | 2009-08-28 17:37:35 +0000 | [diff] [blame] | 53 | // FIXME: Check whether this is an explicit specialization. |
| 54 | if (const TemplateArgumentList *TemplateArgs |
| 55 | = Function->getTemplateSpecializationArgs()) |
| 56 | Result.addOuterTemplateArguments(TemplateArgs); |
John McCall | f181d8a | 2009-08-29 03:16:09 +0000 | [diff] [blame] | 57 | |
| 58 | // If this is a friend declaration and it declares an entity at |
| 59 | // namespace scope, take arguments from its lexical parent |
| 60 | // instead of its semantic parent. |
| 61 | if (Function->getFriendObjectKind() && |
| 62 | Function->getDeclContext()->isFileContext()) { |
| 63 | Ctx = Function->getLexicalDeclContext(); |
| 64 | continue; |
| 65 | } |
Douglas Gregor | d110243 | 2009-08-28 17:37:35 +0000 | [diff] [blame] | 66 | } |
John McCall | f181d8a | 2009-08-29 03:16:09 +0000 | [diff] [blame] | 67 | |
| 68 | Ctx = Ctx->getParent(); |
Douglas Gregor | 54dabfc | 2009-05-14 23:26:13 +0000 | [diff] [blame] | 69 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 70 | |
Douglas Gregor | d110243 | 2009-08-28 17:37:35 +0000 | [diff] [blame] | 71 | return Result; |
Douglas Gregor | 54dabfc | 2009-05-14 23:26:13 +0000 | [diff] [blame] | 72 | } |
| 73 | |
Douglas Gregor | 26dce44 | 2009-03-10 00:06:19 +0000 | [diff] [blame] | 74 | Sema::InstantiatingTemplate:: |
| 75 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
Douglas Gregor | f3e7ce4 | 2009-05-18 17:01:57 +0000 | [diff] [blame] | 76 | Decl *Entity, |
Douglas Gregor | 26dce44 | 2009-03-10 00:06:19 +0000 | [diff] [blame] | 77 | SourceRange InstantiationRange) |
| 78 | : SemaRef(SemaRef) { |
Douglas Gregor | df667e7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 79 | |
| 80 | Invalid = CheckInstantiationDepth(PointOfInstantiation, |
| 81 | InstantiationRange); |
| 82 | if (!Invalid) { |
Douglas Gregor | 26dce44 | 2009-03-10 00:06:19 +0000 | [diff] [blame] | 83 | ActiveTemplateInstantiation Inst; |
Douglas Gregor | df667e7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 84 | Inst.Kind = ActiveTemplateInstantiation::TemplateInstantiation; |
Douglas Gregor | 26dce44 | 2009-03-10 00:06:19 +0000 | [diff] [blame] | 85 | Inst.PointOfInstantiation = PointOfInstantiation; |
Douglas Gregor | df667e7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 86 | Inst.Entity = reinterpret_cast<uintptr_t>(Entity); |
Douglas Gregor | 313a81d | 2009-03-12 18:36:18 +0000 | [diff] [blame] | 87 | Inst.TemplateArgs = 0; |
| 88 | Inst.NumTemplateArgs = 0; |
Douglas Gregor | df667e7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 89 | Inst.InstantiationRange = InstantiationRange; |
| 90 | SemaRef.ActiveTemplateInstantiations.push_back(Inst); |
| 91 | Invalid = false; |
| 92 | } |
| 93 | } |
| 94 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 95 | Sema::InstantiatingTemplate::InstantiatingTemplate(Sema &SemaRef, |
Douglas Gregor | df667e7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 96 | SourceLocation PointOfInstantiation, |
| 97 | TemplateDecl *Template, |
| 98 | const TemplateArgument *TemplateArgs, |
| 99 | unsigned NumTemplateArgs, |
| 100 | SourceRange InstantiationRange) |
| 101 | : SemaRef(SemaRef) { |
| 102 | |
| 103 | Invalid = CheckInstantiationDepth(PointOfInstantiation, |
| 104 | InstantiationRange); |
| 105 | if (!Invalid) { |
| 106 | ActiveTemplateInstantiation Inst; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 107 | Inst.Kind |
Douglas Gregor | df667e7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 108 | = ActiveTemplateInstantiation::DefaultTemplateArgumentInstantiation; |
| 109 | Inst.PointOfInstantiation = PointOfInstantiation; |
| 110 | Inst.Entity = reinterpret_cast<uintptr_t>(Template); |
| 111 | Inst.TemplateArgs = TemplateArgs; |
| 112 | Inst.NumTemplateArgs = NumTemplateArgs; |
Douglas Gregor | 26dce44 | 2009-03-10 00:06:19 +0000 | [diff] [blame] | 113 | Inst.InstantiationRange = InstantiationRange; |
| 114 | SemaRef.ActiveTemplateInstantiations.push_back(Inst); |
| 115 | Invalid = false; |
| 116 | } |
| 117 | } |
| 118 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 119 | Sema::InstantiatingTemplate::InstantiatingTemplate(Sema &SemaRef, |
Douglas Gregor | 637a409 | 2009-06-10 23:47:09 +0000 | [diff] [blame] | 120 | SourceLocation PointOfInstantiation, |
Douglas Gregor | cca9e96 | 2009-07-01 22:01:06 +0000 | [diff] [blame] | 121 | FunctionTemplateDecl *FunctionTemplate, |
| 122 | const TemplateArgument *TemplateArgs, |
| 123 | unsigned NumTemplateArgs, |
| 124 | ActiveTemplateInstantiation::InstantiationKind Kind, |
| 125 | SourceRange InstantiationRange) |
| 126 | : SemaRef(SemaRef) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 127 | |
Douglas Gregor | cca9e96 | 2009-07-01 22:01:06 +0000 | [diff] [blame] | 128 | Invalid = CheckInstantiationDepth(PointOfInstantiation, |
| 129 | InstantiationRange); |
| 130 | if (!Invalid) { |
| 131 | ActiveTemplateInstantiation Inst; |
| 132 | Inst.Kind = Kind; |
| 133 | Inst.PointOfInstantiation = PointOfInstantiation; |
| 134 | Inst.Entity = reinterpret_cast<uintptr_t>(FunctionTemplate); |
| 135 | Inst.TemplateArgs = TemplateArgs; |
| 136 | Inst.NumTemplateArgs = NumTemplateArgs; |
| 137 | Inst.InstantiationRange = InstantiationRange; |
| 138 | SemaRef.ActiveTemplateInstantiations.push_back(Inst); |
| 139 | Invalid = false; |
| 140 | } |
| 141 | } |
| 142 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 143 | Sema::InstantiatingTemplate::InstantiatingTemplate(Sema &SemaRef, |
Douglas Gregor | cca9e96 | 2009-07-01 22:01:06 +0000 | [diff] [blame] | 144 | SourceLocation PointOfInstantiation, |
Douglas Gregor | 637a409 | 2009-06-10 23:47:09 +0000 | [diff] [blame] | 145 | ClassTemplatePartialSpecializationDecl *PartialSpec, |
| 146 | const TemplateArgument *TemplateArgs, |
| 147 | unsigned NumTemplateArgs, |
| 148 | SourceRange InstantiationRange) |
| 149 | : SemaRef(SemaRef) { |
| 150 | |
| 151 | Invalid = CheckInstantiationDepth(PointOfInstantiation, |
| 152 | InstantiationRange); |
| 153 | if (!Invalid) { |
| 154 | ActiveTemplateInstantiation Inst; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 155 | Inst.Kind |
Douglas Gregor | cca9e96 | 2009-07-01 22:01:06 +0000 | [diff] [blame] | 156 | = ActiveTemplateInstantiation::DeducedTemplateArgumentSubstitution; |
Douglas Gregor | 637a409 | 2009-06-10 23:47:09 +0000 | [diff] [blame] | 157 | Inst.PointOfInstantiation = PointOfInstantiation; |
| 158 | Inst.Entity = reinterpret_cast<uintptr_t>(PartialSpec); |
| 159 | Inst.TemplateArgs = TemplateArgs; |
| 160 | Inst.NumTemplateArgs = NumTemplateArgs; |
| 161 | Inst.InstantiationRange = InstantiationRange; |
| 162 | SemaRef.ActiveTemplateInstantiations.push_back(Inst); |
| 163 | Invalid = false; |
| 164 | } |
| 165 | } |
| 166 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 167 | Sema::InstantiatingTemplate::InstantiatingTemplate(Sema &SemaRef, |
Anders Carlsson | 25cae7f | 2009-09-05 05:14:19 +0000 | [diff] [blame] | 168 | SourceLocation PointOfInstantation, |
| 169 | ParmVarDecl *Param, |
| 170 | const TemplateArgument *TemplateArgs, |
| 171 | unsigned NumTemplateArgs, |
| 172 | SourceRange InstantiationRange) |
| 173 | : SemaRef(SemaRef) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 174 | |
Anders Carlsson | 25cae7f | 2009-09-05 05:14:19 +0000 | [diff] [blame] | 175 | Invalid = CheckInstantiationDepth(PointOfInstantation, InstantiationRange); |
| 176 | |
| 177 | if (!Invalid) { |
| 178 | ActiveTemplateInstantiation Inst; |
| 179 | Inst.Kind |
| 180 | = ActiveTemplateInstantiation::DefaultFunctionArgumentInstantiation; |
| 181 | Inst.PointOfInstantiation = PointOfInstantation; |
| 182 | Inst.Entity = reinterpret_cast<uintptr_t>(Param); |
| 183 | Inst.TemplateArgs = TemplateArgs; |
| 184 | Inst.NumTemplateArgs = NumTemplateArgs; |
| 185 | Inst.InstantiationRange = InstantiationRange; |
| 186 | SemaRef.ActiveTemplateInstantiations.push_back(Inst); |
| 187 | Invalid = false; |
| 188 | } |
| 189 | } |
| 190 | |
Douglas Gregor | f3e7ce4 | 2009-05-18 17:01:57 +0000 | [diff] [blame] | 191 | void Sema::InstantiatingTemplate::Clear() { |
| 192 | if (!Invalid) { |
Douglas Gregor | 26dce44 | 2009-03-10 00:06:19 +0000 | [diff] [blame] | 193 | SemaRef.ActiveTemplateInstantiations.pop_back(); |
Douglas Gregor | f3e7ce4 | 2009-05-18 17:01:57 +0000 | [diff] [blame] | 194 | Invalid = true; |
| 195 | } |
Douglas Gregor | 26dce44 | 2009-03-10 00:06:19 +0000 | [diff] [blame] | 196 | } |
| 197 | |
Douglas Gregor | df667e7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 198 | bool Sema::InstantiatingTemplate::CheckInstantiationDepth( |
| 199 | SourceLocation PointOfInstantiation, |
| 200 | SourceRange InstantiationRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 201 | if (SemaRef.ActiveTemplateInstantiations.size() |
Douglas Gregor | df667e7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 202 | <= SemaRef.getLangOptions().InstantiationDepth) |
| 203 | return false; |
| 204 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 205 | SemaRef.Diag(PointOfInstantiation, |
Douglas Gregor | df667e7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 206 | diag::err_template_recursion_depth_exceeded) |
| 207 | << SemaRef.getLangOptions().InstantiationDepth |
| 208 | << InstantiationRange; |
| 209 | SemaRef.Diag(PointOfInstantiation, diag::note_template_recursion_depth) |
| 210 | << SemaRef.getLangOptions().InstantiationDepth; |
| 211 | return true; |
| 212 | } |
| 213 | |
Douglas Gregor | ee1828a | 2009-03-10 18:03:33 +0000 | [diff] [blame] | 214 | /// \brief Prints the current instantiation stack through a series of |
| 215 | /// notes. |
| 216 | void Sema::PrintInstantiationStack() { |
Douglas Gregor | cca9e96 | 2009-07-01 22:01:06 +0000 | [diff] [blame] | 217 | // FIXME: In all of these cases, we need to show the template arguments |
Douglas Gregor | ee1828a | 2009-03-10 18:03:33 +0000 | [diff] [blame] | 218 | for (llvm::SmallVector<ActiveTemplateInstantiation, 16>::reverse_iterator |
| 219 | Active = ActiveTemplateInstantiations.rbegin(), |
| 220 | ActiveEnd = ActiveTemplateInstantiations.rend(); |
| 221 | Active != ActiveEnd; |
| 222 | ++Active) { |
Douglas Gregor | df667e7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 223 | switch (Active->Kind) { |
| 224 | case ActiveTemplateInstantiation::TemplateInstantiation: { |
Douglas Gregor | f3e7ce4 | 2009-05-18 17:01:57 +0000 | [diff] [blame] | 225 | Decl *D = reinterpret_cast<Decl *>(Active->Entity); |
| 226 | if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(D)) { |
| 227 | unsigned DiagID = diag::note_template_member_class_here; |
| 228 | if (isa<ClassTemplateSpecializationDecl>(Record)) |
| 229 | DiagID = diag::note_template_class_instantiation_here; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 230 | Diags.Report(FullSourceLoc(Active->PointOfInstantiation, SourceMgr), |
Douglas Gregor | f3e7ce4 | 2009-05-18 17:01:57 +0000 | [diff] [blame] | 231 | DiagID) |
| 232 | << Context.getTypeDeclType(Record) |
| 233 | << Active->InstantiationRange; |
Douglas Gregor | 7caa682 | 2009-07-24 20:34:43 +0000 | [diff] [blame] | 234 | } else if (FunctionDecl *Function = dyn_cast<FunctionDecl>(D)) { |
Douglas Gregor | 1637be7 | 2009-06-26 00:10:03 +0000 | [diff] [blame] | 235 | unsigned DiagID; |
| 236 | if (Function->getPrimaryTemplate()) |
| 237 | DiagID = diag::note_function_template_spec_here; |
| 238 | else |
| 239 | DiagID = diag::note_template_member_function_here; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 240 | Diags.Report(FullSourceLoc(Active->PointOfInstantiation, SourceMgr), |
Douglas Gregor | f3e7ce4 | 2009-05-18 17:01:57 +0000 | [diff] [blame] | 241 | DiagID) |
| 242 | << Function |
| 243 | << Active->InstantiationRange; |
Douglas Gregor | 7caa682 | 2009-07-24 20:34:43 +0000 | [diff] [blame] | 244 | } else { |
| 245 | Diags.Report(FullSourceLoc(Active->PointOfInstantiation, SourceMgr), |
| 246 | diag::note_template_static_data_member_def_here) |
| 247 | << cast<VarDecl>(D) |
| 248 | << Active->InstantiationRange; |
Douglas Gregor | f3e7ce4 | 2009-05-18 17:01:57 +0000 | [diff] [blame] | 249 | } |
Douglas Gregor | df667e7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 250 | break; |
| 251 | } |
| 252 | |
| 253 | case ActiveTemplateInstantiation::DefaultTemplateArgumentInstantiation: { |
| 254 | TemplateDecl *Template = cast<TemplateDecl>((Decl *)Active->Entity); |
| 255 | std::string TemplateArgsStr |
Douglas Gregor | 7532dc6 | 2009-03-30 22:58:21 +0000 | [diff] [blame] | 256 | = TemplateSpecializationType::PrintTemplateArgumentList( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 257 | Active->TemplateArgs, |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 258 | Active->NumTemplateArgs, |
| 259 | Context.PrintingPolicy); |
Douglas Gregor | df667e7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 260 | Diags.Report(FullSourceLoc(Active->PointOfInstantiation, SourceMgr), |
| 261 | diag::note_default_arg_instantiation_here) |
| 262 | << (Template->getNameAsString() + TemplateArgsStr) |
| 263 | << Active->InstantiationRange; |
| 264 | break; |
| 265 | } |
Douglas Gregor | 637a409 | 2009-06-10 23:47:09 +0000 | [diff] [blame] | 266 | |
Douglas Gregor | cca9e96 | 2009-07-01 22:01:06 +0000 | [diff] [blame] | 267 | case ActiveTemplateInstantiation::ExplicitTemplateArgumentSubstitution: { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 268 | FunctionTemplateDecl *FnTmpl |
Douglas Gregor | cca9e96 | 2009-07-01 22:01:06 +0000 | [diff] [blame] | 269 | = cast<FunctionTemplateDecl>((Decl *)Active->Entity); |
Douglas Gregor | 637a409 | 2009-06-10 23:47:09 +0000 | [diff] [blame] | 270 | Diags.Report(FullSourceLoc(Active->PointOfInstantiation, SourceMgr), |
Douglas Gregor | cca9e96 | 2009-07-01 22:01:06 +0000 | [diff] [blame] | 271 | diag::note_explicit_template_arg_substitution_here) |
| 272 | << FnTmpl << Active->InstantiationRange; |
Douglas Gregor | 637a409 | 2009-06-10 23:47:09 +0000 | [diff] [blame] | 273 | break; |
| 274 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 275 | |
Douglas Gregor | cca9e96 | 2009-07-01 22:01:06 +0000 | [diff] [blame] | 276 | case ActiveTemplateInstantiation::DeducedTemplateArgumentSubstitution: |
| 277 | if (ClassTemplatePartialSpecializationDecl *PartialSpec |
| 278 | = dyn_cast<ClassTemplatePartialSpecializationDecl>( |
| 279 | (Decl *)Active->Entity)) { |
| 280 | Diags.Report(FullSourceLoc(Active->PointOfInstantiation, SourceMgr), |
| 281 | diag::note_partial_spec_deduct_instantiation_here) |
| 282 | << Context.getTypeDeclType(PartialSpec) |
| 283 | << Active->InstantiationRange; |
| 284 | } else { |
| 285 | FunctionTemplateDecl *FnTmpl |
| 286 | = cast<FunctionTemplateDecl>((Decl *)Active->Entity); |
| 287 | Diags.Report(FullSourceLoc(Active->PointOfInstantiation, SourceMgr), |
| 288 | diag::note_function_template_deduction_instantiation_here) |
| 289 | << FnTmpl << Active->InstantiationRange; |
| 290 | } |
| 291 | break; |
Douglas Gregor | 637a409 | 2009-06-10 23:47:09 +0000 | [diff] [blame] | 292 | |
Anders Carlsson | 25cae7f | 2009-09-05 05:14:19 +0000 | [diff] [blame] | 293 | case ActiveTemplateInstantiation::DefaultFunctionArgumentInstantiation: { |
| 294 | ParmVarDecl *Param = cast<ParmVarDecl>((Decl *)Active->Entity); |
| 295 | FunctionDecl *FD = cast<FunctionDecl>(Param->getDeclContext()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 296 | |
Anders Carlsson | 25cae7f | 2009-09-05 05:14:19 +0000 | [diff] [blame] | 297 | std::string TemplateArgsStr |
| 298 | = TemplateSpecializationType::PrintTemplateArgumentList( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 299 | Active->TemplateArgs, |
Anders Carlsson | 25cae7f | 2009-09-05 05:14:19 +0000 | [diff] [blame] | 300 | Active->NumTemplateArgs, |
| 301 | Context.PrintingPolicy); |
| 302 | Diags.Report(FullSourceLoc(Active->PointOfInstantiation, SourceMgr), |
| 303 | diag::note_default_function_arg_instantiation_here) |
Anders Carlsson | 6bc107b | 2009-09-05 05:38:54 +0000 | [diff] [blame] | 304 | << (FD->getNameAsString() + TemplateArgsStr) |
Anders Carlsson | 25cae7f | 2009-09-05 05:14:19 +0000 | [diff] [blame] | 305 | << Active->InstantiationRange; |
| 306 | break; |
| 307 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 308 | |
Douglas Gregor | df667e7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 309 | } |
Douglas Gregor | ee1828a | 2009-03-10 18:03:33 +0000 | [diff] [blame] | 310 | } |
| 311 | } |
| 312 | |
Douglas Gregor | 5e9f35c | 2009-06-14 07:33:30 +0000 | [diff] [blame] | 313 | bool Sema::isSFINAEContext() const { |
| 314 | using llvm::SmallVector; |
| 315 | for (SmallVector<ActiveTemplateInstantiation, 16>::const_reverse_iterator |
| 316 | Active = ActiveTemplateInstantiations.rbegin(), |
| 317 | ActiveEnd = ActiveTemplateInstantiations.rend(); |
| 318 | Active != ActiveEnd; |
| 319 | ++Active) { |
| 320 | |
| 321 | switch(Active->Kind) { |
Douglas Gregor | cca9e96 | 2009-07-01 22:01:06 +0000 | [diff] [blame] | 322 | case ActiveTemplateInstantiation::TemplateInstantiation: |
Anders Carlsson | 25cae7f | 2009-09-05 05:14:19 +0000 | [diff] [blame] | 323 | case ActiveTemplateInstantiation::DefaultFunctionArgumentInstantiation: |
| 324 | |
Douglas Gregor | cca9e96 | 2009-07-01 22:01:06 +0000 | [diff] [blame] | 325 | // This is a template instantiation, so there is no SFINAE. |
| 326 | return false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 327 | |
Douglas Gregor | 5e9f35c | 2009-06-14 07:33:30 +0000 | [diff] [blame] | 328 | case ActiveTemplateInstantiation::DefaultTemplateArgumentInstantiation: |
| 329 | // A default template argument instantiation may or may not be a |
| 330 | // SFINAE context; look further up the stack. |
| 331 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 332 | |
Douglas Gregor | cca9e96 | 2009-07-01 22:01:06 +0000 | [diff] [blame] | 333 | case ActiveTemplateInstantiation::ExplicitTemplateArgumentSubstitution: |
| 334 | case ActiveTemplateInstantiation::DeducedTemplateArgumentSubstitution: |
| 335 | // We're either substitution explicitly-specified template arguments |
| 336 | // or deduced template arguments, so SFINAE applies. |
| 337 | return true; |
Douglas Gregor | 5e9f35c | 2009-06-14 07:33:30 +0000 | [diff] [blame] | 338 | } |
| 339 | } |
| 340 | |
| 341 | return false; |
| 342 | } |
| 343 | |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 344 | //===----------------------------------------------------------------------===/ |
| 345 | // Template Instantiation for Types |
| 346 | //===----------------------------------------------------------------------===/ |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 347 | namespace { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 348 | class VISIBILITY_HIDDEN TemplateInstantiator |
| 349 | : public TreeTransform<TemplateInstantiator> { |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 350 | const MultiLevelTemplateArgumentList &TemplateArgs; |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 351 | SourceLocation Loc; |
| 352 | DeclarationName Entity; |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 353 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 354 | public: |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 355 | typedef TreeTransform<TemplateInstantiator> inherited; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 356 | |
| 357 | TemplateInstantiator(Sema &SemaRef, |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 358 | const MultiLevelTemplateArgumentList &TemplateArgs, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 359 | SourceLocation Loc, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 360 | DeclarationName Entity) |
| 361 | : inherited(SemaRef), TemplateArgs(TemplateArgs), Loc(Loc), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 362 | Entity(Entity) { } |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 363 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 364 | /// \brief Determine whether the given type \p T has already been |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 365 | /// transformed. |
| 366 | /// |
| 367 | /// For the purposes of template instantiation, a type has already been |
| 368 | /// transformed if it is NULL or if it is not dependent. |
| 369 | bool AlreadyTransformed(QualType T) { |
| 370 | return T.isNull() || !T->isDependentType(); |
Douglas Gregor | ff66803 | 2009-05-13 18:28:20 +0000 | [diff] [blame] | 371 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 372 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 373 | /// \brief Returns the location of the entity being instantiated, if known. |
| 374 | SourceLocation getBaseLocation() { return Loc; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 375 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 376 | /// \brief Returns the name of the entity being instantiated, if any. |
| 377 | DeclarationName getBaseEntity() { return Entity; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 378 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 379 | /// \brief Transform the given declaration by instantiating a reference to |
| 380 | /// this declaration. |
| 381 | Decl *TransformDecl(Decl *D); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 382 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 383 | /// \brief Transform the definition of the given declaration by |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 384 | /// instantiating it. |
| 385 | Decl *TransformDefinition(Decl *D); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 386 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 387 | /// \brief Rebuild the exception declaration and register the declaration |
| 388 | /// as an instantiated local. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 389 | VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 390 | DeclaratorInfo *Declarator, |
| 391 | IdentifierInfo *Name, |
| 392 | SourceLocation Loc, SourceRange TypeRange); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 393 | |
John McCall | c4e7019 | 2009-09-11 04:59:25 +0000 | [diff] [blame] | 394 | /// \brief Check for tag mismatches when instantiating an |
| 395 | /// elaborated type. |
| 396 | QualType RebuildElaboratedType(QualType T, ElaboratedType::TagKind Tag); |
| 397 | |
Anders Carlsson | 773f397 | 2009-09-11 01:22:35 +0000 | [diff] [blame] | 398 | Sema::OwningExprResult TransformPredefinedExpr(PredefinedExpr *E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 399 | Sema::OwningExprResult TransformDeclRefExpr(DeclRefExpr *E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 400 | |
| 401 | /// \brief Transforms a template type parameter type by performing |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 402 | /// substitution of the corresponding template type argument. |
| 403 | QualType TransformTemplateTypeParmType(const TemplateTypeParmType *T); |
| 404 | }; |
Douglas Gregor | 7e7eb3d | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 405 | } |
| 406 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 407 | Decl *TemplateInstantiator::TransformDecl(Decl *D) { |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 408 | if (!D) |
| 409 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 410 | |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 411 | if (TemplateTemplateParmDecl *TTP = dyn_cast<TemplateTemplateParmDecl>(D)) { |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 412 | if (TTP->getDepth() < TemplateArgs.getNumLevels()) { |
| 413 | assert(TemplateArgs(TTP->getDepth(), TTP->getPosition()).getAsDecl() && |
| 414 | "Wrong kind of template template argument"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 415 | return cast<TemplateDecl>(TemplateArgs(TTP->getDepth(), |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 416 | TTP->getPosition()).getAsDecl()); |
| 417 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 418 | |
| 419 | // If the corresponding template argument is NULL or non-existent, it's |
| 420 | // because we are performing instantiation from explicitly-specified |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 421 | // template arguments in a function template, but there were some |
| 422 | // arguments left unspecified. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 423 | if (!TemplateArgs.hasTemplateArgument(TTP->getDepth(), |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 424 | TTP->getPosition())) |
| 425 | return D; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 426 | |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 427 | // FIXME: Implement depth reduction of template template parameters |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 428 | assert(false && |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 429 | "Reducing depth of template template parameters is not yet implemented"); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 430 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 431 | |
Douglas Gregor | e95b409 | 2009-09-16 18:34:49 +0000 | [diff] [blame] | 432 | return SemaRef.FindInstantiatedDecl(cast<NamedDecl>(D), TemplateArgs); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 433 | } |
| 434 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 435 | Decl *TemplateInstantiator::TransformDefinition(Decl *D) { |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 436 | Decl *Inst = getSema().SubstDecl(D, getSema().CurContext, TemplateArgs); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 437 | if (!Inst) |
| 438 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 439 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 440 | getSema().CurrentInstantiationScope->InstantiatedLocal(D, Inst); |
| 441 | return Inst; |
| 442 | } |
| 443 | |
| 444 | VarDecl * |
| 445 | TemplateInstantiator::RebuildExceptionDecl(VarDecl *ExceptionDecl, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 446 | QualType T, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 447 | DeclaratorInfo *Declarator, |
| 448 | IdentifierInfo *Name, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 449 | SourceLocation Loc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 450 | SourceRange TypeRange) { |
| 451 | VarDecl *Var = inherited::RebuildExceptionDecl(ExceptionDecl, T, Declarator, |
| 452 | Name, Loc, TypeRange); |
| 453 | if (Var && !Var->isInvalidDecl()) |
| 454 | getSema().CurrentInstantiationScope->InstantiatedLocal(ExceptionDecl, Var); |
| 455 | return Var; |
| 456 | } |
| 457 | |
John McCall | c4e7019 | 2009-09-11 04:59:25 +0000 | [diff] [blame] | 458 | QualType |
| 459 | TemplateInstantiator::RebuildElaboratedType(QualType T, |
| 460 | ElaboratedType::TagKind Tag) { |
| 461 | if (const TagType *TT = T->getAs<TagType>()) { |
| 462 | TagDecl* TD = TT->getDecl(); |
| 463 | |
| 464 | // FIXME: this location is very wrong; we really need typelocs. |
| 465 | SourceLocation TagLocation = TD->getTagKeywordLoc(); |
| 466 | |
| 467 | // FIXME: type might be anonymous. |
| 468 | IdentifierInfo *Id = TD->getIdentifier(); |
| 469 | |
| 470 | // TODO: should we even warn on struct/class mismatches for this? Seems |
| 471 | // like it's likely to produce a lot of spurious errors. |
| 472 | if (!SemaRef.isAcceptableTagRedeclaration(TD, Tag, TagLocation, *Id)) { |
| 473 | SemaRef.Diag(TagLocation, diag::err_use_with_wrong_tag) |
| 474 | << Id |
| 475 | << CodeModificationHint::CreateReplacement(SourceRange(TagLocation), |
| 476 | TD->getKindName()); |
| 477 | SemaRef.Diag(TD->getLocation(), diag::note_previous_use); |
| 478 | } |
| 479 | } |
| 480 | |
| 481 | return TreeTransform<TemplateInstantiator>::RebuildElaboratedType(T, Tag); |
| 482 | } |
| 483 | |
| 484 | Sema::OwningExprResult |
Anders Carlsson | 773f397 | 2009-09-11 01:22:35 +0000 | [diff] [blame] | 485 | TemplateInstantiator::TransformPredefinedExpr(PredefinedExpr *E) { |
| 486 | if (!E->isTypeDependent()) |
| 487 | return SemaRef.Owned(E->Retain()); |
| 488 | |
| 489 | FunctionDecl *currentDecl = getSema().getCurFunctionDecl(); |
| 490 | assert(currentDecl && "Must have current function declaration when " |
| 491 | "instantiating."); |
| 492 | |
| 493 | PredefinedExpr::IdentType IT = E->getIdentType(); |
| 494 | |
| 495 | unsigned Length = |
| 496 | PredefinedExpr::ComputeName(getSema().Context, IT, currentDecl).length(); |
| 497 | |
| 498 | llvm::APInt LengthI(32, Length + 1); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 499 | QualType ResTy = getSema().Context.CharTy.withConst(); |
Anders Carlsson | 773f397 | 2009-09-11 01:22:35 +0000 | [diff] [blame] | 500 | ResTy = getSema().Context.getConstantArrayType(ResTy, LengthI, |
| 501 | ArrayType::Normal, 0); |
| 502 | PredefinedExpr *PE = |
| 503 | new (getSema().Context) PredefinedExpr(E->getLocation(), ResTy, IT); |
| 504 | return getSema().Owned(PE); |
| 505 | } |
| 506 | |
| 507 | Sema::OwningExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 508 | TemplateInstantiator::TransformDeclRefExpr(DeclRefExpr *E) { |
| 509 | // FIXME: Clean this up a bit |
| 510 | NamedDecl *D = E->getDecl(); |
| 511 | if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(D)) { |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 512 | if (NTTP->getDepth() >= TemplateArgs.getNumLevels()) { |
| 513 | assert(false && "Cannot reduce non-type template parameter depth yet"); |
| 514 | return getSema().ExprError(); |
| 515 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 516 | |
| 517 | // If the corresponding template argument is NULL or non-existent, it's |
| 518 | // because we are performing instantiation from explicitly-specified |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 519 | // template arguments in a function template, but there were some |
| 520 | // arguments left unspecified. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 521 | if (!TemplateArgs.hasTemplateArgument(NTTP->getDepth(), |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 522 | NTTP->getPosition())) |
| 523 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 524 | |
| 525 | const TemplateArgument &Arg = TemplateArgs(NTTP->getDepth(), |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 526 | NTTP->getPosition()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 527 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 528 | // The template argument itself might be an expression, in which |
| 529 | // case we just return that expression. |
| 530 | if (Arg.getKind() == TemplateArgument::Expression) |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 531 | return SemaRef.Owned(Arg.getAsExpr()->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 532 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 533 | if (Arg.getKind() == TemplateArgument::Declaration) { |
| 534 | ValueDecl *VD = cast<ValueDecl>(Arg.getAsDecl()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 535 | |
Douglas Gregor | e95b409 | 2009-09-16 18:34:49 +0000 | [diff] [blame] | 536 | VD = cast_or_null<ValueDecl>( |
| 537 | getSema().FindInstantiatedDecl(VD, TemplateArgs)); |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 538 | if (!VD) |
| 539 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 540 | |
| 541 | return SemaRef.BuildDeclRefExpr(VD, VD->getType(), E->getLocation(), |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 542 | /*FIXME:*/false, /*FIXME:*/false); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 543 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 544 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 545 | assert(Arg.getKind() == TemplateArgument::Integral); |
| 546 | QualType T = Arg.getIntegralType(); |
| 547 | if (T->isCharType() || T->isWideCharType()) |
| 548 | return SemaRef.Owned(new (SemaRef.Context) CharacterLiteral( |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 549 | Arg.getAsIntegral()->getZExtValue(), |
| 550 | T->isWideCharType(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 551 | T, |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 552 | E->getSourceRange().getBegin())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 553 | if (T->isBooleanType()) |
| 554 | return SemaRef.Owned(new (SemaRef.Context) CXXBoolLiteralExpr( |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 555 | Arg.getAsIntegral()->getBoolValue(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 556 | T, |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 557 | E->getSourceRange().getBegin())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 558 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 559 | assert(Arg.getAsIntegral()->getBitWidth() == SemaRef.Context.getIntWidth(T)); |
| 560 | return SemaRef.Owned(new (SemaRef.Context) IntegerLiteral( |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 561 | *Arg.getAsIntegral(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 562 | T, |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 563 | E->getSourceRange().getBegin())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 564 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 565 | |
Douglas Gregor | e95b409 | 2009-09-16 18:34:49 +0000 | [diff] [blame] | 566 | NamedDecl *InstD = SemaRef.FindInstantiatedDecl(D, TemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 567 | if (!InstD) |
| 568 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 569 | |
Anders Carlsson | 0d8df78 | 2009-08-29 19:37:28 +0000 | [diff] [blame] | 570 | // If we instantiated an UnresolvedUsingDecl and got back an UsingDecl, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 571 | // we need to get the underlying decl. |
Anders Carlsson | 0d8df78 | 2009-08-29 19:37:28 +0000 | [diff] [blame] | 572 | // FIXME: Is this correct? Maybe FindInstantiatedDecl should do this? |
| 573 | InstD = InstD->getUnderlyingDecl(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 574 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 575 | // FIXME: nested-name-specifier for QualifiedDeclRefExpr |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 576 | return SemaRef.BuildDeclarationNameExpr(E->getLocation(), InstD, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 577 | /*FIXME:*/false, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 578 | /*FIXME:*/0, |
| 579 | /*FIXME:*/false); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 580 | } |
| 581 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 582 | QualType |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 583 | TemplateInstantiator::TransformTemplateTypeParmType( |
| 584 | const TemplateTypeParmType *T) { |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 585 | if (T->getDepth() < TemplateArgs.getNumLevels()) { |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 586 | // Replace the template type parameter with its corresponding |
| 587 | // template argument. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 588 | |
| 589 | // If the corresponding template argument is NULL or doesn't exist, it's |
| 590 | // because we are performing instantiation from explicitly-specified |
| 591 | // template arguments in a function template class, but there were some |
Douglas Gregor | 16134c6 | 2009-07-01 00:28:38 +0000 | [diff] [blame] | 592 | // arguments left unspecified. |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 593 | if (!TemplateArgs.hasTemplateArgument(T->getDepth(), T->getIndex())) |
| 594 | return QualType(T, 0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 595 | |
| 596 | assert(TemplateArgs(T->getDepth(), T->getIndex()).getKind() |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 597 | == TemplateArgument::Type && |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 598 | "Template argument kind mismatch"); |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 599 | |
| 600 | return TemplateArgs(T->getDepth(), T->getIndex()).getAsType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 601 | } |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 602 | |
| 603 | // The template type parameter comes from an inner template (e.g., |
| 604 | // the template parameter list of a member template inside the |
| 605 | // template we are instantiating). Create a new template type |
| 606 | // parameter with the template "level" reduced by one. |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 607 | return getSema().Context.getTemplateTypeParmType( |
| 608 | T->getDepth() - TemplateArgs.getNumLevels(), |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 609 | T->getIndex(), |
| 610 | T->isParameterPack(), |
| 611 | T->getName()); |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 612 | } |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 613 | |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 614 | /// \brief Perform substitution on the type T with a given set of template |
| 615 | /// arguments. |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 616 | /// |
| 617 | /// This routine substitutes the given template arguments into the |
| 618 | /// type T and produces the instantiated type. |
| 619 | /// |
| 620 | /// \param T the type into which the template arguments will be |
| 621 | /// substituted. If this type is not dependent, it will be returned |
| 622 | /// immediately. |
| 623 | /// |
| 624 | /// \param TemplateArgs the template arguments that will be |
| 625 | /// substituted for the top-level template parameters within T. |
| 626 | /// |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 627 | /// \param Loc the location in the source code where this substitution |
| 628 | /// is being performed. It will typically be the location of the |
| 629 | /// declarator (if we're instantiating the type of some declaration) |
| 630 | /// or the location of the type in the source code (if, e.g., we're |
| 631 | /// instantiating the type of a cast expression). |
| 632 | /// |
| 633 | /// \param Entity the name of the entity associated with a declaration |
| 634 | /// being instantiated (if any). May be empty to indicate that there |
| 635 | /// is no such entity (if, e.g., this is a type that occurs as part of |
| 636 | /// a cast expression) or that the entity has no name (e.g., an |
| 637 | /// unnamed function parameter). |
| 638 | /// |
| 639 | /// \returns If the instantiation succeeds, the instantiated |
| 640 | /// type. Otherwise, produces diagnostics and returns a NULL type. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 641 | QualType Sema::SubstType(QualType T, |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 642 | const MultiLevelTemplateArgumentList &TemplateArgs, |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 643 | SourceLocation Loc, DeclarationName Entity) { |
Douglas Gregor | df667e7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 644 | assert(!ActiveTemplateInstantiations.empty() && |
| 645 | "Cannot perform an instantiation without some context on the " |
| 646 | "instantiation stack"); |
| 647 | |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 648 | // If T is not a dependent type, there is nothing to do. |
| 649 | if (!T->isDependentType()) |
| 650 | return T; |
| 651 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 652 | TemplateInstantiator Instantiator(*this, TemplateArgs, Loc, Entity); |
| 653 | return Instantiator.TransformType(T); |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 654 | } |
Douglas Gregor | 2943aed | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 655 | |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 656 | /// \brief Perform substitution on the base class specifiers of the |
| 657 | /// given class template specialization. |
Douglas Gregor | 2943aed | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 658 | /// |
| 659 | /// Produces a diagnostic and returns true on error, returns false and |
| 660 | /// attaches the instantiated base classes to the class template |
| 661 | /// specialization if successful. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 662 | bool |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 663 | Sema::SubstBaseSpecifiers(CXXRecordDecl *Instantiation, |
| 664 | CXXRecordDecl *Pattern, |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 665 | const MultiLevelTemplateArgumentList &TemplateArgs) { |
Douglas Gregor | 2943aed | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 666 | bool Invalid = false; |
Douglas Gregor | 0ca20ac | 2009-05-29 18:27:38 +0000 | [diff] [blame] | 667 | llvm::SmallVector<CXXBaseSpecifier*, 4> InstantiatedBases; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 668 | for (ClassTemplateSpecializationDecl::base_class_iterator |
Douglas Gregor | d475b8d | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 669 | Base = Pattern->bases_begin(), BaseEnd = Pattern->bases_end(); |
Douglas Gregor | 27b152f | 2009-03-10 18:52:44 +0000 | [diff] [blame] | 670 | Base != BaseEnd; ++Base) { |
Douglas Gregor | 2943aed | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 671 | if (!Base->getType()->isDependentType()) { |
Fariborz Jahanian | 71c6e71 | 2009-07-22 17:41:53 +0000 | [diff] [blame] | 672 | InstantiatedBases.push_back(new (Context) CXXBaseSpecifier(*Base)); |
Douglas Gregor | 2943aed | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 673 | continue; |
| 674 | } |
| 675 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 676 | QualType BaseType = SubstType(Base->getType(), |
| 677 | TemplateArgs, |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 678 | Base->getSourceRange().getBegin(), |
| 679 | DeclarationName()); |
Douglas Gregor | 2943aed | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 680 | if (BaseType.isNull()) { |
| 681 | Invalid = true; |
| 682 | continue; |
| 683 | } |
| 684 | |
| 685 | if (CXXBaseSpecifier *InstantiatedBase |
Douglas Gregor | d475b8d | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 686 | = CheckBaseSpecifier(Instantiation, |
Douglas Gregor | 2943aed | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 687 | Base->getSourceRange(), |
| 688 | Base->isVirtual(), |
| 689 | Base->getAccessSpecifierAsWritten(), |
| 690 | BaseType, |
| 691 | /*FIXME: Not totally accurate */ |
| 692 | Base->getSourceRange().getBegin())) |
| 693 | InstantiatedBases.push_back(InstantiatedBase); |
| 694 | else |
| 695 | Invalid = true; |
| 696 | } |
| 697 | |
Douglas Gregor | 27b152f | 2009-03-10 18:52:44 +0000 | [diff] [blame] | 698 | if (!Invalid && |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 699 | AttachBaseSpecifiers(Instantiation, InstantiatedBases.data(), |
Douglas Gregor | 2943aed | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 700 | InstantiatedBases.size())) |
| 701 | Invalid = true; |
| 702 | |
| 703 | return Invalid; |
| 704 | } |
| 705 | |
Douglas Gregor | d475b8d | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 706 | /// \brief Instantiate the definition of a class from a given pattern. |
| 707 | /// |
| 708 | /// \param PointOfInstantiation The point of instantiation within the |
| 709 | /// source code. |
| 710 | /// |
| 711 | /// \param Instantiation is the declaration whose definition is being |
| 712 | /// instantiated. This will be either a class template specialization |
| 713 | /// or a member class of a class template specialization. |
| 714 | /// |
| 715 | /// \param Pattern is the pattern from which the instantiation |
| 716 | /// occurs. This will be either the declaration of a class template or |
| 717 | /// the declaration of a member class of a class template. |
| 718 | /// |
| 719 | /// \param TemplateArgs The template arguments to be substituted into |
| 720 | /// the pattern. |
| 721 | /// |
Douglas Gregor | d0e3daf | 2009-09-04 22:48:11 +0000 | [diff] [blame] | 722 | /// \param TSK the kind of implicit or explicit instantiation to perform. |
Douglas Gregor | 5842ba9 | 2009-08-24 15:23:48 +0000 | [diff] [blame] | 723 | /// |
| 724 | /// \param Complain whether to complain if the class cannot be instantiated due |
| 725 | /// to the lack of a definition. |
| 726 | /// |
Douglas Gregor | d475b8d | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 727 | /// \returns true if an error occurred, false otherwise. |
| 728 | bool |
| 729 | Sema::InstantiateClass(SourceLocation PointOfInstantiation, |
| 730 | CXXRecordDecl *Instantiation, CXXRecordDecl *Pattern, |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 731 | const MultiLevelTemplateArgumentList &TemplateArgs, |
Douglas Gregor | d0e3daf | 2009-09-04 22:48:11 +0000 | [diff] [blame] | 732 | TemplateSpecializationKind TSK, |
Douglas Gregor | 5842ba9 | 2009-08-24 15:23:48 +0000 | [diff] [blame] | 733 | bool Complain) { |
Douglas Gregor | d475b8d | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 734 | bool Invalid = false; |
John McCall | e29ba20 | 2009-08-20 01:44:21 +0000 | [diff] [blame] | 735 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 736 | CXXRecordDecl *PatternDef |
Douglas Gregor | d475b8d | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 737 | = cast_or_null<CXXRecordDecl>(Pattern->getDefinition(Context)); |
| 738 | if (!PatternDef) { |
Douglas Gregor | 5842ba9 | 2009-08-24 15:23:48 +0000 | [diff] [blame] | 739 | if (!Complain) { |
| 740 | // Say nothing |
| 741 | } else if (Pattern == Instantiation->getInstantiatedFromMemberClass()) { |
Douglas Gregor | d475b8d | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 742 | Diag(PointOfInstantiation, |
| 743 | diag::err_implicit_instantiate_member_undefined) |
| 744 | << Context.getTypeDeclType(Instantiation); |
| 745 | Diag(Pattern->getLocation(), diag::note_member_of_template_here); |
| 746 | } else { |
Douglas Gregor | 93dfdb1 | 2009-05-13 00:25:59 +0000 | [diff] [blame] | 747 | Diag(PointOfInstantiation, diag::err_template_instantiate_undefined) |
Douglas Gregor | d0e3daf | 2009-09-04 22:48:11 +0000 | [diff] [blame] | 748 | << (TSK != TSK_ImplicitInstantiation) |
Douglas Gregor | d475b8d | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 749 | << Context.getTypeDeclType(Instantiation); |
| 750 | Diag(Pattern->getLocation(), diag::note_template_decl_here); |
| 751 | } |
| 752 | return true; |
| 753 | } |
| 754 | Pattern = PatternDef; |
| 755 | |
Douglas Gregor | d048bb7 | 2009-03-25 21:23:52 +0000 | [diff] [blame] | 756 | InstantiatingTemplate Inst(*this, PointOfInstantiation, Instantiation); |
Douglas Gregor | d475b8d | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 757 | if (Inst) |
| 758 | return true; |
| 759 | |
| 760 | // Enter the scope of this instantiation. We don't use |
| 761 | // PushDeclContext because we don't have a scope. |
| 762 | DeclContext *PreviousContext = CurContext; |
| 763 | CurContext = Instantiation; |
| 764 | |
| 765 | // Start the definition of this instantiation. |
| 766 | Instantiation->startDefinition(); |
| 767 | |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 768 | // Do substitution on the base class specifiers. |
| 769 | if (SubstBaseSpecifiers(Instantiation, Pattern, TemplateArgs)) |
Douglas Gregor | d475b8d | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 770 | Invalid = true; |
| 771 | |
Douglas Gregor | 0ca20ac | 2009-05-29 18:27:38 +0000 | [diff] [blame] | 772 | llvm::SmallVector<DeclPtrTy, 4> Fields; |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 773 | for (RecordDecl::decl_iterator Member = Pattern->decls_begin(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 774 | MemberEnd = Pattern->decls_end(); |
Douglas Gregor | 6ab3524 | 2009-04-09 21:40:53 +0000 | [diff] [blame] | 775 | Member != MemberEnd; ++Member) { |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 776 | Decl *NewMember = SubstDecl(*Member, Instantiation, TemplateArgs); |
Douglas Gregor | d475b8d | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 777 | if (NewMember) { |
| 778 | if (NewMember->isInvalidDecl()) |
| 779 | Invalid = true; |
| 780 | else if (FieldDecl *Field = dyn_cast<FieldDecl>(NewMember)) |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 781 | Fields.push_back(DeclPtrTy::make(Field)); |
Anders Carlsson | 0d8df78 | 2009-08-29 19:37:28 +0000 | [diff] [blame] | 782 | else if (UsingDecl *UD = dyn_cast<UsingDecl>(NewMember)) |
| 783 | Instantiation->addDecl(UD); |
Douglas Gregor | d475b8d | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 784 | } else { |
| 785 | // FIXME: Eventually, a NULL return will mean that one of the |
Mike Stump | 390b4cc | 2009-05-16 07:39:55 +0000 | [diff] [blame] | 786 | // instantiations was a semantic disaster, and we'll want to set Invalid = |
| 787 | // true. For now, we expect to skip some members that we can't yet handle. |
Douglas Gregor | d475b8d | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 788 | } |
| 789 | } |
| 790 | |
| 791 | // Finish checking fields. |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 792 | ActOnFields(0, Instantiation->getLocation(), DeclPtrTy::make(Instantiation), |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 793 | Fields.data(), Fields.size(), SourceLocation(), SourceLocation(), |
Douglas Gregor | d475b8d | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 794 | 0); |
| 795 | |
| 796 | // Add any implicitly-declared members that we might need. |
| 797 | AddImplicitlyDeclaredMembersToClass(Instantiation); |
| 798 | |
| 799 | // Exit the scope of this instantiation. |
| 800 | CurContext = PreviousContext; |
| 801 | |
Douglas Gregor | aba43bb | 2009-05-26 20:50:29 +0000 | [diff] [blame] | 802 | if (!Invalid) |
| 803 | Consumer.HandleTagDeclDefinition(Instantiation); |
| 804 | |
Douglas Gregor | a58861f | 2009-05-13 20:28:22 +0000 | [diff] [blame] | 805 | // If this is an explicit instantiation, instantiate our members, too. |
Douglas Gregor | d0e3daf | 2009-09-04 22:48:11 +0000 | [diff] [blame] | 806 | if (!Invalid && TSK != TSK_ImplicitInstantiation) { |
Douglas Gregor | f3e7ce4 | 2009-05-18 17:01:57 +0000 | [diff] [blame] | 807 | Inst.Clear(); |
Douglas Gregor | d0e3daf | 2009-09-04 22:48:11 +0000 | [diff] [blame] | 808 | InstantiateClassMembers(PointOfInstantiation, Instantiation, TemplateArgs, |
| 809 | TSK); |
Douglas Gregor | f3e7ce4 | 2009-05-18 17:01:57 +0000 | [diff] [blame] | 810 | } |
Douglas Gregor | a58861f | 2009-05-13 20:28:22 +0000 | [diff] [blame] | 811 | |
Douglas Gregor | d475b8d | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 812 | return Invalid; |
| 813 | } |
| 814 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 815 | bool |
Douglas Gregor | 2943aed | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 816 | Sema::InstantiateClassTemplateSpecialization( |
| 817 | ClassTemplateSpecializationDecl *ClassTemplateSpec, |
Douglas Gregor | d0e3daf | 2009-09-04 22:48:11 +0000 | [diff] [blame] | 818 | TemplateSpecializationKind TSK, |
Douglas Gregor | 5842ba9 | 2009-08-24 15:23:48 +0000 | [diff] [blame] | 819 | bool Complain) { |
Douglas Gregor | 2943aed | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 820 | // Perform the actual instantiation on the canonical declaration. |
| 821 | ClassTemplateSpec = cast<ClassTemplateSpecializationDecl>( |
Argyrios Kyrtzidis | 97fbaa2 | 2009-07-18 00:34:25 +0000 | [diff] [blame] | 822 | ClassTemplateSpec->getCanonicalDecl()); |
Douglas Gregor | 2943aed | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 823 | |
Douglas Gregor | 52604ab | 2009-09-11 21:19:12 +0000 | [diff] [blame] | 824 | // Check whether we have already instantiated or specialized this class |
| 825 | // template specialization. |
| 826 | if (ClassTemplateSpec->getSpecializationKind() != TSK_Undeclared) { |
| 827 | if (ClassTemplateSpec->getSpecializationKind() == |
| 828 | TSK_ExplicitInstantiationDeclaration && |
| 829 | TSK == TSK_ExplicitInstantiationDefinition) { |
| 830 | // An explicit instantiation definition follows an explicit instantiation |
| 831 | // declaration (C++0x [temp.explicit]p10); go ahead and perform the |
| 832 | // explicit instantiation. |
| 833 | ClassTemplateSpec->setSpecializationKind(TSK); |
| 834 | InstantiateClassTemplateSpecializationMembers( |
| 835 | /*FIXME?*/ClassTemplateSpec->getPointOfInstantiation(), |
| 836 | ClassTemplateSpec, |
| 837 | TSK); |
| 838 | return false; |
| 839 | } |
| 840 | |
| 841 | // We can only instantiate something that hasn't already been |
| 842 | // instantiated or specialized. Fail without any diagnostics: our |
| 843 | // caller will provide an error message. |
Douglas Gregor | 2943aed | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 844 | return true; |
Douglas Gregor | 52604ab | 2009-09-11 21:19:12 +0000 | [diff] [blame] | 845 | } |
Douglas Gregor | 2943aed | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 846 | |
Douglas Gregor | 9eea08b | 2009-09-15 16:51:42 +0000 | [diff] [blame] | 847 | if (ClassTemplateSpec->isInvalidDecl()) |
| 848 | return true; |
| 849 | |
Douglas Gregor | 2943aed | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 850 | ClassTemplateDecl *Template = ClassTemplateSpec->getSpecializedTemplate(); |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 851 | CXXRecordDecl *Pattern = 0; |
Douglas Gregor | c8ab256 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 852 | |
Douglas Gregor | c1efb3f | 2009-06-12 22:31:52 +0000 | [diff] [blame] | 853 | // C++ [temp.class.spec.match]p1: |
| 854 | // When a class template is used in a context that requires an |
| 855 | // instantiation of the class, it is necessary to determine |
| 856 | // whether the instantiation is to be generated using the primary |
| 857 | // template or one of the partial specializations. This is done by |
| 858 | // matching the template arguments of the class template |
| 859 | // specialization with the template argument lists of the partial |
| 860 | // specializations. |
Douglas Gregor | 199d991 | 2009-06-05 00:53:49 +0000 | [diff] [blame] | 861 | typedef std::pair<ClassTemplatePartialSpecializationDecl *, |
| 862 | TemplateArgumentList *> MatchResult; |
| 863 | llvm::SmallVector<MatchResult, 4> Matched; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 864 | for (llvm::FoldingSet<ClassTemplatePartialSpecializationDecl>::iterator |
Douglas Gregor | c8ab256 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 865 | Partial = Template->getPartialSpecializations().begin(), |
| 866 | PartialEnd = Template->getPartialSpecializations().end(); |
| 867 | Partial != PartialEnd; |
| 868 | ++Partial) { |
Douglas Gregor | f67875d | 2009-06-12 18:26:56 +0000 | [diff] [blame] | 869 | TemplateDeductionInfo Info(Context); |
| 870 | if (TemplateDeductionResult Result |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 871 | = DeduceTemplateArguments(&*Partial, |
Douglas Gregor | f67875d | 2009-06-12 18:26:56 +0000 | [diff] [blame] | 872 | ClassTemplateSpec->getTemplateArgs(), |
| 873 | Info)) { |
| 874 | // FIXME: Store the failed-deduction information for use in |
| 875 | // diagnostics, later. |
| 876 | (void)Result; |
| 877 | } else { |
| 878 | Matched.push_back(std::make_pair(&*Partial, Info.take())); |
| 879 | } |
Douglas Gregor | c8ab256 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 880 | } |
| 881 | |
| 882 | if (Matched.size() == 1) { |
Douglas Gregor | c1efb3f | 2009-06-12 22:31:52 +0000 | [diff] [blame] | 883 | // -- If exactly one matching specialization is found, the |
| 884 | // instantiation is generated from that specialization. |
Douglas Gregor | 199d991 | 2009-06-05 00:53:49 +0000 | [diff] [blame] | 885 | Pattern = Matched[0].first; |
Douglas Gregor | 37d93e9 | 2009-08-02 23:24:31 +0000 | [diff] [blame] | 886 | ClassTemplateSpec->setInstantiationOf(Matched[0].first, Matched[0].second); |
Douglas Gregor | c8ab256 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 887 | } else if (Matched.size() > 1) { |
Douglas Gregor | c1efb3f | 2009-06-12 22:31:52 +0000 | [diff] [blame] | 888 | // -- If more than one matching specialization is found, the |
| 889 | // partial order rules (14.5.4.2) are used to determine |
| 890 | // whether one of the specializations is more specialized |
| 891 | // than the others. If none of the specializations is more |
| 892 | // specialized than all of the other matching |
| 893 | // specializations, then the use of the class template is |
| 894 | // ambiguous and the program is ill-formed. |
Douglas Gregor | bf4ea56 | 2009-09-15 16:23:51 +0000 | [diff] [blame] | 895 | llvm::SmallVector<MatchResult, 4>::iterator Best = Matched.begin(); |
| 896 | for (llvm::SmallVector<MatchResult, 4>::iterator P = Best + 1, |
| 897 | PEnd = Matched.end(); |
| 898 | P != PEnd; ++P) { |
| 899 | if (getMoreSpecializedPartialSpecialization(P->first, Best->first) |
| 900 | == P->first) |
| 901 | Best = P; |
| 902 | } |
| 903 | |
| 904 | // Determine if the best partial specialization is more specialized than |
| 905 | // the others. |
| 906 | bool Ambiguous = false; |
| 907 | for (llvm::SmallVector<MatchResult, 4>::iterator P = Matched.begin(), |
| 908 | PEnd = Matched.end(); |
| 909 | P != PEnd; ++P) { |
| 910 | if (P != Best && |
| 911 | getMoreSpecializedPartialSpecialization(P->first, Best->first) |
| 912 | != Best->first) { |
| 913 | Ambiguous = true; |
| 914 | break; |
| 915 | } |
| 916 | } |
| 917 | |
| 918 | if (Ambiguous) { |
| 919 | // Partial ordering did not produce a clear winner. Complain. |
| 920 | ClassTemplateSpec->setInvalidDecl(); |
| 921 | Diag(ClassTemplateSpec->getPointOfInstantiation(), |
| 922 | diag::err_partial_spec_ordering_ambiguous) |
| 923 | << ClassTemplateSpec; |
| 924 | |
| 925 | // Print the matching partial specializations. |
| 926 | for (llvm::SmallVector<MatchResult, 4>::iterator P = Matched.begin(), |
| 927 | PEnd = Matched.end(); |
| 928 | P != PEnd; ++P) |
| 929 | Diag(P->first->getLocation(), diag::note_partial_spec_match) |
| 930 | << getTemplateArgumentBindingsText(P->first->getTemplateParameters(), |
| 931 | *P->second); |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 932 | |
Douglas Gregor | bf4ea56 | 2009-09-15 16:23:51 +0000 | [diff] [blame] | 933 | return true; |
| 934 | } |
| 935 | |
| 936 | // Instantiate using the best class template partial specialization. |
| 937 | Pattern = Best->first; |
| 938 | ClassTemplateSpec->setInstantiationOf(Best->first, Best->second); |
Douglas Gregor | c1efb3f | 2009-06-12 22:31:52 +0000 | [diff] [blame] | 939 | } else { |
| 940 | // -- If no matches are found, the instantiation is generated |
| 941 | // from the primary template. |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 942 | ClassTemplateDecl *OrigTemplate = Template; |
| 943 | while (OrigTemplate->getInstantiatedFromMemberTemplate()) |
| 944 | OrigTemplate = OrigTemplate->getInstantiatedFromMemberTemplate(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 945 | |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 946 | Pattern = OrigTemplate->getTemplatedDecl(); |
Douglas Gregor | c8ab256 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 947 | } |
Douglas Gregor | 2943aed | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 948 | |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 949 | // Note that this is an instantiation. |
Douglas Gregor | d0e3daf | 2009-09-04 22:48:11 +0000 | [diff] [blame] | 950 | ClassTemplateSpec->setSpecializationKind(TSK); |
Douglas Gregor | 2943aed | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 951 | |
John McCall | 9cc7807 | 2009-09-11 07:25:08 +0000 | [diff] [blame] | 952 | bool Result = InstantiateClass(ClassTemplateSpec->getPointOfInstantiation(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 953 | ClassTemplateSpec, Pattern, |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 954 | getTemplateInstantiationArgs(ClassTemplateSpec), |
Douglas Gregor | d0e3daf | 2009-09-04 22:48:11 +0000 | [diff] [blame] | 955 | TSK, |
Douglas Gregor | 5842ba9 | 2009-08-24 15:23:48 +0000 | [diff] [blame] | 956 | Complain); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 957 | |
Douglas Gregor | 199d991 | 2009-06-05 00:53:49 +0000 | [diff] [blame] | 958 | for (unsigned I = 0, N = Matched.size(); I != N; ++I) { |
| 959 | // FIXME: Implement TemplateArgumentList::Destroy! |
| 960 | // if (Matched[I].first != Pattern) |
| 961 | // Matched[I].second->Destroy(Context); |
| 962 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 963 | |
Douglas Gregor | 199d991 | 2009-06-05 00:53:49 +0000 | [diff] [blame] | 964 | return Result; |
Douglas Gregor | 2943aed | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 965 | } |
Douglas Gregor | 5953d8b | 2009-03-19 17:26:29 +0000 | [diff] [blame] | 966 | |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 967 | /// \brief Instantiates the definitions of all of the member |
| 968 | /// of the given class, which is an instantiation of a class template |
| 969 | /// or a member class of a template. |
Douglas Gregor | a58861f | 2009-05-13 20:28:22 +0000 | [diff] [blame] | 970 | void |
| 971 | Sema::InstantiateClassMembers(SourceLocation PointOfInstantiation, |
Douglas Gregor | d0e3daf | 2009-09-04 22:48:11 +0000 | [diff] [blame] | 972 | CXXRecordDecl *Instantiation, |
| 973 | const MultiLevelTemplateArgumentList &TemplateArgs, |
| 974 | TemplateSpecializationKind TSK) { |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 975 | for (DeclContext::decl_iterator D = Instantiation->decls_begin(), |
| 976 | DEnd = Instantiation->decls_end(); |
Douglas Gregor | a58861f | 2009-05-13 20:28:22 +0000 | [diff] [blame] | 977 | D != DEnd; ++D) { |
| 978 | if (FunctionDecl *Function = dyn_cast<FunctionDecl>(*D)) { |
Douglas Gregor | f6b1185 | 2009-10-08 15:14:33 +0000 | [diff] [blame] | 979 | if (Function->getInstantiatedFromMemberFunction()) { |
| 980 | // If this member was explicitly specialized, do nothing. |
| 981 | if (Function->getTemplateSpecializationKind() == |
| 982 | TSK_ExplicitSpecialization) |
| 983 | continue; |
| 984 | |
Douglas Gregor | 2db3232 | 2009-10-07 23:56:10 +0000 | [diff] [blame] | 985 | Function->setTemplateSpecializationKind(TSK); |
Douglas Gregor | f6b1185 | 2009-10-08 15:14:33 +0000 | [diff] [blame] | 986 | } |
| 987 | |
| 988 | if (!Function->getBody() && TSK == TSK_ExplicitInstantiationDefinition) |
Douglas Gregor | f3e7ce4 | 2009-05-18 17:01:57 +0000 | [diff] [blame] | 989 | InstantiateFunctionDefinition(PointOfInstantiation, Function); |
Douglas Gregor | a58861f | 2009-05-13 20:28:22 +0000 | [diff] [blame] | 990 | } else if (VarDecl *Var = dyn_cast<VarDecl>(*D)) { |
Douglas Gregor | 251b4ff | 2009-10-08 07:24:58 +0000 | [diff] [blame] | 991 | if (Var->isStaticDataMember()) { |
Douglas Gregor | f6b1185 | 2009-10-08 15:14:33 +0000 | [diff] [blame] | 992 | // If this member was explicitly specialized, do nothing. |
| 993 | if (Var->getTemplateSpecializationKind() == TSK_ExplicitSpecialization) |
| 994 | continue; |
| 995 | |
Douglas Gregor | 251b4ff | 2009-10-08 07:24:58 +0000 | [diff] [blame] | 996 | Var->setTemplateSpecializationKind(TSK); |
| 997 | |
Douglas Gregor | f6b1185 | 2009-10-08 15:14:33 +0000 | [diff] [blame] | 998 | if (TSK == TSK_ExplicitInstantiationDefinition) |
Douglas Gregor | 251b4ff | 2009-10-08 07:24:58 +0000 | [diff] [blame] | 999 | InstantiateStaticDataMemberDefinition(PointOfInstantiation, Var); |
| 1000 | } |
Douglas Gregor | a58861f | 2009-05-13 20:28:22 +0000 | [diff] [blame] | 1001 | } else if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(*D)) { |
Douglas Gregor | 2db3232 | 2009-10-07 23:56:10 +0000 | [diff] [blame] | 1002 | if (Record->isInjectedClassName()) |
| 1003 | continue; |
| 1004 | |
| 1005 | assert(Record->getInstantiatedFromMemberClass() && |
| 1006 | "Missing instantiated-from-template information"); |
Douglas Gregor | f6b1185 | 2009-10-08 15:14:33 +0000 | [diff] [blame] | 1007 | |
| 1008 | // If this member was explicitly specialized, do nothing. |
| 1009 | if (Record->getTemplateSpecializationKind() == TSK_ExplicitSpecialization) |
| 1010 | continue; |
| 1011 | |
Douglas Gregor | 2db3232 | 2009-10-07 23:56:10 +0000 | [diff] [blame] | 1012 | if (!Record->getDefinition(Context)) |
Douglas Gregor | f3e7ce4 | 2009-05-18 17:01:57 +0000 | [diff] [blame] | 1013 | InstantiateClass(PointOfInstantiation, Record, |
Douglas Gregor | a58861f | 2009-05-13 20:28:22 +0000 | [diff] [blame] | 1014 | Record->getInstantiatedFromMemberClass(), |
Douglas Gregor | d0e3daf | 2009-09-04 22:48:11 +0000 | [diff] [blame] | 1015 | TemplateArgs, |
| 1016 | TSK); |
Douglas Gregor | e9374d5 | 2009-10-08 01:19:17 +0000 | [diff] [blame] | 1017 | |
| 1018 | InstantiateClassMembers(PointOfInstantiation, Record, TemplateArgs, |
| 1019 | TSK); |
Douglas Gregor | a58861f | 2009-05-13 20:28:22 +0000 | [diff] [blame] | 1020 | } |
| 1021 | } |
| 1022 | } |
| 1023 | |
| 1024 | /// \brief Instantiate the definitions of all of the members of the |
| 1025 | /// given class template specialization, which was named as part of an |
| 1026 | /// explicit instantiation. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1027 | void |
Douglas Gregor | d0e3daf | 2009-09-04 22:48:11 +0000 | [diff] [blame] | 1028 | Sema::InstantiateClassTemplateSpecializationMembers( |
Douglas Gregor | a58861f | 2009-05-13 20:28:22 +0000 | [diff] [blame] | 1029 | SourceLocation PointOfInstantiation, |
Douglas Gregor | d0e3daf | 2009-09-04 22:48:11 +0000 | [diff] [blame] | 1030 | ClassTemplateSpecializationDecl *ClassTemplateSpec, |
| 1031 | TemplateSpecializationKind TSK) { |
Douglas Gregor | a58861f | 2009-05-13 20:28:22 +0000 | [diff] [blame] | 1032 | // C++0x [temp.explicit]p7: |
| 1033 | // An explicit instantiation that names a class template |
| 1034 | // specialization is an explicit instantion of the same kind |
| 1035 | // (declaration or definition) of each of its members (not |
| 1036 | // including members inherited from base classes) that has not |
| 1037 | // been previously explicitly specialized in the translation unit |
| 1038 | // containing the explicit instantiation, except as described |
| 1039 | // below. |
| 1040 | InstantiateClassMembers(PointOfInstantiation, ClassTemplateSpec, |
Douglas Gregor | d0e3daf | 2009-09-04 22:48:11 +0000 | [diff] [blame] | 1041 | getTemplateInstantiationArgs(ClassTemplateSpec), |
| 1042 | TSK); |
Douglas Gregor | a58861f | 2009-05-13 20:28:22 +0000 | [diff] [blame] | 1043 | } |
| 1044 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1045 | Sema::OwningStmtResult |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 1046 | Sema::SubstStmt(Stmt *S, const MultiLevelTemplateArgumentList &TemplateArgs) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1047 | if (!S) |
| 1048 | return Owned(S); |
| 1049 | |
| 1050 | TemplateInstantiator Instantiator(*this, TemplateArgs, |
| 1051 | SourceLocation(), |
| 1052 | DeclarationName()); |
| 1053 | return Instantiator.TransformStmt(S); |
| 1054 | } |
| 1055 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1056 | Sema::OwningExprResult |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 1057 | Sema::SubstExpr(Expr *E, const MultiLevelTemplateArgumentList &TemplateArgs) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1058 | if (!E) |
| 1059 | return Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1060 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1061 | TemplateInstantiator Instantiator(*this, TemplateArgs, |
| 1062 | SourceLocation(), |
| 1063 | DeclarationName()); |
| 1064 | return Instantiator.TransformExpr(E); |
| 1065 | } |
| 1066 | |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 1067 | /// \brief Do template substitution on a nested-name-specifier. |
Douglas Gregor | ab452ba | 2009-03-26 23:50:42 +0000 | [diff] [blame] | 1068 | NestedNameSpecifier * |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 1069 | Sema::SubstNestedNameSpecifier(NestedNameSpecifier *NNS, |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 1070 | SourceRange Range, |
| 1071 | const MultiLevelTemplateArgumentList &TemplateArgs) { |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1072 | TemplateInstantiator Instantiator(*this, TemplateArgs, Range.getBegin(), |
| 1073 | DeclarationName()); |
| 1074 | return Instantiator.TransformNestedNameSpecifier(NNS, Range); |
Douglas Gregor | 5953d8b | 2009-03-19 17:26:29 +0000 | [diff] [blame] | 1075 | } |
Douglas Gregor | de650ae | 2009-03-31 18:38:02 +0000 | [diff] [blame] | 1076 | |
| 1077 | TemplateName |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 1078 | Sema::SubstTemplateName(TemplateName Name, SourceLocation Loc, |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 1079 | const MultiLevelTemplateArgumentList &TemplateArgs) { |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1080 | TemplateInstantiator Instantiator(*this, TemplateArgs, Loc, |
| 1081 | DeclarationName()); |
| 1082 | return Instantiator.TransformTemplateName(Name); |
Douglas Gregor | de650ae | 2009-03-31 18:38:02 +0000 | [diff] [blame] | 1083 | } |
Douglas Gregor | 9133300 | 2009-06-11 00:06:24 +0000 | [diff] [blame] | 1084 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1085 | TemplateArgument Sema::Subst(TemplateArgument Arg, |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 1086 | const MultiLevelTemplateArgumentList &TemplateArgs) { |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1087 | TemplateInstantiator Instantiator(*this, TemplateArgs, SourceLocation(), |
| 1088 | DeclarationName()); |
| 1089 | return Instantiator.TransformTemplateArgument(Arg); |
Douglas Gregor | 9133300 | 2009-06-11 00:06:24 +0000 | [diff] [blame] | 1090 | } |