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" |
John McCall | 5b3f913 | 2009-11-22 01:44:31 +0000 | [diff] [blame] | 15 | #include "Lookup.h" |
Douglas Gregor | aba43bb | 2009-05-26 20:50:29 +0000 | [diff] [blame] | 16 | #include "clang/AST/ASTConsumer.h" |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 17 | #include "clang/AST/ASTContext.h" |
| 18 | #include "clang/AST/Expr.h" |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 19 | #include "clang/AST/DeclTemplate.h" |
| 20 | #include "clang/Parse/DeclSpec.h" |
| 21 | #include "clang/Basic/LangOptions.h" |
| 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 | 0f8716b | 2009-11-09 19:17:50 +0000 | [diff] [blame] | 31 | /// |
| 32 | /// \param D the declaration for which we are computing template instantiation |
| 33 | /// arguments. |
| 34 | /// |
| 35 | /// \param Innermost if non-NULL, the innermost template argument list. |
Douglas Gregor | d110243 | 2009-08-28 17:37:35 +0000 | [diff] [blame] | 36 | MultiLevelTemplateArgumentList |
Douglas Gregor | 0f8716b | 2009-11-09 19:17:50 +0000 | [diff] [blame] | 37 | Sema::getTemplateInstantiationArgs(NamedDecl *D, |
| 38 | const TemplateArgumentList *Innermost) { |
Douglas Gregor | d110243 | 2009-08-28 17:37:35 +0000 | [diff] [blame] | 39 | // Accumulate the set of template argument lists in this structure. |
| 40 | MultiLevelTemplateArgumentList Result; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 41 | |
Douglas Gregor | 0f8716b | 2009-11-09 19:17:50 +0000 | [diff] [blame] | 42 | if (Innermost) |
| 43 | Result.addOuterTemplateArguments(Innermost); |
| 44 | |
Douglas Gregor | d110243 | 2009-08-28 17:37:35 +0000 | [diff] [blame] | 45 | DeclContext *Ctx = dyn_cast<DeclContext>(D); |
| 46 | if (!Ctx) |
| 47 | Ctx = D->getDeclContext(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 48 | |
John McCall | f181d8a | 2009-08-29 03:16:09 +0000 | [diff] [blame] | 49 | while (!Ctx->isFileContext()) { |
Douglas Gregor | d110243 | 2009-08-28 17:37:35 +0000 | [diff] [blame] | 50 | // Add template arguments from a class template instantiation. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 51 | if (ClassTemplateSpecializationDecl *Spec |
Douglas Gregor | d110243 | 2009-08-28 17:37:35 +0000 | [diff] [blame] | 52 | = dyn_cast<ClassTemplateSpecializationDecl>(Ctx)) { |
| 53 | // We're done when we hit an explicit specialization. |
| 54 | if (Spec->getSpecializationKind() == TSK_ExplicitSpecialization) |
| 55 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 56 | |
Douglas Gregor | d110243 | 2009-08-28 17:37:35 +0000 | [diff] [blame] | 57 | Result.addOuterTemplateArguments(&Spec->getTemplateInstantiationArgs()); |
Douglas Gregor | fd056bc | 2009-10-13 16:30:37 +0000 | [diff] [blame] | 58 | |
| 59 | // If this class template specialization was instantiated from a |
| 60 | // specialized member that is a class template, we're done. |
| 61 | assert(Spec->getSpecializedTemplate() && "No class template?"); |
| 62 | if (Spec->getSpecializedTemplate()->isMemberSpecialization()) |
| 63 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 64 | } |
Douglas Gregor | d110243 | 2009-08-28 17:37:35 +0000 | [diff] [blame] | 65 | // Add template arguments from a function template specialization. |
John McCall | f181d8a | 2009-08-29 03:16:09 +0000 | [diff] [blame] | 66 | else if (FunctionDecl *Function = dyn_cast<FunctionDecl>(Ctx)) { |
Douglas Gregor | fd056bc | 2009-10-13 16:30:37 +0000 | [diff] [blame] | 67 | if (Function->getTemplateSpecializationKind() |
| 68 | == TSK_ExplicitSpecialization) |
| 69 | break; |
| 70 | |
Douglas Gregor | d110243 | 2009-08-28 17:37:35 +0000 | [diff] [blame] | 71 | if (const TemplateArgumentList *TemplateArgs |
Douglas Gregor | fd056bc | 2009-10-13 16:30:37 +0000 | [diff] [blame] | 72 | = Function->getTemplateSpecializationArgs()) { |
| 73 | // Add the template arguments for this specialization. |
Douglas Gregor | d110243 | 2009-08-28 17:37:35 +0000 | [diff] [blame] | 74 | Result.addOuterTemplateArguments(TemplateArgs); |
John McCall | f181d8a | 2009-08-29 03:16:09 +0000 | [diff] [blame] | 75 | |
Douglas Gregor | fd056bc | 2009-10-13 16:30:37 +0000 | [diff] [blame] | 76 | // If this function was instantiated from a specialized member that is |
| 77 | // a function template, we're done. |
| 78 | assert(Function->getPrimaryTemplate() && "No function template?"); |
| 79 | if (Function->getPrimaryTemplate()->isMemberSpecialization()) |
| 80 | break; |
| 81 | } |
| 82 | |
John McCall | f181d8a | 2009-08-29 03:16:09 +0000 | [diff] [blame] | 83 | // If this is a friend declaration and it declares an entity at |
| 84 | // namespace scope, take arguments from its lexical parent |
| 85 | // instead of its semantic parent. |
| 86 | if (Function->getFriendObjectKind() && |
| 87 | Function->getDeclContext()->isFileContext()) { |
| 88 | Ctx = Function->getLexicalDeclContext(); |
| 89 | continue; |
| 90 | } |
Douglas Gregor | d110243 | 2009-08-28 17:37:35 +0000 | [diff] [blame] | 91 | } |
John McCall | f181d8a | 2009-08-29 03:16:09 +0000 | [diff] [blame] | 92 | |
| 93 | Ctx = Ctx->getParent(); |
Douglas Gregor | 54dabfc | 2009-05-14 23:26:13 +0000 | [diff] [blame] | 94 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 95 | |
Douglas Gregor | d110243 | 2009-08-28 17:37:35 +0000 | [diff] [blame] | 96 | return Result; |
Douglas Gregor | 54dabfc | 2009-05-14 23:26:13 +0000 | [diff] [blame] | 97 | } |
| 98 | |
Douglas Gregor | f35f828 | 2009-11-11 21:54:23 +0000 | [diff] [blame] | 99 | bool Sema::ActiveTemplateInstantiation::isInstantiationRecord() const { |
| 100 | switch (Kind) { |
| 101 | case TemplateInstantiation: |
| 102 | case DefaultTemplateArgumentInstantiation: |
| 103 | case DefaultFunctionArgumentInstantiation: |
| 104 | return true; |
| 105 | |
| 106 | case ExplicitTemplateArgumentSubstitution: |
| 107 | case DeducedTemplateArgumentSubstitution: |
| 108 | case PriorTemplateArgumentSubstitution: |
| 109 | case DefaultTemplateArgumentChecking: |
| 110 | return false; |
| 111 | } |
| 112 | |
| 113 | return true; |
| 114 | } |
| 115 | |
Douglas Gregor | 26dce44 | 2009-03-10 00:06:19 +0000 | [diff] [blame] | 116 | Sema::InstantiatingTemplate:: |
| 117 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
Douglas Gregor | f3e7ce4 | 2009-05-18 17:01:57 +0000 | [diff] [blame] | 118 | Decl *Entity, |
Douglas Gregor | 26dce44 | 2009-03-10 00:06:19 +0000 | [diff] [blame] | 119 | SourceRange InstantiationRange) |
| 120 | : SemaRef(SemaRef) { |
Douglas Gregor | df667e7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 121 | |
| 122 | Invalid = CheckInstantiationDepth(PointOfInstantiation, |
| 123 | InstantiationRange); |
| 124 | if (!Invalid) { |
Douglas Gregor | 26dce44 | 2009-03-10 00:06:19 +0000 | [diff] [blame] | 125 | ActiveTemplateInstantiation Inst; |
Douglas Gregor | df667e7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 126 | Inst.Kind = ActiveTemplateInstantiation::TemplateInstantiation; |
Douglas Gregor | 26dce44 | 2009-03-10 00:06:19 +0000 | [diff] [blame] | 127 | Inst.PointOfInstantiation = PointOfInstantiation; |
Douglas Gregor | df667e7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 128 | Inst.Entity = reinterpret_cast<uintptr_t>(Entity); |
Douglas Gregor | 313a81d | 2009-03-12 18:36:18 +0000 | [diff] [blame] | 129 | Inst.TemplateArgs = 0; |
| 130 | Inst.NumTemplateArgs = 0; |
Douglas Gregor | df667e7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 131 | Inst.InstantiationRange = InstantiationRange; |
| 132 | SemaRef.ActiveTemplateInstantiations.push_back(Inst); |
Douglas Gregor | df667e7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 133 | } |
| 134 | } |
| 135 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 136 | Sema::InstantiatingTemplate::InstantiatingTemplate(Sema &SemaRef, |
Douglas Gregor | df667e7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 137 | SourceLocation PointOfInstantiation, |
| 138 | TemplateDecl *Template, |
| 139 | const TemplateArgument *TemplateArgs, |
| 140 | unsigned NumTemplateArgs, |
| 141 | SourceRange InstantiationRange) |
| 142 | : SemaRef(SemaRef) { |
| 143 | |
| 144 | Invalid = CheckInstantiationDepth(PointOfInstantiation, |
| 145 | InstantiationRange); |
| 146 | if (!Invalid) { |
| 147 | ActiveTemplateInstantiation Inst; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 148 | Inst.Kind |
Douglas Gregor | df667e7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 149 | = ActiveTemplateInstantiation::DefaultTemplateArgumentInstantiation; |
| 150 | Inst.PointOfInstantiation = PointOfInstantiation; |
| 151 | Inst.Entity = reinterpret_cast<uintptr_t>(Template); |
| 152 | Inst.TemplateArgs = TemplateArgs; |
| 153 | Inst.NumTemplateArgs = NumTemplateArgs; |
Douglas Gregor | 26dce44 | 2009-03-10 00:06:19 +0000 | [diff] [blame] | 154 | Inst.InstantiationRange = InstantiationRange; |
| 155 | SemaRef.ActiveTemplateInstantiations.push_back(Inst); |
Douglas Gregor | 26dce44 | 2009-03-10 00:06:19 +0000 | [diff] [blame] | 156 | } |
| 157 | } |
| 158 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 159 | Sema::InstantiatingTemplate::InstantiatingTemplate(Sema &SemaRef, |
Douglas Gregor | 637a409 | 2009-06-10 23:47:09 +0000 | [diff] [blame] | 160 | SourceLocation PointOfInstantiation, |
Douglas Gregor | cca9e96 | 2009-07-01 22:01:06 +0000 | [diff] [blame] | 161 | FunctionTemplateDecl *FunctionTemplate, |
| 162 | const TemplateArgument *TemplateArgs, |
| 163 | unsigned NumTemplateArgs, |
| 164 | ActiveTemplateInstantiation::InstantiationKind Kind, |
| 165 | SourceRange InstantiationRange) |
| 166 | : SemaRef(SemaRef) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 167 | |
Douglas Gregor | cca9e96 | 2009-07-01 22:01:06 +0000 | [diff] [blame] | 168 | Invalid = CheckInstantiationDepth(PointOfInstantiation, |
| 169 | InstantiationRange); |
| 170 | if (!Invalid) { |
| 171 | ActiveTemplateInstantiation Inst; |
| 172 | Inst.Kind = Kind; |
| 173 | Inst.PointOfInstantiation = PointOfInstantiation; |
| 174 | Inst.Entity = reinterpret_cast<uintptr_t>(FunctionTemplate); |
| 175 | Inst.TemplateArgs = TemplateArgs; |
| 176 | Inst.NumTemplateArgs = NumTemplateArgs; |
| 177 | Inst.InstantiationRange = InstantiationRange; |
| 178 | SemaRef.ActiveTemplateInstantiations.push_back(Inst); |
Douglas Gregor | f35f828 | 2009-11-11 21:54:23 +0000 | [diff] [blame] | 179 | |
| 180 | if (!Inst.isInstantiationRecord()) |
| 181 | ++SemaRef.NonInstantiationEntries; |
Douglas Gregor | cca9e96 | 2009-07-01 22:01:06 +0000 | [diff] [blame] | 182 | } |
| 183 | } |
| 184 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 185 | Sema::InstantiatingTemplate::InstantiatingTemplate(Sema &SemaRef, |
Douglas Gregor | cca9e96 | 2009-07-01 22:01:06 +0000 | [diff] [blame] | 186 | SourceLocation PointOfInstantiation, |
Douglas Gregor | 637a409 | 2009-06-10 23:47:09 +0000 | [diff] [blame] | 187 | ClassTemplatePartialSpecializationDecl *PartialSpec, |
| 188 | const TemplateArgument *TemplateArgs, |
| 189 | unsigned NumTemplateArgs, |
| 190 | SourceRange InstantiationRange) |
| 191 | : SemaRef(SemaRef) { |
| 192 | |
Douglas Gregor | f35f828 | 2009-11-11 21:54:23 +0000 | [diff] [blame] | 193 | Invalid = false; |
| 194 | |
| 195 | ActiveTemplateInstantiation Inst; |
| 196 | Inst.Kind = ActiveTemplateInstantiation::DeducedTemplateArgumentSubstitution; |
| 197 | Inst.PointOfInstantiation = PointOfInstantiation; |
| 198 | Inst.Entity = reinterpret_cast<uintptr_t>(PartialSpec); |
| 199 | Inst.TemplateArgs = TemplateArgs; |
| 200 | Inst.NumTemplateArgs = NumTemplateArgs; |
| 201 | Inst.InstantiationRange = InstantiationRange; |
| 202 | SemaRef.ActiveTemplateInstantiations.push_back(Inst); |
| 203 | |
| 204 | assert(!Inst.isInstantiationRecord()); |
| 205 | ++SemaRef.NonInstantiationEntries; |
Douglas Gregor | 637a409 | 2009-06-10 23:47:09 +0000 | [diff] [blame] | 206 | } |
| 207 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 208 | Sema::InstantiatingTemplate::InstantiatingTemplate(Sema &SemaRef, |
Douglas Gregor | 9148c3f | 2009-11-11 19:13:48 +0000 | [diff] [blame] | 209 | SourceLocation PointOfInstantiation, |
Anders Carlsson | 25cae7f | 2009-09-05 05:14:19 +0000 | [diff] [blame] | 210 | ParmVarDecl *Param, |
| 211 | const TemplateArgument *TemplateArgs, |
| 212 | unsigned NumTemplateArgs, |
| 213 | SourceRange InstantiationRange) |
| 214 | : SemaRef(SemaRef) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 215 | |
Douglas Gregor | 9148c3f | 2009-11-11 19:13:48 +0000 | [diff] [blame] | 216 | Invalid = CheckInstantiationDepth(PointOfInstantiation, InstantiationRange); |
Anders Carlsson | 25cae7f | 2009-09-05 05:14:19 +0000 | [diff] [blame] | 217 | |
| 218 | if (!Invalid) { |
| 219 | ActiveTemplateInstantiation Inst; |
| 220 | Inst.Kind |
| 221 | = ActiveTemplateInstantiation::DefaultFunctionArgumentInstantiation; |
Douglas Gregor | 9148c3f | 2009-11-11 19:13:48 +0000 | [diff] [blame] | 222 | Inst.PointOfInstantiation = PointOfInstantiation; |
Anders Carlsson | 25cae7f | 2009-09-05 05:14:19 +0000 | [diff] [blame] | 223 | Inst.Entity = reinterpret_cast<uintptr_t>(Param); |
| 224 | Inst.TemplateArgs = TemplateArgs; |
| 225 | Inst.NumTemplateArgs = NumTemplateArgs; |
| 226 | Inst.InstantiationRange = InstantiationRange; |
| 227 | SemaRef.ActiveTemplateInstantiations.push_back(Inst); |
Douglas Gregor | 9148c3f | 2009-11-11 19:13:48 +0000 | [diff] [blame] | 228 | } |
| 229 | } |
| 230 | |
| 231 | Sema::InstantiatingTemplate:: |
| 232 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
| 233 | TemplateDecl *Template, |
| 234 | NonTypeTemplateParmDecl *Param, |
| 235 | const TemplateArgument *TemplateArgs, |
| 236 | unsigned NumTemplateArgs, |
| 237 | SourceRange InstantiationRange) : SemaRef(SemaRef) { |
Douglas Gregor | f35f828 | 2009-11-11 21:54:23 +0000 | [diff] [blame] | 238 | Invalid = false; |
Douglas Gregor | 9148c3f | 2009-11-11 19:13:48 +0000 | [diff] [blame] | 239 | |
Douglas Gregor | f35f828 | 2009-11-11 21:54:23 +0000 | [diff] [blame] | 240 | ActiveTemplateInstantiation Inst; |
| 241 | Inst.Kind = ActiveTemplateInstantiation::PriorTemplateArgumentSubstitution; |
| 242 | Inst.PointOfInstantiation = PointOfInstantiation; |
| 243 | Inst.Template = Template; |
| 244 | Inst.Entity = reinterpret_cast<uintptr_t>(Param); |
| 245 | Inst.TemplateArgs = TemplateArgs; |
| 246 | Inst.NumTemplateArgs = NumTemplateArgs; |
| 247 | Inst.InstantiationRange = InstantiationRange; |
| 248 | SemaRef.ActiveTemplateInstantiations.push_back(Inst); |
| 249 | |
| 250 | assert(!Inst.isInstantiationRecord()); |
| 251 | ++SemaRef.NonInstantiationEntries; |
Douglas Gregor | 9148c3f | 2009-11-11 19:13:48 +0000 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | Sema::InstantiatingTemplate:: |
| 255 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
| 256 | TemplateDecl *Template, |
| 257 | TemplateTemplateParmDecl *Param, |
| 258 | const TemplateArgument *TemplateArgs, |
| 259 | unsigned NumTemplateArgs, |
| 260 | SourceRange InstantiationRange) : SemaRef(SemaRef) { |
Douglas Gregor | f35f828 | 2009-11-11 21:54:23 +0000 | [diff] [blame] | 261 | Invalid = false; |
| 262 | ActiveTemplateInstantiation Inst; |
| 263 | Inst.Kind = ActiveTemplateInstantiation::PriorTemplateArgumentSubstitution; |
| 264 | Inst.PointOfInstantiation = PointOfInstantiation; |
| 265 | Inst.Template = Template; |
| 266 | Inst.Entity = reinterpret_cast<uintptr_t>(Param); |
| 267 | Inst.TemplateArgs = TemplateArgs; |
| 268 | Inst.NumTemplateArgs = NumTemplateArgs; |
| 269 | Inst.InstantiationRange = InstantiationRange; |
| 270 | SemaRef.ActiveTemplateInstantiations.push_back(Inst); |
Douglas Gregor | 9148c3f | 2009-11-11 19:13:48 +0000 | [diff] [blame] | 271 | |
Douglas Gregor | f35f828 | 2009-11-11 21:54:23 +0000 | [diff] [blame] | 272 | assert(!Inst.isInstantiationRecord()); |
| 273 | ++SemaRef.NonInstantiationEntries; |
| 274 | } |
| 275 | |
| 276 | Sema::InstantiatingTemplate:: |
| 277 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
| 278 | TemplateDecl *Template, |
| 279 | NamedDecl *Param, |
| 280 | const TemplateArgument *TemplateArgs, |
| 281 | unsigned NumTemplateArgs, |
| 282 | SourceRange InstantiationRange) : SemaRef(SemaRef) { |
| 283 | Invalid = false; |
| 284 | |
| 285 | ActiveTemplateInstantiation Inst; |
| 286 | Inst.Kind = ActiveTemplateInstantiation::DefaultTemplateArgumentChecking; |
| 287 | Inst.PointOfInstantiation = PointOfInstantiation; |
| 288 | Inst.Template = Template; |
| 289 | Inst.Entity = reinterpret_cast<uintptr_t>(Param); |
| 290 | Inst.TemplateArgs = TemplateArgs; |
| 291 | Inst.NumTemplateArgs = NumTemplateArgs; |
| 292 | Inst.InstantiationRange = InstantiationRange; |
| 293 | SemaRef.ActiveTemplateInstantiations.push_back(Inst); |
| 294 | |
| 295 | assert(!Inst.isInstantiationRecord()); |
| 296 | ++SemaRef.NonInstantiationEntries; |
Anders Carlsson | 25cae7f | 2009-09-05 05:14:19 +0000 | [diff] [blame] | 297 | } |
| 298 | |
Douglas Gregor | f3e7ce4 | 2009-05-18 17:01:57 +0000 | [diff] [blame] | 299 | void Sema::InstantiatingTemplate::Clear() { |
| 300 | if (!Invalid) { |
Douglas Gregor | f35f828 | 2009-11-11 21:54:23 +0000 | [diff] [blame] | 301 | if (!SemaRef.ActiveTemplateInstantiations.back().isInstantiationRecord()) { |
| 302 | assert(SemaRef.NonInstantiationEntries > 0); |
| 303 | --SemaRef.NonInstantiationEntries; |
| 304 | } |
| 305 | |
Douglas Gregor | 26dce44 | 2009-03-10 00:06:19 +0000 | [diff] [blame] | 306 | SemaRef.ActiveTemplateInstantiations.pop_back(); |
Douglas Gregor | f3e7ce4 | 2009-05-18 17:01:57 +0000 | [diff] [blame] | 307 | Invalid = true; |
| 308 | } |
Douglas Gregor | 26dce44 | 2009-03-10 00:06:19 +0000 | [diff] [blame] | 309 | } |
| 310 | |
Douglas Gregor | df667e7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 311 | bool Sema::InstantiatingTemplate::CheckInstantiationDepth( |
| 312 | SourceLocation PointOfInstantiation, |
| 313 | SourceRange InstantiationRange) { |
Douglas Gregor | f35f828 | 2009-11-11 21:54:23 +0000 | [diff] [blame] | 314 | assert(SemaRef.NonInstantiationEntries <= |
| 315 | SemaRef.ActiveTemplateInstantiations.size()); |
| 316 | if ((SemaRef.ActiveTemplateInstantiations.size() - |
| 317 | SemaRef.NonInstantiationEntries) |
| 318 | <= SemaRef.getLangOptions().InstantiationDepth) |
Douglas Gregor | df667e7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 319 | return false; |
| 320 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 321 | SemaRef.Diag(PointOfInstantiation, |
Douglas Gregor | df667e7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 322 | diag::err_template_recursion_depth_exceeded) |
| 323 | << SemaRef.getLangOptions().InstantiationDepth |
| 324 | << InstantiationRange; |
| 325 | SemaRef.Diag(PointOfInstantiation, diag::note_template_recursion_depth) |
| 326 | << SemaRef.getLangOptions().InstantiationDepth; |
| 327 | return true; |
| 328 | } |
| 329 | |
Douglas Gregor | ee1828a | 2009-03-10 18:03:33 +0000 | [diff] [blame] | 330 | /// \brief Prints the current instantiation stack through a series of |
| 331 | /// notes. |
| 332 | void Sema::PrintInstantiationStack() { |
Douglas Gregor | cca9e96 | 2009-07-01 22:01:06 +0000 | [diff] [blame] | 333 | // 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] | 334 | for (llvm::SmallVector<ActiveTemplateInstantiation, 16>::reverse_iterator |
| 335 | Active = ActiveTemplateInstantiations.rbegin(), |
| 336 | ActiveEnd = ActiveTemplateInstantiations.rend(); |
| 337 | Active != ActiveEnd; |
| 338 | ++Active) { |
Douglas Gregor | df667e7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 339 | switch (Active->Kind) { |
| 340 | case ActiveTemplateInstantiation::TemplateInstantiation: { |
Douglas Gregor | f3e7ce4 | 2009-05-18 17:01:57 +0000 | [diff] [blame] | 341 | Decl *D = reinterpret_cast<Decl *>(Active->Entity); |
| 342 | if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(D)) { |
| 343 | unsigned DiagID = diag::note_template_member_class_here; |
| 344 | if (isa<ClassTemplateSpecializationDecl>(Record)) |
| 345 | DiagID = diag::note_template_class_instantiation_here; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 346 | Diags.Report(FullSourceLoc(Active->PointOfInstantiation, SourceMgr), |
Douglas Gregor | f3e7ce4 | 2009-05-18 17:01:57 +0000 | [diff] [blame] | 347 | DiagID) |
| 348 | << Context.getTypeDeclType(Record) |
| 349 | << Active->InstantiationRange; |
Douglas Gregor | 7caa682 | 2009-07-24 20:34:43 +0000 | [diff] [blame] | 350 | } else if (FunctionDecl *Function = dyn_cast<FunctionDecl>(D)) { |
Douglas Gregor | 1637be7 | 2009-06-26 00:10:03 +0000 | [diff] [blame] | 351 | unsigned DiagID; |
| 352 | if (Function->getPrimaryTemplate()) |
| 353 | DiagID = diag::note_function_template_spec_here; |
| 354 | else |
| 355 | DiagID = diag::note_template_member_function_here; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 356 | Diags.Report(FullSourceLoc(Active->PointOfInstantiation, SourceMgr), |
Douglas Gregor | f3e7ce4 | 2009-05-18 17:01:57 +0000 | [diff] [blame] | 357 | DiagID) |
| 358 | << Function |
| 359 | << Active->InstantiationRange; |
Douglas Gregor | 7caa682 | 2009-07-24 20:34:43 +0000 | [diff] [blame] | 360 | } else { |
| 361 | Diags.Report(FullSourceLoc(Active->PointOfInstantiation, SourceMgr), |
| 362 | diag::note_template_static_data_member_def_here) |
| 363 | << cast<VarDecl>(D) |
| 364 | << Active->InstantiationRange; |
Douglas Gregor | f3e7ce4 | 2009-05-18 17:01:57 +0000 | [diff] [blame] | 365 | } |
Douglas Gregor | df667e7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 366 | break; |
| 367 | } |
| 368 | |
| 369 | case ActiveTemplateInstantiation::DefaultTemplateArgumentInstantiation: { |
| 370 | TemplateDecl *Template = cast<TemplateDecl>((Decl *)Active->Entity); |
| 371 | std::string TemplateArgsStr |
Douglas Gregor | 7532dc6 | 2009-03-30 22:58:21 +0000 | [diff] [blame] | 372 | = TemplateSpecializationType::PrintTemplateArgumentList( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 373 | Active->TemplateArgs, |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 374 | Active->NumTemplateArgs, |
| 375 | Context.PrintingPolicy); |
Douglas Gregor | df667e7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 376 | Diags.Report(FullSourceLoc(Active->PointOfInstantiation, SourceMgr), |
| 377 | diag::note_default_arg_instantiation_here) |
| 378 | << (Template->getNameAsString() + TemplateArgsStr) |
| 379 | << Active->InstantiationRange; |
| 380 | break; |
| 381 | } |
Douglas Gregor | 637a409 | 2009-06-10 23:47:09 +0000 | [diff] [blame] | 382 | |
Douglas Gregor | cca9e96 | 2009-07-01 22:01:06 +0000 | [diff] [blame] | 383 | case ActiveTemplateInstantiation::ExplicitTemplateArgumentSubstitution: { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 384 | FunctionTemplateDecl *FnTmpl |
Douglas Gregor | cca9e96 | 2009-07-01 22:01:06 +0000 | [diff] [blame] | 385 | = cast<FunctionTemplateDecl>((Decl *)Active->Entity); |
Douglas Gregor | 637a409 | 2009-06-10 23:47:09 +0000 | [diff] [blame] | 386 | Diags.Report(FullSourceLoc(Active->PointOfInstantiation, SourceMgr), |
Douglas Gregor | cca9e96 | 2009-07-01 22:01:06 +0000 | [diff] [blame] | 387 | diag::note_explicit_template_arg_substitution_here) |
| 388 | << FnTmpl << Active->InstantiationRange; |
Douglas Gregor | 637a409 | 2009-06-10 23:47:09 +0000 | [diff] [blame] | 389 | break; |
| 390 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 391 | |
Douglas Gregor | cca9e96 | 2009-07-01 22:01:06 +0000 | [diff] [blame] | 392 | case ActiveTemplateInstantiation::DeducedTemplateArgumentSubstitution: |
| 393 | if (ClassTemplatePartialSpecializationDecl *PartialSpec |
| 394 | = dyn_cast<ClassTemplatePartialSpecializationDecl>( |
| 395 | (Decl *)Active->Entity)) { |
| 396 | Diags.Report(FullSourceLoc(Active->PointOfInstantiation, SourceMgr), |
| 397 | diag::note_partial_spec_deduct_instantiation_here) |
| 398 | << Context.getTypeDeclType(PartialSpec) |
| 399 | << Active->InstantiationRange; |
| 400 | } else { |
| 401 | FunctionTemplateDecl *FnTmpl |
| 402 | = cast<FunctionTemplateDecl>((Decl *)Active->Entity); |
| 403 | Diags.Report(FullSourceLoc(Active->PointOfInstantiation, SourceMgr), |
| 404 | diag::note_function_template_deduction_instantiation_here) |
| 405 | << FnTmpl << Active->InstantiationRange; |
| 406 | } |
| 407 | break; |
Douglas Gregor | 637a409 | 2009-06-10 23:47:09 +0000 | [diff] [blame] | 408 | |
Anders Carlsson | 25cae7f | 2009-09-05 05:14:19 +0000 | [diff] [blame] | 409 | case ActiveTemplateInstantiation::DefaultFunctionArgumentInstantiation: { |
| 410 | ParmVarDecl *Param = cast<ParmVarDecl>((Decl *)Active->Entity); |
| 411 | FunctionDecl *FD = cast<FunctionDecl>(Param->getDeclContext()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 412 | |
Anders Carlsson | 25cae7f | 2009-09-05 05:14:19 +0000 | [diff] [blame] | 413 | std::string TemplateArgsStr |
| 414 | = TemplateSpecializationType::PrintTemplateArgumentList( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 415 | Active->TemplateArgs, |
Anders Carlsson | 25cae7f | 2009-09-05 05:14:19 +0000 | [diff] [blame] | 416 | Active->NumTemplateArgs, |
| 417 | Context.PrintingPolicy); |
| 418 | Diags.Report(FullSourceLoc(Active->PointOfInstantiation, SourceMgr), |
| 419 | diag::note_default_function_arg_instantiation_here) |
Anders Carlsson | 6bc107b | 2009-09-05 05:38:54 +0000 | [diff] [blame] | 420 | << (FD->getNameAsString() + TemplateArgsStr) |
Anders Carlsson | 25cae7f | 2009-09-05 05:14:19 +0000 | [diff] [blame] | 421 | << Active->InstantiationRange; |
| 422 | break; |
| 423 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 424 | |
Douglas Gregor | 9148c3f | 2009-11-11 19:13:48 +0000 | [diff] [blame] | 425 | case ActiveTemplateInstantiation::PriorTemplateArgumentSubstitution: { |
| 426 | NamedDecl *Parm = cast<NamedDecl>((Decl *)Active->Entity); |
| 427 | std::string Name; |
| 428 | if (!Parm->getName().empty()) |
| 429 | Name = std::string(" '") + Parm->getName().str() + "'"; |
| 430 | |
| 431 | Diags.Report(FullSourceLoc(Active->PointOfInstantiation, SourceMgr), |
| 432 | diag::note_prior_template_arg_substitution) |
| 433 | << isa<TemplateTemplateParmDecl>(Parm) |
| 434 | << Name |
| 435 | << getTemplateArgumentBindingsText( |
| 436 | Active->Template->getTemplateParameters(), |
| 437 | Active->TemplateArgs, |
| 438 | Active->NumTemplateArgs) |
| 439 | << Active->InstantiationRange; |
| 440 | break; |
| 441 | } |
Douglas Gregor | f35f828 | 2009-11-11 21:54:23 +0000 | [diff] [blame] | 442 | |
| 443 | case ActiveTemplateInstantiation::DefaultTemplateArgumentChecking: { |
| 444 | Diags.Report(FullSourceLoc(Active->PointOfInstantiation, SourceMgr), |
| 445 | diag::note_template_default_arg_checking) |
| 446 | << getTemplateArgumentBindingsText( |
| 447 | Active->Template->getTemplateParameters(), |
| 448 | Active->TemplateArgs, |
| 449 | Active->NumTemplateArgs) |
| 450 | << Active->InstantiationRange; |
| 451 | break; |
| 452 | } |
Douglas Gregor | df667e7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 453 | } |
Douglas Gregor | ee1828a | 2009-03-10 18:03:33 +0000 | [diff] [blame] | 454 | } |
| 455 | } |
| 456 | |
Douglas Gregor | 5e9f35c | 2009-06-14 07:33:30 +0000 | [diff] [blame] | 457 | bool Sema::isSFINAEContext() const { |
| 458 | using llvm::SmallVector; |
| 459 | for (SmallVector<ActiveTemplateInstantiation, 16>::const_reverse_iterator |
| 460 | Active = ActiveTemplateInstantiations.rbegin(), |
| 461 | ActiveEnd = ActiveTemplateInstantiations.rend(); |
| 462 | Active != ActiveEnd; |
Douglas Gregor | f35f828 | 2009-11-11 21:54:23 +0000 | [diff] [blame] | 463 | ++Active) |
| 464 | { |
Douglas Gregor | 5e9f35c | 2009-06-14 07:33:30 +0000 | [diff] [blame] | 465 | switch(Active->Kind) { |
Douglas Gregor | cca9e96 | 2009-07-01 22:01:06 +0000 | [diff] [blame] | 466 | case ActiveTemplateInstantiation::TemplateInstantiation: |
Anders Carlsson | 25cae7f | 2009-09-05 05:14:19 +0000 | [diff] [blame] | 467 | case ActiveTemplateInstantiation::DefaultFunctionArgumentInstantiation: |
Douglas Gregor | cca9e96 | 2009-07-01 22:01:06 +0000 | [diff] [blame] | 468 | // This is a template instantiation, so there is no SFINAE. |
| 469 | return false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 470 | |
Douglas Gregor | 5e9f35c | 2009-06-14 07:33:30 +0000 | [diff] [blame] | 471 | case ActiveTemplateInstantiation::DefaultTemplateArgumentInstantiation: |
Douglas Gregor | 9148c3f | 2009-11-11 19:13:48 +0000 | [diff] [blame] | 472 | case ActiveTemplateInstantiation::PriorTemplateArgumentSubstitution: |
Douglas Gregor | f35f828 | 2009-11-11 21:54:23 +0000 | [diff] [blame] | 473 | case ActiveTemplateInstantiation::DefaultTemplateArgumentChecking: |
Douglas Gregor | 9148c3f | 2009-11-11 19:13:48 +0000 | [diff] [blame] | 474 | // A default template argument instantiation and substitution into |
| 475 | // template parameters with arguments for prior parameters may or may |
| 476 | // not be a SFINAE context; look further up the stack. |
Douglas Gregor | 5e9f35c | 2009-06-14 07:33:30 +0000 | [diff] [blame] | 477 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 478 | |
Douglas Gregor | cca9e96 | 2009-07-01 22:01:06 +0000 | [diff] [blame] | 479 | case ActiveTemplateInstantiation::ExplicitTemplateArgumentSubstitution: |
| 480 | case ActiveTemplateInstantiation::DeducedTemplateArgumentSubstitution: |
| 481 | // We're either substitution explicitly-specified template arguments |
| 482 | // or deduced template arguments, so SFINAE applies. |
| 483 | return true; |
Douglas Gregor | 5e9f35c | 2009-06-14 07:33:30 +0000 | [diff] [blame] | 484 | } |
| 485 | } |
| 486 | |
| 487 | return false; |
| 488 | } |
| 489 | |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 490 | //===----------------------------------------------------------------------===/ |
| 491 | // Template Instantiation for Types |
| 492 | //===----------------------------------------------------------------------===/ |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 493 | namespace { |
Benjamin Kramer | 85b4521 | 2009-11-28 19:45:26 +0000 | [diff] [blame] | 494 | class TemplateInstantiator |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 495 | : public TreeTransform<TemplateInstantiator> { |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 496 | const MultiLevelTemplateArgumentList &TemplateArgs; |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 497 | SourceLocation Loc; |
| 498 | DeclarationName Entity; |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 499 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 500 | public: |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 501 | typedef TreeTransform<TemplateInstantiator> inherited; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 502 | |
| 503 | TemplateInstantiator(Sema &SemaRef, |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 504 | const MultiLevelTemplateArgumentList &TemplateArgs, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 505 | SourceLocation Loc, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 506 | DeclarationName Entity) |
| 507 | : inherited(SemaRef), TemplateArgs(TemplateArgs), Loc(Loc), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 508 | Entity(Entity) { } |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 509 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 510 | /// \brief Determine whether the given type \p T has already been |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 511 | /// transformed. |
| 512 | /// |
| 513 | /// For the purposes of template instantiation, a type has already been |
| 514 | /// transformed if it is NULL or if it is not dependent. |
| 515 | bool AlreadyTransformed(QualType T) { |
| 516 | return T.isNull() || !T->isDependentType(); |
Douglas Gregor | ff66803 | 2009-05-13 18:28:20 +0000 | [diff] [blame] | 517 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 518 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 519 | /// \brief Returns the location of the entity being instantiated, if known. |
| 520 | SourceLocation getBaseLocation() { return Loc; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 521 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 522 | /// \brief Returns the name of the entity being instantiated, if any. |
| 523 | DeclarationName getBaseEntity() { return Entity; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 524 | |
Douglas Gregor | 972e6ce | 2009-10-27 06:26:26 +0000 | [diff] [blame] | 525 | /// \brief Sets the "base" location and entity when that |
| 526 | /// information is known based on another transformation. |
| 527 | void setBase(SourceLocation Loc, DeclarationName Entity) { |
| 528 | this->Loc = Loc; |
| 529 | this->Entity = Entity; |
| 530 | } |
| 531 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 532 | /// \brief Transform the given declaration by instantiating a reference to |
| 533 | /// this declaration. |
| 534 | Decl *TransformDecl(Decl *D); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 535 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 536 | /// \brief Transform the definition of the given declaration by |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 537 | /// instantiating it. |
| 538 | Decl *TransformDefinition(Decl *D); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 539 | |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 540 | /// \bried Transform the first qualifier within a scope by instantiating the |
| 541 | /// declaration. |
| 542 | NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc); |
| 543 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 544 | /// \brief Rebuild the exception declaration and register the declaration |
| 545 | /// as an instantiated local. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 546 | VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 547 | DeclaratorInfo *Declarator, |
| 548 | IdentifierInfo *Name, |
| 549 | SourceLocation Loc, SourceRange TypeRange); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 550 | |
John McCall | c4e7019 | 2009-09-11 04:59:25 +0000 | [diff] [blame] | 551 | /// \brief Check for tag mismatches when instantiating an |
| 552 | /// elaborated type. |
| 553 | QualType RebuildElaboratedType(QualType T, ElaboratedType::TagKind Tag); |
| 554 | |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 555 | Sema::OwningExprResult TransformPredefinedExpr(PredefinedExpr *E, |
| 556 | bool isAddressOfOperand); |
| 557 | Sema::OwningExprResult TransformDeclRefExpr(DeclRefExpr *E, |
| 558 | bool isAddressOfOperand); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 559 | |
Sebastian Redl | a29e51b | 2009-11-08 13:56:19 +0000 | [diff] [blame] | 560 | Sema::OwningExprResult TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E, |
| 561 | bool isAddressOfOperand); |
| 562 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 563 | /// \brief Transforms a template type parameter type by performing |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 564 | /// substitution of the corresponding template type argument. |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 565 | QualType TransformTemplateTypeParmType(TypeLocBuilder &TLB, |
| 566 | TemplateTypeParmTypeLoc TL); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 567 | }; |
Douglas Gregor | 7e7eb3d | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 568 | } |
| 569 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 570 | Decl *TemplateInstantiator::TransformDecl(Decl *D) { |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 571 | if (!D) |
| 572 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 573 | |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 574 | if (TemplateTemplateParmDecl *TTP = dyn_cast<TemplateTemplateParmDecl>(D)) { |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 575 | if (TTP->getDepth() < TemplateArgs.getNumLevels()) { |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 576 | TemplateName Template |
| 577 | = TemplateArgs(TTP->getDepth(), TTP->getPosition()).getAsTemplate(); |
| 578 | assert(!Template.isNull() && Template.getAsTemplateDecl() && |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 579 | "Wrong kind of template template argument"); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 580 | return Template.getAsTemplateDecl(); |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 581 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 582 | |
| 583 | // If the corresponding template argument is NULL or non-existent, it's |
| 584 | // because we are performing instantiation from explicitly-specified |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 585 | // template arguments in a function template, but there were some |
| 586 | // arguments left unspecified. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 587 | if (!TemplateArgs.hasTemplateArgument(TTP->getDepth(), |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 588 | TTP->getPosition())) |
| 589 | return D; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 590 | |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 591 | // Fall through to find the instantiated declaration for this template |
| 592 | // template parameter. |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 593 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 594 | |
Douglas Gregor | e95b409 | 2009-09-16 18:34:49 +0000 | [diff] [blame] | 595 | return SemaRef.FindInstantiatedDecl(cast<NamedDecl>(D), TemplateArgs); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 596 | } |
| 597 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 598 | Decl *TemplateInstantiator::TransformDefinition(Decl *D) { |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 599 | Decl *Inst = getSema().SubstDecl(D, getSema().CurContext, TemplateArgs); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 600 | if (!Inst) |
| 601 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 602 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 603 | getSema().CurrentInstantiationScope->InstantiatedLocal(D, Inst); |
| 604 | return Inst; |
| 605 | } |
| 606 | |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 607 | NamedDecl * |
| 608 | TemplateInstantiator::TransformFirstQualifierInScope(NamedDecl *D, |
| 609 | SourceLocation Loc) { |
| 610 | // If the first part of the nested-name-specifier was a template type |
| 611 | // parameter, instantiate that type parameter down to a tag type. |
| 612 | if (TemplateTypeParmDecl *TTPD = dyn_cast_or_null<TemplateTypeParmDecl>(D)) { |
| 613 | const TemplateTypeParmType *TTP |
| 614 | = cast<TemplateTypeParmType>(getSema().Context.getTypeDeclType(TTPD)); |
| 615 | if (TTP->getDepth() < TemplateArgs.getNumLevels()) { |
| 616 | QualType T = TemplateArgs(TTP->getDepth(), TTP->getIndex()).getAsType(); |
| 617 | if (T.isNull()) |
| 618 | return cast_or_null<NamedDecl>(TransformDecl(D)); |
| 619 | |
| 620 | if (const TagType *Tag = T->getAs<TagType>()) |
| 621 | return Tag->getDecl(); |
| 622 | |
| 623 | // The resulting type is not a tag; complain. |
| 624 | getSema().Diag(Loc, diag::err_nested_name_spec_non_tag) << T; |
| 625 | return 0; |
| 626 | } |
| 627 | } |
| 628 | |
| 629 | return cast_or_null<NamedDecl>(TransformDecl(D)); |
| 630 | } |
| 631 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 632 | VarDecl * |
| 633 | TemplateInstantiator::RebuildExceptionDecl(VarDecl *ExceptionDecl, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 634 | QualType T, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 635 | DeclaratorInfo *Declarator, |
| 636 | IdentifierInfo *Name, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 637 | SourceLocation Loc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 638 | SourceRange TypeRange) { |
| 639 | VarDecl *Var = inherited::RebuildExceptionDecl(ExceptionDecl, T, Declarator, |
| 640 | Name, Loc, TypeRange); |
| 641 | if (Var && !Var->isInvalidDecl()) |
| 642 | getSema().CurrentInstantiationScope->InstantiatedLocal(ExceptionDecl, Var); |
| 643 | return Var; |
| 644 | } |
| 645 | |
John McCall | c4e7019 | 2009-09-11 04:59:25 +0000 | [diff] [blame] | 646 | QualType |
| 647 | TemplateInstantiator::RebuildElaboratedType(QualType T, |
| 648 | ElaboratedType::TagKind Tag) { |
| 649 | if (const TagType *TT = T->getAs<TagType>()) { |
| 650 | TagDecl* TD = TT->getDecl(); |
| 651 | |
| 652 | // FIXME: this location is very wrong; we really need typelocs. |
| 653 | SourceLocation TagLocation = TD->getTagKeywordLoc(); |
| 654 | |
| 655 | // FIXME: type might be anonymous. |
| 656 | IdentifierInfo *Id = TD->getIdentifier(); |
| 657 | |
| 658 | // TODO: should we even warn on struct/class mismatches for this? Seems |
| 659 | // like it's likely to produce a lot of spurious errors. |
| 660 | if (!SemaRef.isAcceptableTagRedeclaration(TD, Tag, TagLocation, *Id)) { |
| 661 | SemaRef.Diag(TagLocation, diag::err_use_with_wrong_tag) |
| 662 | << Id |
| 663 | << CodeModificationHint::CreateReplacement(SourceRange(TagLocation), |
| 664 | TD->getKindName()); |
| 665 | SemaRef.Diag(TD->getLocation(), diag::note_previous_use); |
| 666 | } |
| 667 | } |
| 668 | |
| 669 | return TreeTransform<TemplateInstantiator>::RebuildElaboratedType(T, Tag); |
| 670 | } |
| 671 | |
| 672 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 673 | TemplateInstantiator::TransformPredefinedExpr(PredefinedExpr *E, |
| 674 | bool isAddressOfOperand) { |
Anders Carlsson | 773f397 | 2009-09-11 01:22:35 +0000 | [diff] [blame] | 675 | if (!E->isTypeDependent()) |
| 676 | return SemaRef.Owned(E->Retain()); |
| 677 | |
| 678 | FunctionDecl *currentDecl = getSema().getCurFunctionDecl(); |
| 679 | assert(currentDecl && "Must have current function declaration when " |
| 680 | "instantiating."); |
| 681 | |
| 682 | PredefinedExpr::IdentType IT = E->getIdentType(); |
| 683 | |
| 684 | unsigned Length = |
| 685 | PredefinedExpr::ComputeName(getSema().Context, IT, currentDecl).length(); |
| 686 | |
| 687 | llvm::APInt LengthI(32, Length + 1); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 688 | QualType ResTy = getSema().Context.CharTy.withConst(); |
Anders Carlsson | 773f397 | 2009-09-11 01:22:35 +0000 | [diff] [blame] | 689 | ResTy = getSema().Context.getConstantArrayType(ResTy, LengthI, |
| 690 | ArrayType::Normal, 0); |
| 691 | PredefinedExpr *PE = |
| 692 | new (getSema().Context) PredefinedExpr(E->getLocation(), ResTy, IT); |
| 693 | return getSema().Owned(PE); |
| 694 | } |
| 695 | |
| 696 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 697 | TemplateInstantiator::TransformDeclRefExpr(DeclRefExpr *E, |
| 698 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 699 | // FIXME: Clean this up a bit |
| 700 | NamedDecl *D = E->getDecl(); |
| 701 | if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(D)) { |
Douglas Gregor | 550d9b2 | 2009-10-31 17:21:17 +0000 | [diff] [blame] | 702 | if (NTTP->getDepth() < TemplateArgs.getNumLevels()) { |
Douglas Gregor | 550d9b2 | 2009-10-31 17:21:17 +0000 | [diff] [blame] | 703 | // If the corresponding template argument is NULL or non-existent, it's |
| 704 | // because we are performing instantiation from explicitly-specified |
| 705 | // template arguments in a function template, but there were some |
| 706 | // arguments left unspecified. |
| 707 | if (!TemplateArgs.hasTemplateArgument(NTTP->getDepth(), |
| 708 | NTTP->getPosition())) |
| 709 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 710 | |
Douglas Gregor | 550d9b2 | 2009-10-31 17:21:17 +0000 | [diff] [blame] | 711 | const TemplateArgument &Arg = TemplateArgs(NTTP->getDepth(), |
| 712 | NTTP->getPosition()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 713 | |
Douglas Gregor | 550d9b2 | 2009-10-31 17:21:17 +0000 | [diff] [blame] | 714 | // The template argument itself might be an expression, in which |
| 715 | // case we just return that expression. |
| 716 | if (Arg.getKind() == TemplateArgument::Expression) |
| 717 | return SemaRef.Owned(Arg.getAsExpr()->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 718 | |
Douglas Gregor | 550d9b2 | 2009-10-31 17:21:17 +0000 | [diff] [blame] | 719 | if (Arg.getKind() == TemplateArgument::Declaration) { |
| 720 | ValueDecl *VD = cast<ValueDecl>(Arg.getAsDecl()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 721 | |
Douglas Gregor | 550d9b2 | 2009-10-31 17:21:17 +0000 | [diff] [blame] | 722 | VD = cast_or_null<ValueDecl>( |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 723 | getSema().FindInstantiatedDecl(VD, TemplateArgs)); |
Douglas Gregor | 550d9b2 | 2009-10-31 17:21:17 +0000 | [diff] [blame] | 724 | if (!VD) |
| 725 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 726 | |
Douglas Gregor | 231edff | 2009-11-12 17:40:13 +0000 | [diff] [blame] | 727 | if (VD->getDeclContext()->isRecord()) { |
| 728 | // If the value is a class member, we might have a pointer-to-member. |
| 729 | // Determine whether the non-type template template parameter is of |
| 730 | // pointer-to-member type. If so, we need to build an appropriate |
| 731 | // expression for a pointer-to-member, since a "normal" DeclRefExpr |
| 732 | // would refer to the member itself. |
| 733 | if (NTTP->getType()->isMemberPointerType()) { |
| 734 | QualType ClassType |
| 735 | = SemaRef.Context.getTypeDeclType( |
| 736 | cast<RecordDecl>(VD->getDeclContext())); |
| 737 | NestedNameSpecifier *Qualifier |
| 738 | = NestedNameSpecifier::Create(SemaRef.Context, 0, false, |
| 739 | ClassType.getTypePtr()); |
| 740 | CXXScopeSpec SS; |
| 741 | SS.setScopeRep(Qualifier); |
| 742 | OwningExprResult RefExpr |
| 743 | = SemaRef.BuildDeclRefExpr(VD, |
| 744 | VD->getType().getNonReferenceType(), |
| 745 | E->getLocation(), |
Douglas Gregor | 231edff | 2009-11-12 17:40:13 +0000 | [diff] [blame] | 746 | &SS); |
| 747 | if (RefExpr.isInvalid()) |
| 748 | return SemaRef.ExprError(); |
| 749 | |
| 750 | return SemaRef.CreateBuiltinUnaryOp(E->getLocation(), |
| 751 | UnaryOperator::AddrOf, |
| 752 | move(RefExpr)); |
| 753 | } |
| 754 | } |
| 755 | |
| 756 | return SemaRef.BuildDeclRefExpr(VD, VD->getType().getNonReferenceType(), |
Douglas Gregor | 0da76df | 2009-11-23 11:41:28 +0000 | [diff] [blame] | 757 | E->getLocation()); |
Douglas Gregor | 550d9b2 | 2009-10-31 17:21:17 +0000 | [diff] [blame] | 758 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 759 | |
Douglas Gregor | 550d9b2 | 2009-10-31 17:21:17 +0000 | [diff] [blame] | 760 | assert(Arg.getKind() == TemplateArgument::Integral); |
| 761 | QualType T = Arg.getIntegralType(); |
| 762 | if (T->isCharType() || T->isWideCharType()) |
| 763 | return SemaRef.Owned(new (SemaRef.Context) CharacterLiteral( |
| 764 | Arg.getAsIntegral()->getZExtValue(), |
| 765 | T->isWideCharType(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 766 | T, |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 767 | E->getSourceRange().getBegin())); |
Douglas Gregor | 550d9b2 | 2009-10-31 17:21:17 +0000 | [diff] [blame] | 768 | if (T->isBooleanType()) |
| 769 | return SemaRef.Owned(new (SemaRef.Context) CXXBoolLiteralExpr( |
| 770 | Arg.getAsIntegral()->getBoolValue(), |
| 771 | T, |
| 772 | E->getSourceRange().getBegin())); |
| 773 | |
| 774 | assert(Arg.getAsIntegral()->getBitWidth() == SemaRef.Context.getIntWidth(T)); |
| 775 | return SemaRef.Owned(new (SemaRef.Context) IntegerLiteral( |
| 776 | *Arg.getAsIntegral(), |
| 777 | T, |
| 778 | E->getSourceRange().getBegin())); |
| 779 | } |
| 780 | |
| 781 | // We have a non-type template parameter that isn't fully substituted; |
| 782 | // FindInstantiatedDecl will find it in the local instantiation scope. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 783 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 784 | |
Douglas Gregor | e95b409 | 2009-09-16 18:34:49 +0000 | [diff] [blame] | 785 | NamedDecl *InstD = SemaRef.FindInstantiatedDecl(D, TemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 786 | if (!InstD) |
| 787 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 788 | |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 789 | assert(!isa<UsingDecl>(InstD) && "decl ref instantiated to UsingDecl"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 790 | |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 791 | CXXScopeSpec SS; |
| 792 | NestedNameSpecifier *Qualifier = 0; |
| 793 | if (E->getQualifier()) { |
| 794 | Qualifier = TransformNestedNameSpecifier(E->getQualifier(), |
| 795 | E->getQualifierRange()); |
| 796 | if (!Qualifier) |
| 797 | return SemaRef.ExprError(); |
| 798 | |
| 799 | SS.setScopeRep(Qualifier); |
| 800 | SS.setRange(E->getQualifierRange()); |
| 801 | } |
| 802 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 803 | return SemaRef.BuildDeclarationNameExpr(SS, E->getLocation(), InstD); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 804 | } |
| 805 | |
Sebastian Redl | a29e51b | 2009-11-08 13:56:19 +0000 | [diff] [blame] | 806 | Sema::OwningExprResult TemplateInstantiator::TransformCXXDefaultArgExpr( |
| 807 | CXXDefaultArgExpr *E, bool isAddressOfOperand) { |
| 808 | assert(!cast<FunctionDecl>(E->getParam()->getDeclContext())-> |
| 809 | getDescribedFunctionTemplate() && |
| 810 | "Default arg expressions are never formed in dependent cases."); |
| 811 | return SemaRef.Owned(E->Retain()); |
| 812 | } |
| 813 | |
| 814 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 815 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 816 | TemplateInstantiator::TransformTemplateTypeParmType(TypeLocBuilder &TLB, |
| 817 | TemplateTypeParmTypeLoc TL) { |
| 818 | TemplateTypeParmType *T = TL.getTypePtr(); |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 819 | if (T->getDepth() < TemplateArgs.getNumLevels()) { |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 820 | // Replace the template type parameter with its corresponding |
| 821 | // template argument. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 822 | |
| 823 | // If the corresponding template argument is NULL or doesn't exist, it's |
| 824 | // because we are performing instantiation from explicitly-specified |
| 825 | // template arguments in a function template class, but there were some |
Douglas Gregor | 16134c6 | 2009-07-01 00:28:38 +0000 | [diff] [blame] | 826 | // arguments left unspecified. |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 827 | if (!TemplateArgs.hasTemplateArgument(T->getDepth(), T->getIndex())) { |
| 828 | TemplateTypeParmTypeLoc NewTL |
| 829 | = TLB.push<TemplateTypeParmTypeLoc>(TL.getType()); |
| 830 | NewTL.setNameLoc(TL.getNameLoc()); |
| 831 | return TL.getType(); |
| 832 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 833 | |
| 834 | assert(TemplateArgs(T->getDepth(), T->getIndex()).getKind() |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 835 | == TemplateArgument::Type && |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 836 | "Template argument kind mismatch"); |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 837 | |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 838 | QualType Replacement |
| 839 | = TemplateArgs(T->getDepth(), T->getIndex()).getAsType(); |
| 840 | |
| 841 | // TODO: only do this uniquing once, at the start of instantiation. |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 842 | QualType Result |
| 843 | = getSema().Context.getSubstTemplateTypeParmType(T, Replacement); |
| 844 | SubstTemplateTypeParmTypeLoc NewTL |
| 845 | = TLB.push<SubstTemplateTypeParmTypeLoc>(Result); |
| 846 | NewTL.setNameLoc(TL.getNameLoc()); |
| 847 | return Result; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 848 | } |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 849 | |
| 850 | // The template type parameter comes from an inner template (e.g., |
| 851 | // the template parameter list of a member template inside the |
| 852 | // template we are instantiating). Create a new template type |
| 853 | // parameter with the template "level" reduced by one. |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 854 | QualType Result |
| 855 | = getSema().Context.getTemplateTypeParmType(T->getDepth() |
| 856 | - TemplateArgs.getNumLevels(), |
| 857 | T->getIndex(), |
| 858 | T->isParameterPack(), |
| 859 | T->getName()); |
| 860 | TemplateTypeParmTypeLoc NewTL = TLB.push<TemplateTypeParmTypeLoc>(Result); |
| 861 | NewTL.setNameLoc(TL.getNameLoc()); |
| 862 | return Result; |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 863 | } |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 864 | |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 865 | /// \brief Perform substitution on the type T with a given set of template |
| 866 | /// arguments. |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 867 | /// |
| 868 | /// This routine substitutes the given template arguments into the |
| 869 | /// type T and produces the instantiated type. |
| 870 | /// |
| 871 | /// \param T the type into which the template arguments will be |
| 872 | /// substituted. If this type is not dependent, it will be returned |
| 873 | /// immediately. |
| 874 | /// |
| 875 | /// \param TemplateArgs the template arguments that will be |
| 876 | /// substituted for the top-level template parameters within T. |
| 877 | /// |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 878 | /// \param Loc the location in the source code where this substitution |
| 879 | /// is being performed. It will typically be the location of the |
| 880 | /// declarator (if we're instantiating the type of some declaration) |
| 881 | /// or the location of the type in the source code (if, e.g., we're |
| 882 | /// instantiating the type of a cast expression). |
| 883 | /// |
| 884 | /// \param Entity the name of the entity associated with a declaration |
| 885 | /// being instantiated (if any). May be empty to indicate that there |
| 886 | /// is no such entity (if, e.g., this is a type that occurs as part of |
| 887 | /// a cast expression) or that the entity has no name (e.g., an |
| 888 | /// unnamed function parameter). |
| 889 | /// |
| 890 | /// \returns If the instantiation succeeds, the instantiated |
| 891 | /// type. Otherwise, produces diagnostics and returns a NULL type. |
John McCall | cd7ba1c | 2009-10-21 00:58:09 +0000 | [diff] [blame] | 892 | DeclaratorInfo *Sema::SubstType(DeclaratorInfo *T, |
| 893 | const MultiLevelTemplateArgumentList &Args, |
| 894 | SourceLocation Loc, |
| 895 | DeclarationName Entity) { |
| 896 | assert(!ActiveTemplateInstantiations.empty() && |
| 897 | "Cannot perform an instantiation without some context on the " |
| 898 | "instantiation stack"); |
| 899 | |
| 900 | if (!T->getType()->isDependentType()) |
| 901 | return T; |
| 902 | |
| 903 | TemplateInstantiator Instantiator(*this, Args, Loc, Entity); |
| 904 | return Instantiator.TransformType(T); |
| 905 | } |
| 906 | |
| 907 | /// Deprecated form of the above. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 908 | QualType Sema::SubstType(QualType T, |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 909 | const MultiLevelTemplateArgumentList &TemplateArgs, |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 910 | SourceLocation Loc, DeclarationName Entity) { |
Douglas Gregor | df667e7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 911 | assert(!ActiveTemplateInstantiations.empty() && |
| 912 | "Cannot perform an instantiation without some context on the " |
| 913 | "instantiation stack"); |
| 914 | |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 915 | // If T is not a dependent type, there is nothing to do. |
| 916 | if (!T->isDependentType()) |
| 917 | return T; |
| 918 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 919 | TemplateInstantiator Instantiator(*this, TemplateArgs, Loc, Entity); |
| 920 | return Instantiator.TransformType(T); |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 921 | } |
Douglas Gregor | 2943aed | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 922 | |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 923 | /// \brief Perform substitution on the base class specifiers of the |
| 924 | /// given class template specialization. |
Douglas Gregor | 2943aed | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 925 | /// |
| 926 | /// Produces a diagnostic and returns true on error, returns false and |
| 927 | /// attaches the instantiated base classes to the class template |
| 928 | /// specialization if successful. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 929 | bool |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 930 | Sema::SubstBaseSpecifiers(CXXRecordDecl *Instantiation, |
| 931 | CXXRecordDecl *Pattern, |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 932 | const MultiLevelTemplateArgumentList &TemplateArgs) { |
Douglas Gregor | 2943aed | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 933 | bool Invalid = false; |
Douglas Gregor | 0ca20ac | 2009-05-29 18:27:38 +0000 | [diff] [blame] | 934 | llvm::SmallVector<CXXBaseSpecifier*, 4> InstantiatedBases; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 935 | for (ClassTemplateSpecializationDecl::base_class_iterator |
Douglas Gregor | d475b8d | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 936 | Base = Pattern->bases_begin(), BaseEnd = Pattern->bases_end(); |
Douglas Gregor | 27b152f | 2009-03-10 18:52:44 +0000 | [diff] [blame] | 937 | Base != BaseEnd; ++Base) { |
Douglas Gregor | 2943aed | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 938 | if (!Base->getType()->isDependentType()) { |
Anders Carlsson | 51f9404 | 2009-12-03 17:49:57 +0000 | [diff] [blame] | 939 | const CXXRecordDecl *BaseDecl = |
| 940 | cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl()); |
| 941 | |
| 942 | // Make sure to set the attributes from the base. |
| 943 | SetClassDeclAttributesFromBase(Instantiation, BaseDecl, |
| 944 | Base->isVirtual()); |
| 945 | |
Fariborz Jahanian | 71c6e71 | 2009-07-22 17:41:53 +0000 | [diff] [blame] | 946 | InstantiatedBases.push_back(new (Context) CXXBaseSpecifier(*Base)); |
Douglas Gregor | 2943aed | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 947 | continue; |
| 948 | } |
| 949 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 950 | QualType BaseType = SubstType(Base->getType(), |
| 951 | TemplateArgs, |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 952 | Base->getSourceRange().getBegin(), |
| 953 | DeclarationName()); |
Douglas Gregor | 2943aed | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 954 | if (BaseType.isNull()) { |
| 955 | Invalid = true; |
| 956 | continue; |
| 957 | } |
| 958 | |
| 959 | if (CXXBaseSpecifier *InstantiatedBase |
Douglas Gregor | d475b8d | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 960 | = CheckBaseSpecifier(Instantiation, |
Douglas Gregor | 2943aed | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 961 | Base->getSourceRange(), |
| 962 | Base->isVirtual(), |
| 963 | Base->getAccessSpecifierAsWritten(), |
| 964 | BaseType, |
| 965 | /*FIXME: Not totally accurate */ |
| 966 | Base->getSourceRange().getBegin())) |
| 967 | InstantiatedBases.push_back(InstantiatedBase); |
| 968 | else |
| 969 | Invalid = true; |
| 970 | } |
| 971 | |
Douglas Gregor | 27b152f | 2009-03-10 18:52:44 +0000 | [diff] [blame] | 972 | if (!Invalid && |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 973 | AttachBaseSpecifiers(Instantiation, InstantiatedBases.data(), |
Douglas Gregor | 2943aed | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 974 | InstantiatedBases.size())) |
| 975 | Invalid = true; |
| 976 | |
| 977 | return Invalid; |
| 978 | } |
| 979 | |
Douglas Gregor | d475b8d | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 980 | /// \brief Instantiate the definition of a class from a given pattern. |
| 981 | /// |
| 982 | /// \param PointOfInstantiation The point of instantiation within the |
| 983 | /// source code. |
| 984 | /// |
| 985 | /// \param Instantiation is the declaration whose definition is being |
| 986 | /// instantiated. This will be either a class template specialization |
| 987 | /// or a member class of a class template specialization. |
| 988 | /// |
| 989 | /// \param Pattern is the pattern from which the instantiation |
| 990 | /// occurs. This will be either the declaration of a class template or |
| 991 | /// the declaration of a member class of a class template. |
| 992 | /// |
| 993 | /// \param TemplateArgs The template arguments to be substituted into |
| 994 | /// the pattern. |
| 995 | /// |
Douglas Gregor | d0e3daf | 2009-09-04 22:48:11 +0000 | [diff] [blame] | 996 | /// \param TSK the kind of implicit or explicit instantiation to perform. |
Douglas Gregor | 5842ba9 | 2009-08-24 15:23:48 +0000 | [diff] [blame] | 997 | /// |
| 998 | /// \param Complain whether to complain if the class cannot be instantiated due |
| 999 | /// to the lack of a definition. |
| 1000 | /// |
Douglas Gregor | d475b8d | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 1001 | /// \returns true if an error occurred, false otherwise. |
| 1002 | bool |
| 1003 | Sema::InstantiateClass(SourceLocation PointOfInstantiation, |
| 1004 | CXXRecordDecl *Instantiation, CXXRecordDecl *Pattern, |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 1005 | const MultiLevelTemplateArgumentList &TemplateArgs, |
Douglas Gregor | d0e3daf | 2009-09-04 22:48:11 +0000 | [diff] [blame] | 1006 | TemplateSpecializationKind TSK, |
Douglas Gregor | 5842ba9 | 2009-08-24 15:23:48 +0000 | [diff] [blame] | 1007 | bool Complain) { |
Douglas Gregor | d475b8d | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 1008 | bool Invalid = false; |
John McCall | e29ba20 | 2009-08-20 01:44:21 +0000 | [diff] [blame] | 1009 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1010 | CXXRecordDecl *PatternDef |
Douglas Gregor | d475b8d | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 1011 | = cast_or_null<CXXRecordDecl>(Pattern->getDefinition(Context)); |
| 1012 | if (!PatternDef) { |
Douglas Gregor | 5842ba9 | 2009-08-24 15:23:48 +0000 | [diff] [blame] | 1013 | if (!Complain) { |
| 1014 | // Say nothing |
| 1015 | } else if (Pattern == Instantiation->getInstantiatedFromMemberClass()) { |
Douglas Gregor | d475b8d | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 1016 | Diag(PointOfInstantiation, |
| 1017 | diag::err_implicit_instantiate_member_undefined) |
| 1018 | << Context.getTypeDeclType(Instantiation); |
| 1019 | Diag(Pattern->getLocation(), diag::note_member_of_template_here); |
| 1020 | } else { |
Douglas Gregor | 93dfdb1 | 2009-05-13 00:25:59 +0000 | [diff] [blame] | 1021 | Diag(PointOfInstantiation, diag::err_template_instantiate_undefined) |
Douglas Gregor | d0e3daf | 2009-09-04 22:48:11 +0000 | [diff] [blame] | 1022 | << (TSK != TSK_ImplicitInstantiation) |
Douglas Gregor | d475b8d | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 1023 | << Context.getTypeDeclType(Instantiation); |
| 1024 | Diag(Pattern->getLocation(), diag::note_template_decl_here); |
| 1025 | } |
| 1026 | return true; |
| 1027 | } |
| 1028 | Pattern = PatternDef; |
| 1029 | |
Douglas Gregor | 454885e | 2009-10-15 15:54:05 +0000 | [diff] [blame] | 1030 | // \brief Record the point of instantiation. |
| 1031 | if (MemberSpecializationInfo *MSInfo |
| 1032 | = Instantiation->getMemberSpecializationInfo()) { |
| 1033 | MSInfo->setTemplateSpecializationKind(TSK); |
| 1034 | MSInfo->setPointOfInstantiation(PointOfInstantiation); |
Douglas Gregor | 972e6ce | 2009-10-27 06:26:26 +0000 | [diff] [blame] | 1035 | } else if (ClassTemplateSpecializationDecl *Spec |
| 1036 | = dyn_cast<ClassTemplateSpecializationDecl>(Instantiation)) { |
| 1037 | Spec->setTemplateSpecializationKind(TSK); |
| 1038 | Spec->setPointOfInstantiation(PointOfInstantiation); |
Douglas Gregor | 454885e | 2009-10-15 15:54:05 +0000 | [diff] [blame] | 1039 | } |
| 1040 | |
Douglas Gregor | d048bb7 | 2009-03-25 21:23:52 +0000 | [diff] [blame] | 1041 | InstantiatingTemplate Inst(*this, PointOfInstantiation, Instantiation); |
Douglas Gregor | d475b8d | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 1042 | if (Inst) |
| 1043 | return true; |
| 1044 | |
| 1045 | // Enter the scope of this instantiation. We don't use |
| 1046 | // PushDeclContext because we don't have a scope. |
| 1047 | DeclContext *PreviousContext = CurContext; |
| 1048 | CurContext = Instantiation; |
| 1049 | |
| 1050 | // Start the definition of this instantiation. |
| 1051 | Instantiation->startDefinition(); |
| 1052 | |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 1053 | // Do substitution on the base class specifiers. |
| 1054 | if (SubstBaseSpecifiers(Instantiation, Pattern, TemplateArgs)) |
Douglas Gregor | d475b8d | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 1055 | Invalid = true; |
| 1056 | |
Douglas Gregor | 0ca20ac | 2009-05-29 18:27:38 +0000 | [diff] [blame] | 1057 | llvm::SmallVector<DeclPtrTy, 4> Fields; |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 1058 | for (RecordDecl::decl_iterator Member = Pattern->decls_begin(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1059 | MemberEnd = Pattern->decls_end(); |
Douglas Gregor | 6ab3524 | 2009-04-09 21:40:53 +0000 | [diff] [blame] | 1060 | Member != MemberEnd; ++Member) { |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 1061 | Decl *NewMember = SubstDecl(*Member, Instantiation, TemplateArgs); |
Douglas Gregor | d475b8d | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 1062 | if (NewMember) { |
Eli Friedman | 721e77d | 2009-12-07 00:22:08 +0000 | [diff] [blame] | 1063 | if (FieldDecl *Field = dyn_cast<FieldDecl>(NewMember)) |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 1064 | Fields.push_back(DeclPtrTy::make(Field)); |
Eli Friedman | 721e77d | 2009-12-07 00:22:08 +0000 | [diff] [blame] | 1065 | else if (NewMember->isInvalidDecl()) |
| 1066 | Invalid = true; |
Douglas Gregor | d475b8d | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 1067 | } else { |
| 1068 | // FIXME: Eventually, a NULL return will mean that one of the |
Mike Stump | 390b4cc | 2009-05-16 07:39:55 +0000 | [diff] [blame] | 1069 | // instantiations was a semantic disaster, and we'll want to set Invalid = |
| 1070 | // 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] | 1071 | } |
| 1072 | } |
| 1073 | |
| 1074 | // Finish checking fields. |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 1075 | ActOnFields(0, Instantiation->getLocation(), DeclPtrTy::make(Instantiation), |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 1076 | Fields.data(), Fields.size(), SourceLocation(), SourceLocation(), |
Douglas Gregor | d475b8d | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 1077 | 0); |
Douglas Gregor | 1ab537b | 2009-12-03 18:33:45 +0000 | [diff] [blame] | 1078 | CheckCompletedCXXClass(Instantiation); |
Douglas Gregor | 663b5a0 | 2009-10-14 20:14:33 +0000 | [diff] [blame] | 1079 | if (Instantiation->isInvalidDecl()) |
| 1080 | Invalid = true; |
| 1081 | |
Douglas Gregor | d475b8d | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 1082 | // Exit the scope of this instantiation. |
| 1083 | CurContext = PreviousContext; |
| 1084 | |
Douglas Gregor | aba43bb | 2009-05-26 20:50:29 +0000 | [diff] [blame] | 1085 | if (!Invalid) |
| 1086 | Consumer.HandleTagDeclDefinition(Instantiation); |
| 1087 | |
Douglas Gregor | d475b8d | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 1088 | return Invalid; |
| 1089 | } |
| 1090 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1091 | bool |
Douglas Gregor | 2943aed | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 1092 | Sema::InstantiateClassTemplateSpecialization( |
Douglas Gregor | 972e6ce | 2009-10-27 06:26:26 +0000 | [diff] [blame] | 1093 | SourceLocation PointOfInstantiation, |
Douglas Gregor | 2943aed | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 1094 | ClassTemplateSpecializationDecl *ClassTemplateSpec, |
Douglas Gregor | d0e3daf | 2009-09-04 22:48:11 +0000 | [diff] [blame] | 1095 | TemplateSpecializationKind TSK, |
Douglas Gregor | 5842ba9 | 2009-08-24 15:23:48 +0000 | [diff] [blame] | 1096 | bool Complain) { |
Douglas Gregor | 2943aed | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 1097 | // Perform the actual instantiation on the canonical declaration. |
| 1098 | ClassTemplateSpec = cast<ClassTemplateSpecializationDecl>( |
Argyrios Kyrtzidis | 97fbaa2 | 2009-07-18 00:34:25 +0000 | [diff] [blame] | 1099 | ClassTemplateSpec->getCanonicalDecl()); |
Douglas Gregor | 2943aed | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 1100 | |
Douglas Gregor | 52604ab | 2009-09-11 21:19:12 +0000 | [diff] [blame] | 1101 | // Check whether we have already instantiated or specialized this class |
| 1102 | // template specialization. |
| 1103 | if (ClassTemplateSpec->getSpecializationKind() != TSK_Undeclared) { |
| 1104 | if (ClassTemplateSpec->getSpecializationKind() == |
| 1105 | TSK_ExplicitInstantiationDeclaration && |
| 1106 | TSK == TSK_ExplicitInstantiationDefinition) { |
| 1107 | // An explicit instantiation definition follows an explicit instantiation |
| 1108 | // declaration (C++0x [temp.explicit]p10); go ahead and perform the |
| 1109 | // explicit instantiation. |
| 1110 | ClassTemplateSpec->setSpecializationKind(TSK); |
Douglas Gregor | 52604ab | 2009-09-11 21:19:12 +0000 | [diff] [blame] | 1111 | return false; |
| 1112 | } |
| 1113 | |
| 1114 | // We can only instantiate something that hasn't already been |
| 1115 | // instantiated or specialized. Fail without any diagnostics: our |
| 1116 | // caller will provide an error message. |
Douglas Gregor | 2943aed | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 1117 | return true; |
Douglas Gregor | 52604ab | 2009-09-11 21:19:12 +0000 | [diff] [blame] | 1118 | } |
Douglas Gregor | 2943aed | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 1119 | |
Douglas Gregor | 9eea08b | 2009-09-15 16:51:42 +0000 | [diff] [blame] | 1120 | if (ClassTemplateSpec->isInvalidDecl()) |
| 1121 | return true; |
| 1122 | |
Douglas Gregor | 2943aed | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 1123 | ClassTemplateDecl *Template = ClassTemplateSpec->getSpecializedTemplate(); |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 1124 | CXXRecordDecl *Pattern = 0; |
Douglas Gregor | c8ab256 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 1125 | |
Douglas Gregor | c1efb3f | 2009-06-12 22:31:52 +0000 | [diff] [blame] | 1126 | // C++ [temp.class.spec.match]p1: |
| 1127 | // When a class template is used in a context that requires an |
| 1128 | // instantiation of the class, it is necessary to determine |
| 1129 | // whether the instantiation is to be generated using the primary |
| 1130 | // template or one of the partial specializations. This is done by |
| 1131 | // matching the template arguments of the class template |
| 1132 | // specialization with the template argument lists of the partial |
| 1133 | // specializations. |
Douglas Gregor | 199d991 | 2009-06-05 00:53:49 +0000 | [diff] [blame] | 1134 | typedef std::pair<ClassTemplatePartialSpecializationDecl *, |
| 1135 | TemplateArgumentList *> MatchResult; |
| 1136 | llvm::SmallVector<MatchResult, 4> Matched; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1137 | for (llvm::FoldingSet<ClassTemplatePartialSpecializationDecl>::iterator |
Douglas Gregor | c8ab256 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 1138 | Partial = Template->getPartialSpecializations().begin(), |
| 1139 | PartialEnd = Template->getPartialSpecializations().end(); |
| 1140 | Partial != PartialEnd; |
| 1141 | ++Partial) { |
Douglas Gregor | f67875d | 2009-06-12 18:26:56 +0000 | [diff] [blame] | 1142 | TemplateDeductionInfo Info(Context); |
| 1143 | if (TemplateDeductionResult Result |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1144 | = DeduceTemplateArguments(&*Partial, |
Douglas Gregor | f67875d | 2009-06-12 18:26:56 +0000 | [diff] [blame] | 1145 | ClassTemplateSpec->getTemplateArgs(), |
| 1146 | Info)) { |
| 1147 | // FIXME: Store the failed-deduction information for use in |
| 1148 | // diagnostics, later. |
| 1149 | (void)Result; |
| 1150 | } else { |
| 1151 | Matched.push_back(std::make_pair(&*Partial, Info.take())); |
| 1152 | } |
Douglas Gregor | c8ab256 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 1153 | } |
| 1154 | |
Douglas Gregor | ed9c0f9 | 2009-10-29 00:04:11 +0000 | [diff] [blame] | 1155 | if (Matched.size() >= 1) { |
Douglas Gregor | bf4ea56 | 2009-09-15 16:23:51 +0000 | [diff] [blame] | 1156 | llvm::SmallVector<MatchResult, 4>::iterator Best = Matched.begin(); |
Douglas Gregor | ed9c0f9 | 2009-10-29 00:04:11 +0000 | [diff] [blame] | 1157 | if (Matched.size() == 1) { |
| 1158 | // -- If exactly one matching specialization is found, the |
| 1159 | // instantiation is generated from that specialization. |
| 1160 | // We don't need to do anything for this. |
| 1161 | } else { |
| 1162 | // -- If more than one matching specialization is found, the |
| 1163 | // partial order rules (14.5.4.2) are used to determine |
| 1164 | // whether one of the specializations is more specialized |
| 1165 | // than the others. If none of the specializations is more |
| 1166 | // specialized than all of the other matching |
| 1167 | // specializations, then the use of the class template is |
| 1168 | // ambiguous and the program is ill-formed. |
| 1169 | for (llvm::SmallVector<MatchResult, 4>::iterator P = Best + 1, |
| 1170 | PEnd = Matched.end(); |
| 1171 | P != PEnd; ++P) { |
| 1172 | if (getMoreSpecializedPartialSpecialization(P->first, Best->first) |
| 1173 | == P->first) |
| 1174 | Best = P; |
Douglas Gregor | bf4ea56 | 2009-09-15 16:23:51 +0000 | [diff] [blame] | 1175 | } |
Douglas Gregor | bf4ea56 | 2009-09-15 16:23:51 +0000 | [diff] [blame] | 1176 | |
Douglas Gregor | ed9c0f9 | 2009-10-29 00:04:11 +0000 | [diff] [blame] | 1177 | // Determine if the best partial specialization is more specialized than |
| 1178 | // the others. |
| 1179 | bool Ambiguous = false; |
Douglas Gregor | bf4ea56 | 2009-09-15 16:23:51 +0000 | [diff] [blame] | 1180 | for (llvm::SmallVector<MatchResult, 4>::iterator P = Matched.begin(), |
| 1181 | PEnd = Matched.end(); |
Douglas Gregor | ed9c0f9 | 2009-10-29 00:04:11 +0000 | [diff] [blame] | 1182 | P != PEnd; ++P) { |
| 1183 | if (P != Best && |
| 1184 | getMoreSpecializedPartialSpecialization(P->first, Best->first) |
| 1185 | != Best->first) { |
| 1186 | Ambiguous = true; |
| 1187 | break; |
| 1188 | } |
| 1189 | } |
| 1190 | |
| 1191 | if (Ambiguous) { |
| 1192 | // Partial ordering did not produce a clear winner. Complain. |
| 1193 | ClassTemplateSpec->setInvalidDecl(); |
| 1194 | Diag(PointOfInstantiation, diag::err_partial_spec_ordering_ambiguous) |
| 1195 | << ClassTemplateSpec; |
| 1196 | |
| 1197 | // Print the matching partial specializations. |
| 1198 | for (llvm::SmallVector<MatchResult, 4>::iterator P = Matched.begin(), |
| 1199 | PEnd = Matched.end(); |
| 1200 | P != PEnd; ++P) |
| 1201 | Diag(P->first->getLocation(), diag::note_partial_spec_match) |
| 1202 | << getTemplateArgumentBindingsText(P->first->getTemplateParameters(), |
| 1203 | *P->second); |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 1204 | |
Douglas Gregor | ed9c0f9 | 2009-10-29 00:04:11 +0000 | [diff] [blame] | 1205 | return true; |
| 1206 | } |
Douglas Gregor | bf4ea56 | 2009-09-15 16:23:51 +0000 | [diff] [blame] | 1207 | } |
| 1208 | |
| 1209 | // Instantiate using the best class template partial specialization. |
Douglas Gregor | ed9c0f9 | 2009-10-29 00:04:11 +0000 | [diff] [blame] | 1210 | ClassTemplatePartialSpecializationDecl *OrigPartialSpec = Best->first; |
| 1211 | while (OrigPartialSpec->getInstantiatedFromMember()) { |
| 1212 | // If we've found an explicit specialization of this class template, |
| 1213 | // stop here and use that as the pattern. |
| 1214 | if (OrigPartialSpec->isMemberSpecialization()) |
| 1215 | break; |
| 1216 | |
| 1217 | OrigPartialSpec = OrigPartialSpec->getInstantiatedFromMember(); |
| 1218 | } |
| 1219 | |
| 1220 | Pattern = OrigPartialSpec; |
Douglas Gregor | bf4ea56 | 2009-09-15 16:23:51 +0000 | [diff] [blame] | 1221 | ClassTemplateSpec->setInstantiationOf(Best->first, Best->second); |
Douglas Gregor | c1efb3f | 2009-06-12 22:31:52 +0000 | [diff] [blame] | 1222 | } else { |
| 1223 | // -- If no matches are found, the instantiation is generated |
| 1224 | // from the primary template. |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 1225 | ClassTemplateDecl *OrigTemplate = Template; |
Douglas Gregor | fd056bc | 2009-10-13 16:30:37 +0000 | [diff] [blame] | 1226 | while (OrigTemplate->getInstantiatedFromMemberTemplate()) { |
| 1227 | // If we've found an explicit specialization of this class template, |
| 1228 | // stop here and use that as the pattern. |
| 1229 | if (OrigTemplate->isMemberSpecialization()) |
| 1230 | break; |
| 1231 | |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 1232 | OrigTemplate = OrigTemplate->getInstantiatedFromMemberTemplate(); |
Douglas Gregor | fd056bc | 2009-10-13 16:30:37 +0000 | [diff] [blame] | 1233 | } |
| 1234 | |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 1235 | Pattern = OrigTemplate->getTemplatedDecl(); |
Douglas Gregor | c8ab256 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 1236 | } |
Douglas Gregor | 2943aed | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 1237 | |
Douglas Gregor | 972e6ce | 2009-10-27 06:26:26 +0000 | [diff] [blame] | 1238 | bool Result = InstantiateClass(PointOfInstantiation, ClassTemplateSpec, |
| 1239 | Pattern, |
| 1240 | getTemplateInstantiationArgs(ClassTemplateSpec), |
Douglas Gregor | d0e3daf | 2009-09-04 22:48:11 +0000 | [diff] [blame] | 1241 | TSK, |
Douglas Gregor | 5842ba9 | 2009-08-24 15:23:48 +0000 | [diff] [blame] | 1242 | Complain); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1243 | |
Douglas Gregor | 199d991 | 2009-06-05 00:53:49 +0000 | [diff] [blame] | 1244 | for (unsigned I = 0, N = Matched.size(); I != N; ++I) { |
| 1245 | // FIXME: Implement TemplateArgumentList::Destroy! |
| 1246 | // if (Matched[I].first != Pattern) |
| 1247 | // Matched[I].second->Destroy(Context); |
| 1248 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1249 | |
Douglas Gregor | 199d991 | 2009-06-05 00:53:49 +0000 | [diff] [blame] | 1250 | return Result; |
Douglas Gregor | 2943aed | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 1251 | } |
Douglas Gregor | 5953d8b | 2009-03-19 17:26:29 +0000 | [diff] [blame] | 1252 | |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 1253 | /// \brief Instantiates the definitions of all of the member |
| 1254 | /// of the given class, which is an instantiation of a class template |
| 1255 | /// or a member class of a template. |
Douglas Gregor | a58861f | 2009-05-13 20:28:22 +0000 | [diff] [blame] | 1256 | void |
| 1257 | Sema::InstantiateClassMembers(SourceLocation PointOfInstantiation, |
Douglas Gregor | d0e3daf | 2009-09-04 22:48:11 +0000 | [diff] [blame] | 1258 | CXXRecordDecl *Instantiation, |
| 1259 | const MultiLevelTemplateArgumentList &TemplateArgs, |
| 1260 | TemplateSpecializationKind TSK) { |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 1261 | for (DeclContext::decl_iterator D = Instantiation->decls_begin(), |
| 1262 | DEnd = Instantiation->decls_end(); |
Douglas Gregor | a58861f | 2009-05-13 20:28:22 +0000 | [diff] [blame] | 1263 | D != DEnd; ++D) { |
Douglas Gregor | 0d03514 | 2009-10-27 18:42:08 +0000 | [diff] [blame] | 1264 | bool SuppressNew = false; |
Douglas Gregor | a58861f | 2009-05-13 20:28:22 +0000 | [diff] [blame] | 1265 | if (FunctionDecl *Function = dyn_cast<FunctionDecl>(*D)) { |
Douglas Gregor | 0d03514 | 2009-10-27 18:42:08 +0000 | [diff] [blame] | 1266 | if (FunctionDecl *Pattern |
| 1267 | = Function->getInstantiatedFromMemberFunction()) { |
| 1268 | MemberSpecializationInfo *MSInfo |
| 1269 | = Function->getMemberSpecializationInfo(); |
| 1270 | assert(MSInfo && "No member specialization information?"); |
| 1271 | if (CheckSpecializationInstantiationRedecl(PointOfInstantiation, TSK, |
| 1272 | Function, |
| 1273 | MSInfo->getTemplateSpecializationKind(), |
| 1274 | MSInfo->getPointOfInstantiation(), |
| 1275 | SuppressNew) || |
| 1276 | SuppressNew) |
Douglas Gregor | f6b1185 | 2009-10-08 15:14:33 +0000 | [diff] [blame] | 1277 | continue; |
| 1278 | |
Douglas Gregor | 0d03514 | 2009-10-27 18:42:08 +0000 | [diff] [blame] | 1279 | if (Function->getBody()) |
| 1280 | continue; |
| 1281 | |
| 1282 | if (TSK == TSK_ExplicitInstantiationDefinition) { |
| 1283 | // C++0x [temp.explicit]p8: |
| 1284 | // An explicit instantiation definition that names a class template |
| 1285 | // specialization explicitly instantiates the class template |
| 1286 | // specialization and is only an explicit instantiation definition |
| 1287 | // of members whose definition is visible at the point of |
| 1288 | // instantiation. |
| 1289 | if (!Pattern->getBody()) |
| 1290 | continue; |
| 1291 | |
| 1292 | Function->setTemplateSpecializationKind(TSK, PointOfInstantiation); |
| 1293 | |
| 1294 | InstantiateFunctionDefinition(PointOfInstantiation, Function); |
| 1295 | } else { |
| 1296 | Function->setTemplateSpecializationKind(TSK, PointOfInstantiation); |
| 1297 | } |
Douglas Gregor | f6b1185 | 2009-10-08 15:14:33 +0000 | [diff] [blame] | 1298 | } |
Douglas Gregor | a58861f | 2009-05-13 20:28:22 +0000 | [diff] [blame] | 1299 | } else if (VarDecl *Var = dyn_cast<VarDecl>(*D)) { |
Douglas Gregor | 251b4ff | 2009-10-08 07:24:58 +0000 | [diff] [blame] | 1300 | if (Var->isStaticDataMember()) { |
Douglas Gregor | 0d03514 | 2009-10-27 18:42:08 +0000 | [diff] [blame] | 1301 | MemberSpecializationInfo *MSInfo = Var->getMemberSpecializationInfo(); |
| 1302 | assert(MSInfo && "No member specialization information?"); |
| 1303 | if (CheckSpecializationInstantiationRedecl(PointOfInstantiation, TSK, |
| 1304 | Var, |
| 1305 | MSInfo->getTemplateSpecializationKind(), |
| 1306 | MSInfo->getPointOfInstantiation(), |
| 1307 | SuppressNew) || |
| 1308 | SuppressNew) |
Douglas Gregor | f6b1185 | 2009-10-08 15:14:33 +0000 | [diff] [blame] | 1309 | continue; |
| 1310 | |
Douglas Gregor | 0d03514 | 2009-10-27 18:42:08 +0000 | [diff] [blame] | 1311 | if (TSK == TSK_ExplicitInstantiationDefinition) { |
| 1312 | // C++0x [temp.explicit]p8: |
| 1313 | // An explicit instantiation definition that names a class template |
| 1314 | // specialization explicitly instantiates the class template |
| 1315 | // specialization and is only an explicit instantiation definition |
| 1316 | // of members whose definition is visible at the point of |
| 1317 | // instantiation. |
| 1318 | if (!Var->getInstantiatedFromStaticDataMember() |
| 1319 | ->getOutOfLineDefinition()) |
| 1320 | continue; |
| 1321 | |
| 1322 | Var->setTemplateSpecializationKind(TSK, PointOfInstantiation); |
Douglas Gregor | 251b4ff | 2009-10-08 07:24:58 +0000 | [diff] [blame] | 1323 | InstantiateStaticDataMemberDefinition(PointOfInstantiation, Var); |
Douglas Gregor | 0d03514 | 2009-10-27 18:42:08 +0000 | [diff] [blame] | 1324 | } else { |
| 1325 | Var->setTemplateSpecializationKind(TSK, PointOfInstantiation); |
| 1326 | } |
| 1327 | } |
Douglas Gregor | a58861f | 2009-05-13 20:28:22 +0000 | [diff] [blame] | 1328 | } else if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(*D)) { |
Douglas Gregor | 2db3232 | 2009-10-07 23:56:10 +0000 | [diff] [blame] | 1329 | if (Record->isInjectedClassName()) |
| 1330 | continue; |
| 1331 | |
Douglas Gregor | 0d03514 | 2009-10-27 18:42:08 +0000 | [diff] [blame] | 1332 | MemberSpecializationInfo *MSInfo = Record->getMemberSpecializationInfo(); |
| 1333 | assert(MSInfo && "No member specialization information?"); |
| 1334 | if (CheckSpecializationInstantiationRedecl(PointOfInstantiation, TSK, |
| 1335 | Record, |
| 1336 | MSInfo->getTemplateSpecializationKind(), |
| 1337 | MSInfo->getPointOfInstantiation(), |
| 1338 | SuppressNew) || |
| 1339 | SuppressNew) |
Douglas Gregor | f6b1185 | 2009-10-08 15:14:33 +0000 | [diff] [blame] | 1340 | continue; |
| 1341 | |
Douglas Gregor | 0d03514 | 2009-10-27 18:42:08 +0000 | [diff] [blame] | 1342 | CXXRecordDecl *Pattern = Record->getInstantiatedFromMemberClass(); |
| 1343 | assert(Pattern && "Missing instantiated-from-template information"); |
| 1344 | |
| 1345 | if (!Record->getDefinition(Context)) { |
| 1346 | if (!Pattern->getDefinition(Context)) { |
| 1347 | // C++0x [temp.explicit]p8: |
| 1348 | // An explicit instantiation definition that names a class template |
| 1349 | // specialization explicitly instantiates the class template |
| 1350 | // specialization and is only an explicit instantiation definition |
| 1351 | // of members whose definition is visible at the point of |
| 1352 | // instantiation. |
| 1353 | if (TSK == TSK_ExplicitInstantiationDeclaration) { |
| 1354 | MSInfo->setTemplateSpecializationKind(TSK); |
| 1355 | MSInfo->setPointOfInstantiation(PointOfInstantiation); |
| 1356 | } |
| 1357 | |
| 1358 | continue; |
| 1359 | } |
| 1360 | |
| 1361 | InstantiateClass(PointOfInstantiation, Record, Pattern, |
Douglas Gregor | d0e3daf | 2009-09-04 22:48:11 +0000 | [diff] [blame] | 1362 | TemplateArgs, |
| 1363 | TSK); |
Douglas Gregor | 0d03514 | 2009-10-27 18:42:08 +0000 | [diff] [blame] | 1364 | } |
Douglas Gregor | e9374d5 | 2009-10-08 01:19:17 +0000 | [diff] [blame] | 1365 | |
Douglas Gregor | 0d03514 | 2009-10-27 18:42:08 +0000 | [diff] [blame] | 1366 | Pattern = cast_or_null<CXXRecordDecl>(Record->getDefinition(Context)); |
| 1367 | if (Pattern) |
| 1368 | InstantiateClassMembers(PointOfInstantiation, Pattern, TemplateArgs, |
| 1369 | TSK); |
Douglas Gregor | a58861f | 2009-05-13 20:28:22 +0000 | [diff] [blame] | 1370 | } |
| 1371 | } |
| 1372 | } |
| 1373 | |
| 1374 | /// \brief Instantiate the definitions of all of the members of the |
| 1375 | /// given class template specialization, which was named as part of an |
| 1376 | /// explicit instantiation. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1377 | void |
Douglas Gregor | d0e3daf | 2009-09-04 22:48:11 +0000 | [diff] [blame] | 1378 | Sema::InstantiateClassTemplateSpecializationMembers( |
Douglas Gregor | a58861f | 2009-05-13 20:28:22 +0000 | [diff] [blame] | 1379 | SourceLocation PointOfInstantiation, |
Douglas Gregor | d0e3daf | 2009-09-04 22:48:11 +0000 | [diff] [blame] | 1380 | ClassTemplateSpecializationDecl *ClassTemplateSpec, |
| 1381 | TemplateSpecializationKind TSK) { |
Douglas Gregor | a58861f | 2009-05-13 20:28:22 +0000 | [diff] [blame] | 1382 | // C++0x [temp.explicit]p7: |
| 1383 | // An explicit instantiation that names a class template |
| 1384 | // specialization is an explicit instantion of the same kind |
| 1385 | // (declaration or definition) of each of its members (not |
| 1386 | // including members inherited from base classes) that has not |
| 1387 | // been previously explicitly specialized in the translation unit |
| 1388 | // containing the explicit instantiation, except as described |
| 1389 | // below. |
| 1390 | InstantiateClassMembers(PointOfInstantiation, ClassTemplateSpec, |
Douglas Gregor | d0e3daf | 2009-09-04 22:48:11 +0000 | [diff] [blame] | 1391 | getTemplateInstantiationArgs(ClassTemplateSpec), |
| 1392 | TSK); |
Douglas Gregor | a58861f | 2009-05-13 20:28:22 +0000 | [diff] [blame] | 1393 | } |
| 1394 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1395 | Sema::OwningStmtResult |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 1396 | Sema::SubstStmt(Stmt *S, const MultiLevelTemplateArgumentList &TemplateArgs) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1397 | if (!S) |
| 1398 | return Owned(S); |
| 1399 | |
| 1400 | TemplateInstantiator Instantiator(*this, TemplateArgs, |
| 1401 | SourceLocation(), |
| 1402 | DeclarationName()); |
| 1403 | return Instantiator.TransformStmt(S); |
| 1404 | } |
| 1405 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1406 | Sema::OwningExprResult |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 1407 | Sema::SubstExpr(Expr *E, const MultiLevelTemplateArgumentList &TemplateArgs) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1408 | if (!E) |
| 1409 | return Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1410 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1411 | TemplateInstantiator Instantiator(*this, TemplateArgs, |
| 1412 | SourceLocation(), |
| 1413 | DeclarationName()); |
| 1414 | return Instantiator.TransformExpr(E); |
| 1415 | } |
| 1416 | |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 1417 | /// \brief Do template substitution on a nested-name-specifier. |
Douglas Gregor | ab452ba | 2009-03-26 23:50:42 +0000 | [diff] [blame] | 1418 | NestedNameSpecifier * |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 1419 | Sema::SubstNestedNameSpecifier(NestedNameSpecifier *NNS, |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 1420 | SourceRange Range, |
| 1421 | const MultiLevelTemplateArgumentList &TemplateArgs) { |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1422 | TemplateInstantiator Instantiator(*this, TemplateArgs, Range.getBegin(), |
| 1423 | DeclarationName()); |
| 1424 | return Instantiator.TransformNestedNameSpecifier(NNS, Range); |
Douglas Gregor | 5953d8b | 2009-03-19 17:26:29 +0000 | [diff] [blame] | 1425 | } |
Douglas Gregor | de650ae | 2009-03-31 18:38:02 +0000 | [diff] [blame] | 1426 | |
| 1427 | TemplateName |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 1428 | Sema::SubstTemplateName(TemplateName Name, SourceLocation Loc, |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 1429 | const MultiLevelTemplateArgumentList &TemplateArgs) { |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1430 | TemplateInstantiator Instantiator(*this, TemplateArgs, Loc, |
| 1431 | DeclarationName()); |
| 1432 | return Instantiator.TransformTemplateName(Name); |
Douglas Gregor | de650ae | 2009-03-31 18:38:02 +0000 | [diff] [blame] | 1433 | } |
Douglas Gregor | 9133300 | 2009-06-11 00:06:24 +0000 | [diff] [blame] | 1434 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1435 | bool Sema::Subst(const TemplateArgumentLoc &Input, TemplateArgumentLoc &Output, |
| 1436 | const MultiLevelTemplateArgumentList &TemplateArgs) { |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1437 | TemplateInstantiator Instantiator(*this, TemplateArgs, SourceLocation(), |
| 1438 | DeclarationName()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1439 | |
| 1440 | return Instantiator.TransformTemplateArgument(Input, Output); |
Douglas Gregor | 9133300 | 2009-06-11 00:06:24 +0000 | [diff] [blame] | 1441 | } |