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