| Douglas Gregor | fe1e110 | 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 |  | 
| John McCall | 8302463 | 2010-08-25 22:03:47 +0000 | [diff] [blame] | 13 | #include "clang/Sema/SemaInternal.h" | 
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 14 | #include "TreeTransform.h" | 
| Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 15 | #include "clang/AST/ASTConsumer.h" | 
|  | 16 | #include "clang/AST/ASTContext.h" | 
| Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 17 | #include "clang/AST/ASTLambda.h" | 
| Richard Smith | 4b054b2 | 2016-08-24 21:25:37 +0000 | [diff] [blame] | 18 | #include "clang/AST/ASTMutationListener.h" | 
| Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 19 | #include "clang/AST/DeclTemplate.h" | 
|  | 20 | #include "clang/AST/Expr.h" | 
| Jordan Rose | 1e879d8 | 2018-03-23 00:07:18 +0000 | [diff] [blame] | 21 | #include "clang/AST/PrettyDeclStackTrace.h" | 
| Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 22 | #include "clang/Basic/LangOptions.h" | 
| John McCall | 8b0666c | 2010-08-20 18:27:03 +0000 | [diff] [blame] | 23 | #include "clang/Sema/DeclSpec.h" | 
| Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 24 | #include "clang/Sema/Initialization.h" | 
| Douglas Gregor | c3a6ade | 2010-08-12 20:07:10 +0000 | [diff] [blame] | 25 | #include "clang/Sema/Lookup.h" | 
| John McCall | de6836a | 2010-08-24 07:21:54 +0000 | [diff] [blame] | 26 | #include "clang/Sema/Template.h" | 
| John McCall | 19c1bfd | 2010-08-25 05:32:35 +0000 | [diff] [blame] | 27 | #include "clang/Sema/TemplateDeduction.h" | 
| Gabor Horvath | 207e7b1 | 2018-02-10 14:04:45 +0000 | [diff] [blame] | 28 | #include "clang/Sema/TemplateInstCallback.h" | 
| Douglas Gregor | fe1e110 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 29 |  | 
|  | 30 | using namespace clang; | 
| John McCall | 19c1bfd | 2010-08-25 05:32:35 +0000 | [diff] [blame] | 31 | using namespace sema; | 
| Douglas Gregor | fe1e110 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 32 |  | 
| Douglas Gregor | 4ea568f | 2009-03-10 18:03:33 +0000 | [diff] [blame] | 33 | //===----------------------------------------------------------------------===/ | 
|  | 34 | // Template Instantiation Support | 
|  | 35 | //===----------------------------------------------------------------------===/ | 
|  | 36 |  | 
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 37 | /// Retrieve the template argument list(s) that should be used to | 
| Douglas Gregor | 01afeef | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 38 | /// instantiate the definition of the given declaration. | 
| Douglas Gregor | 36d7c5f | 2009-11-09 19:17:50 +0000 | [diff] [blame] | 39 | /// | 
|  | 40 | /// \param D the declaration for which we are computing template instantiation | 
|  | 41 | /// arguments. | 
|  | 42 | /// | 
|  | 43 | /// \param Innermost if non-NULL, the innermost template argument list. | 
| Douglas Gregor | 8c70253 | 2010-02-05 07:33:43 +0000 | [diff] [blame] | 44 | /// | 
|  | 45 | /// \param RelativeToPrimary true if we should get the template | 
|  | 46 | /// arguments relative to the primary template, even when we're | 
|  | 47 | /// dealing with a specialization. This is only relevant for function | 
|  | 48 | /// template specializations. | 
| Douglas Gregor | 1bd7a94 | 2010-05-03 23:29:10 +0000 | [diff] [blame] | 49 | /// | 
|  | 50 | /// \param Pattern If non-NULL, indicates the pattern from which we will be | 
|  | 51 | /// instantiating the definition of the given declaration, \p D. This is | 
|  | 52 | /// used to determine the proper set of template instantiation arguments for | 
|  | 53 | /// friend function template specializations. | 
| Douglas Gregor | a654dd8 | 2009-08-28 17:37:35 +0000 | [diff] [blame] | 54 | MultiLevelTemplateArgumentList | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 55 | Sema::getTemplateInstantiationArgs(NamedDecl *D, | 
| Douglas Gregor | 8c70253 | 2010-02-05 07:33:43 +0000 | [diff] [blame] | 56 | const TemplateArgumentList *Innermost, | 
| Douglas Gregor | 1bd7a94 | 2010-05-03 23:29:10 +0000 | [diff] [blame] | 57 | bool RelativeToPrimary, | 
|  | 58 | const FunctionDecl *Pattern) { | 
| Douglas Gregor | a654dd8 | 2009-08-28 17:37:35 +0000 | [diff] [blame] | 59 | // Accumulate the set of template argument lists in this structure. | 
|  | 60 | MultiLevelTemplateArgumentList Result; | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 61 |  | 
| Douglas Gregor | 36d7c5f | 2009-11-09 19:17:50 +0000 | [diff] [blame] | 62 | if (Innermost) | 
|  | 63 | Result.addOuterTemplateArguments(Innermost); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 64 |  | 
| Douglas Gregor | a654dd8 | 2009-08-28 17:37:35 +0000 | [diff] [blame] | 65 | DeclContext *Ctx = dyn_cast<DeclContext>(D); | 
| Douglas Gregor | a51c9cc | 2011-05-22 00:21:10 +0000 | [diff] [blame] | 66 | if (!Ctx) { | 
| Douglas Gregor | a654dd8 | 2009-08-28 17:37:35 +0000 | [diff] [blame] | 67 | Ctx = D->getDeclContext(); | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 68 |  | 
|  | 69 | // Add template arguments from a variable template instantiation. | 
|  | 70 | if (VarTemplateSpecializationDecl *Spec = | 
|  | 71 | dyn_cast<VarTemplateSpecializationDecl>(D)) { | 
|  | 72 | // We're done when we hit an explicit specialization. | 
|  | 73 | if (Spec->getSpecializationKind() == TSK_ExplicitSpecialization && | 
|  | 74 | !isa<VarTemplatePartialSpecializationDecl>(Spec)) | 
|  | 75 | return Result; | 
|  | 76 |  | 
|  | 77 | Result.addOuterTemplateArguments(&Spec->getTemplateInstantiationArgs()); | 
|  | 78 |  | 
|  | 79 | // If this variable template specialization was instantiated from a | 
|  | 80 | // specialized member that is a variable template, we're done. | 
|  | 81 | assert(Spec->getSpecializedTemplate() && "No variable template?"); | 
| Richard Smith | beef345 | 2014-01-16 23:39:20 +0000 | [diff] [blame] | 82 | llvm::PointerUnion<VarTemplateDecl*, | 
|  | 83 | VarTemplatePartialSpecializationDecl*> Specialized | 
|  | 84 | = Spec->getSpecializedTemplateOrPartial(); | 
|  | 85 | if (VarTemplatePartialSpecializationDecl *Partial = | 
|  | 86 | Specialized.dyn_cast<VarTemplatePartialSpecializationDecl *>()) { | 
|  | 87 | if (Partial->isMemberSpecialization()) | 
|  | 88 | return Result; | 
|  | 89 | } else { | 
|  | 90 | VarTemplateDecl *Tmpl = Specialized.get<VarTemplateDecl *>(); | 
|  | 91 | if (Tmpl->isMemberSpecialization()) | 
|  | 92 | return Result; | 
|  | 93 | } | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 94 | } | 
|  | 95 |  | 
| Douglas Gregor | 5546262 | 2011-06-15 14:20:42 +0000 | [diff] [blame] | 96 | // If we have a template template parameter with translation unit context, | 
|  | 97 | // then we're performing substitution into a default template argument of | 
|  | 98 | // this template template parameter before we've constructed the template | 
|  | 99 | // that will own this template template parameter. In this case, we | 
|  | 100 | // use empty template parameter lists for all of the outer templates | 
|  | 101 | // to avoid performing any substitutions. | 
|  | 102 | if (Ctx->isTranslationUnit()) { | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 103 | if (TemplateTemplateParmDecl *TTP | 
| Douglas Gregor | 5546262 | 2011-06-15 14:20:42 +0000 | [diff] [blame] | 104 | = dyn_cast<TemplateTemplateParmDecl>(D)) { | 
|  | 105 | for (unsigned I = 0, N = TTP->getDepth() + 1; I != N; ++I) | 
| Richard Smith | 841d8b2 | 2013-05-17 03:04:50 +0000 | [diff] [blame] | 106 | Result.addOuterTemplateArguments(None); | 
| Douglas Gregor | 5546262 | 2011-06-15 14:20:42 +0000 | [diff] [blame] | 107 | return Result; | 
|  | 108 | } | 
|  | 109 | } | 
| Douglas Gregor | a51c9cc | 2011-05-22 00:21:10 +0000 | [diff] [blame] | 110 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 111 |  | 
| John McCall | 970d530 | 2009-08-29 03:16:09 +0000 | [diff] [blame] | 112 | while (!Ctx->isFileContext()) { | 
| Douglas Gregor | a654dd8 | 2009-08-28 17:37:35 +0000 | [diff] [blame] | 113 | // Add template arguments from a class template instantiation. | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 114 | if (ClassTemplateSpecializationDecl *Spec | 
| Douglas Gregor | a654dd8 | 2009-08-28 17:37:35 +0000 | [diff] [blame] | 115 | = dyn_cast<ClassTemplateSpecializationDecl>(Ctx)) { | 
|  | 116 | // We're done when we hit an explicit specialization. | 
| Douglas Gregor | 9961ce9 | 2010-07-08 18:37:38 +0000 | [diff] [blame] | 117 | if (Spec->getSpecializationKind() == TSK_ExplicitSpecialization && | 
|  | 118 | !isa<ClassTemplatePartialSpecializationDecl>(Spec)) | 
| Douglas Gregor | a654dd8 | 2009-08-28 17:37:35 +0000 | [diff] [blame] | 119 | break; | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 120 |  | 
| Douglas Gregor | a654dd8 | 2009-08-28 17:37:35 +0000 | [diff] [blame] | 121 | Result.addOuterTemplateArguments(&Spec->getTemplateInstantiationArgs()); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 122 |  | 
|  | 123 | // If this class template specialization was instantiated from a | 
| Douglas Gregor | cf91555 | 2009-10-13 16:30:37 +0000 | [diff] [blame] | 124 | // specialized member that is a class template, we're done. | 
|  | 125 | assert(Spec->getSpecializedTemplate() && "No class template?"); | 
|  | 126 | if (Spec->getSpecializedTemplate()->isMemberSpecialization()) | 
|  | 127 | break; | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 128 | } | 
| Douglas Gregor | a654dd8 | 2009-08-28 17:37:35 +0000 | [diff] [blame] | 129 | // Add template arguments from a function template specialization. | 
| John McCall | 970d530 | 2009-08-29 03:16:09 +0000 | [diff] [blame] | 130 | else if (FunctionDecl *Function = dyn_cast<FunctionDecl>(Ctx)) { | 
| Douglas Gregor | 8c70253 | 2010-02-05 07:33:43 +0000 | [diff] [blame] | 131 | if (!RelativeToPrimary && | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 132 | (Function->getTemplateSpecializationKind() == | 
| Francois Pichet | 00c7e6c | 2011-08-14 03:52:19 +0000 | [diff] [blame] | 133 | TSK_ExplicitSpecialization && | 
|  | 134 | !Function->getClassScopeSpecializationPattern())) | 
| Douglas Gregor | cf91555 | 2009-10-13 16:30:37 +0000 | [diff] [blame] | 135 | break; | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 136 |  | 
| Douglas Gregor | a654dd8 | 2009-08-28 17:37:35 +0000 | [diff] [blame] | 137 | if (const TemplateArgumentList *TemplateArgs | 
| Douglas Gregor | cf91555 | 2009-10-13 16:30:37 +0000 | [diff] [blame] | 138 | = Function->getTemplateSpecializationArgs()) { | 
|  | 139 | // Add the template arguments for this specialization. | 
| Douglas Gregor | a654dd8 | 2009-08-28 17:37:35 +0000 | [diff] [blame] | 140 | Result.addOuterTemplateArguments(TemplateArgs); | 
| John McCall | 970d530 | 2009-08-29 03:16:09 +0000 | [diff] [blame] | 141 |  | 
| Douglas Gregor | cf91555 | 2009-10-13 16:30:37 +0000 | [diff] [blame] | 142 | // If this function was instantiated from a specialized member that is | 
|  | 143 | // a function template, we're done. | 
|  | 144 | assert(Function->getPrimaryTemplate() && "No function template?"); | 
|  | 145 | if (Function->getPrimaryTemplate()->isMemberSpecialization()) | 
|  | 146 | break; | 
| Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 147 |  | 
|  | 148 | // If this function is a generic lambda specialization, we are done. | 
|  | 149 | if (isGenericLambdaCallOperatorSpecialization(Function)) | 
|  | 150 | break; | 
|  | 151 |  | 
| Douglas Gregor | 43669f8 | 2011-03-05 17:54:25 +0000 | [diff] [blame] | 152 | } else if (FunctionTemplateDecl *FunTmpl | 
|  | 153 | = Function->getDescribedFunctionTemplate()) { | 
|  | 154 | // Add the "injected" template arguments. | 
| Richard Smith | 841d8b2 | 2013-05-17 03:04:50 +0000 | [diff] [blame] | 155 | Result.addOuterTemplateArguments(FunTmpl->getInjectedTemplateArgs()); | 
| Douglas Gregor | cf91555 | 2009-10-13 16:30:37 +0000 | [diff] [blame] | 156 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 157 |  | 
| John McCall | 970d530 | 2009-08-29 03:16:09 +0000 | [diff] [blame] | 158 | // If this is a friend declaration and it declares an entity at | 
|  | 159 | // namespace scope, take arguments from its lexical parent | 
| Douglas Gregor | 1bd7a94 | 2010-05-03 23:29:10 +0000 | [diff] [blame] | 160 | // instead of its semantic parent, unless of course the pattern we're | 
|  | 161 | // instantiating actually comes from the file's context! | 
| John McCall | 970d530 | 2009-08-29 03:16:09 +0000 | [diff] [blame] | 162 | if (Function->getFriendObjectKind() && | 
| Douglas Gregor | 1bd7a94 | 2010-05-03 23:29:10 +0000 | [diff] [blame] | 163 | Function->getDeclContext()->isFileContext() && | 
|  | 164 | (!Pattern || !Pattern->getLexicalDeclContext()->isFileContext())) { | 
| John McCall | 970d530 | 2009-08-29 03:16:09 +0000 | [diff] [blame] | 165 | Ctx = Function->getLexicalDeclContext(); | 
| Douglas Gregor | 8c70253 | 2010-02-05 07:33:43 +0000 | [diff] [blame] | 166 | RelativeToPrimary = false; | 
| John McCall | 970d530 | 2009-08-29 03:16:09 +0000 | [diff] [blame] | 167 | continue; | 
|  | 168 | } | 
| Douglas Gregor | 9961ce9 | 2010-07-08 18:37:38 +0000 | [diff] [blame] | 169 | } else if (CXXRecordDecl *Rec = dyn_cast<CXXRecordDecl>(Ctx)) { | 
|  | 170 | if (ClassTemplateDecl *ClassTemplate = Rec->getDescribedClassTemplate()) { | 
|  | 171 | QualType T = ClassTemplate->getInjectedClassNameSpecialization(); | 
| Richard Smith | 841d8b2 | 2013-05-17 03:04:50 +0000 | [diff] [blame] | 172 | const TemplateSpecializationType *TST = | 
|  | 173 | cast<TemplateSpecializationType>(Context.getCanonicalType(T)); | 
|  | 174 | Result.addOuterTemplateArguments( | 
|  | 175 | llvm::makeArrayRef(TST->getArgs(), TST->getNumArgs())); | 
| Douglas Gregor | 9961ce9 | 2010-07-08 18:37:38 +0000 | [diff] [blame] | 176 | if (ClassTemplate->isMemberSpecialization()) | 
|  | 177 | break; | 
|  | 178 | } | 
| Douglas Gregor | a654dd8 | 2009-08-28 17:37:35 +0000 | [diff] [blame] | 179 | } | 
| John McCall | 970d530 | 2009-08-29 03:16:09 +0000 | [diff] [blame] | 180 |  | 
|  | 181 | Ctx = Ctx->getParent(); | 
| Douglas Gregor | 8c70253 | 2010-02-05 07:33:43 +0000 | [diff] [blame] | 182 | RelativeToPrimary = false; | 
| Douglas Gregor | b485046 | 2009-05-14 23:26:13 +0000 | [diff] [blame] | 183 | } | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 184 |  | 
| Douglas Gregor | a654dd8 | 2009-08-28 17:37:35 +0000 | [diff] [blame] | 185 | return Result; | 
| Douglas Gregor | b485046 | 2009-05-14 23:26:13 +0000 | [diff] [blame] | 186 | } | 
|  | 187 |  | 
| Richard Smith | 696e312 | 2017-02-23 01:43:54 +0000 | [diff] [blame] | 188 | bool Sema::CodeSynthesisContext::isInstantiationRecord() const { | 
| Douglas Gregor | 84d49a2 | 2009-11-11 21:54:23 +0000 | [diff] [blame] | 189 | switch (Kind) { | 
|  | 190 | case TemplateInstantiation: | 
| Richard Smith | f623c96 | 2012-04-17 00:58:00 +0000 | [diff] [blame] | 191 | case ExceptionSpecInstantiation: | 
| Douglas Gregor | 84d49a2 | 2009-11-11 21:54:23 +0000 | [diff] [blame] | 192 | case DefaultTemplateArgumentInstantiation: | 
|  | 193 | case DefaultFunctionArgumentInstantiation: | 
| Douglas Gregor | 84d49a2 | 2009-11-11 21:54:23 +0000 | [diff] [blame] | 194 | case ExplicitTemplateArgumentSubstitution: | 
|  | 195 | case DeducedTemplateArgumentSubstitution: | 
|  | 196 | case PriorTemplateArgumentSubstitution: | 
| Richard Smith | 8a874c9 | 2012-07-08 02:38:24 +0000 | [diff] [blame] | 197 | return true; | 
|  | 198 |  | 
| Douglas Gregor | 84d49a2 | 2009-11-11 21:54:23 +0000 | [diff] [blame] | 199 | case DefaultTemplateArgumentChecking: | 
| Richard Smith | 1338122 | 2017-02-23 21:43:43 +0000 | [diff] [blame] | 200 | case DeclaringSpecialMember: | 
| Richard Smith | 883dbc4 | 2017-05-25 22:47:05 +0000 | [diff] [blame] | 201 | case DefiningSynthesizedFunction: | 
| Richard Smith | 5159bbad | 2018-09-05 22:30:37 +0000 | [diff] [blame] | 202 | case ExceptionSpecEvaluation: | 
| Douglas Gregor | 84d49a2 | 2009-11-11 21:54:23 +0000 | [diff] [blame] | 203 | return false; | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 204 |  | 
| Gabor Horvath | 207e7b1 | 2018-02-10 14:04:45 +0000 | [diff] [blame] | 205 | // This function should never be called when Kind's value is Memoization. | 
|  | 206 | case Memoization: | 
|  | 207 | break; | 
| Douglas Gregor | 84d49a2 | 2009-11-11 21:54:23 +0000 | [diff] [blame] | 208 | } | 
| David Blaikie | 8a40f70 | 2012-01-17 06:56:22 +0000 | [diff] [blame] | 209 |  | 
| Richard Smith | 696e312 | 2017-02-23 01:43:54 +0000 | [diff] [blame] | 210 | llvm_unreachable("Invalid SynthesisKind!"); | 
| Douglas Gregor | 84d49a2 | 2009-11-11 21:54:23 +0000 | [diff] [blame] | 211 | } | 
|  | 212 |  | 
| Benjamin Kramer | 7761a04 | 2015-03-06 16:36:50 +0000 | [diff] [blame] | 213 | Sema::InstantiatingTemplate::InstantiatingTemplate( | 
| Richard Smith | 696e312 | 2017-02-23 01:43:54 +0000 | [diff] [blame] | 214 | Sema &SemaRef, CodeSynthesisContext::SynthesisKind Kind, | 
| Stephan Tolksdorf | 232670f | 2014-03-13 20:34:22 +0000 | [diff] [blame] | 215 | SourceLocation PointOfInstantiation, SourceRange InstantiationRange, | 
|  | 216 | Decl *Entity, NamedDecl *Template, ArrayRef<TemplateArgument> TemplateArgs, | 
| Benjamin Kramer | 7761a04 | 2015-03-06 16:36:50 +0000 | [diff] [blame] | 217 | sema::TemplateDeductionInfo *DeductionInfo) | 
| Richard Smith | 1338122 | 2017-02-23 21:43:43 +0000 | [diff] [blame] | 218 | : SemaRef(SemaRef) { | 
| Akira Hatanaka | 43556c1 | 2016-11-03 15:04:58 +0000 | [diff] [blame] | 219 | // Don't allow further instantiation if a fatal error and an uncompilable | 
| Akira Hatanaka | 40c15ab | 2016-11-03 17:11:28 +0000 | [diff] [blame] | 220 | // error have occurred. Any diagnostics we might have raised will not be | 
| Akira Hatanaka | 43556c1 | 2016-11-03 15:04:58 +0000 | [diff] [blame] | 221 | // visible, and we do not need to construct a correct AST. | 
|  | 222 | if (SemaRef.Diags.hasFatalErrorOccurred() && | 
|  | 223 | SemaRef.Diags.hasUncompilableErrorOccurred()) { | 
| David Majnemer | 8c969ea | 2015-01-30 05:01:23 +0000 | [diff] [blame] | 224 | Invalid = true; | 
|  | 225 | return; | 
|  | 226 | } | 
| Stephan Tolksdorf | 232670f | 2014-03-13 20:34:22 +0000 | [diff] [blame] | 227 | Invalid = CheckInstantiationDepth(PointOfInstantiation, InstantiationRange); | 
|  | 228 | if (!Invalid) { | 
| Richard Smith | 696e312 | 2017-02-23 01:43:54 +0000 | [diff] [blame] | 229 | CodeSynthesisContext Inst; | 
| Stephan Tolksdorf | 232670f | 2014-03-13 20:34:22 +0000 | [diff] [blame] | 230 | Inst.Kind = Kind; | 
|  | 231 | Inst.PointOfInstantiation = PointOfInstantiation; | 
|  | 232 | Inst.Entity = Entity; | 
|  | 233 | Inst.Template = Template; | 
|  | 234 | Inst.TemplateArgs = TemplateArgs.data(); | 
|  | 235 | Inst.NumTemplateArgs = TemplateArgs.size(); | 
|  | 236 | Inst.DeductionInfo = DeductionInfo; | 
|  | 237 | Inst.InstantiationRange = InstantiationRange; | 
| Richard Smith | 1338122 | 2017-02-23 21:43:43 +0000 | [diff] [blame] | 238 | SemaRef.pushCodeSynthesisContext(Inst); | 
|  | 239 |  | 
| Richard Smith | 54f18e8 | 2016-08-31 02:15:21 +0000 | [diff] [blame] | 240 | AlreadyInstantiating = | 
|  | 241 | !SemaRef.InstantiatingSpecializations | 
|  | 242 | .insert(std::make_pair(Inst.Entity->getCanonicalDecl(), Inst.Kind)) | 
|  | 243 | .second; | 
| Gabor Horvath | 207e7b1 | 2018-02-10 14:04:45 +0000 | [diff] [blame] | 244 | atTemplateBegin(SemaRef.TemplateInstCallbacks, SemaRef, Inst); | 
| Stephan Tolksdorf | 232670f | 2014-03-13 20:34:22 +0000 | [diff] [blame] | 245 | } | 
|  | 246 | } | 
|  | 247 |  | 
| Benjamin Kramer | 7761a04 | 2015-03-06 16:36:50 +0000 | [diff] [blame] | 248 | Sema::InstantiatingTemplate::InstantiatingTemplate( | 
|  | 249 | Sema &SemaRef, SourceLocation PointOfInstantiation, Decl *Entity, | 
|  | 250 | SourceRange InstantiationRange) | 
|  | 251 | : InstantiatingTemplate(SemaRef, | 
| Richard Smith | 696e312 | 2017-02-23 01:43:54 +0000 | [diff] [blame] | 252 | CodeSynthesisContext::TemplateInstantiation, | 
| Benjamin Kramer | 7761a04 | 2015-03-06 16:36:50 +0000 | [diff] [blame] | 253 | PointOfInstantiation, InstantiationRange, Entity) {} | 
| Douglas Gregor | 79cf603 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 254 |  | 
| Benjamin Kramer | 7761a04 | 2015-03-06 16:36:50 +0000 | [diff] [blame] | 255 | Sema::InstantiatingTemplate::InstantiatingTemplate( | 
|  | 256 | Sema &SemaRef, SourceLocation PointOfInstantiation, FunctionDecl *Entity, | 
|  | 257 | ExceptionSpecification, SourceRange InstantiationRange) | 
|  | 258 | : InstantiatingTemplate( | 
| Richard Smith | 696e312 | 2017-02-23 01:43:54 +0000 | [diff] [blame] | 259 | SemaRef, CodeSynthesisContext::ExceptionSpecInstantiation, | 
| Benjamin Kramer | 7761a04 | 2015-03-06 16:36:50 +0000 | [diff] [blame] | 260 | PointOfInstantiation, InstantiationRange, Entity) {} | 
| Richard Smith | f623c96 | 2012-04-17 00:58:00 +0000 | [diff] [blame] | 261 |  | 
| Benjamin Kramer | 7761a04 | 2015-03-06 16:36:50 +0000 | [diff] [blame] | 262 | Sema::InstantiatingTemplate::InstantiatingTemplate( | 
| Richard Smith | 54f18e8 | 2016-08-31 02:15:21 +0000 | [diff] [blame] | 263 | Sema &SemaRef, SourceLocation PointOfInstantiation, TemplateParameter Param, | 
|  | 264 | TemplateDecl *Template, ArrayRef<TemplateArgument> TemplateArgs, | 
|  | 265 | SourceRange InstantiationRange) | 
| Benjamin Kramer | 7761a04 | 2015-03-06 16:36:50 +0000 | [diff] [blame] | 266 | : InstantiatingTemplate( | 
|  | 267 | SemaRef, | 
| Richard Smith | 696e312 | 2017-02-23 01:43:54 +0000 | [diff] [blame] | 268 | CodeSynthesisContext::DefaultTemplateArgumentInstantiation, | 
| Richard Smith | 54f18e8 | 2016-08-31 02:15:21 +0000 | [diff] [blame] | 269 | PointOfInstantiation, InstantiationRange, getAsNamedDecl(Param), | 
|  | 270 | Template, TemplateArgs) {} | 
| Douglas Gregor | fcd5db3 | 2009-03-10 00:06:19 +0000 | [diff] [blame] | 271 |  | 
| Benjamin Kramer | 7761a04 | 2015-03-06 16:36:50 +0000 | [diff] [blame] | 272 | Sema::InstantiatingTemplate::InstantiatingTemplate( | 
|  | 273 | Sema &SemaRef, SourceLocation PointOfInstantiation, | 
|  | 274 | FunctionTemplateDecl *FunctionTemplate, | 
|  | 275 | ArrayRef<TemplateArgument> TemplateArgs, | 
| Richard Smith | 696e312 | 2017-02-23 01:43:54 +0000 | [diff] [blame] | 276 | CodeSynthesisContext::SynthesisKind Kind, | 
| Benjamin Kramer | 7761a04 | 2015-03-06 16:36:50 +0000 | [diff] [blame] | 277 | sema::TemplateDeductionInfo &DeductionInfo, SourceRange InstantiationRange) | 
|  | 278 | : InstantiatingTemplate(SemaRef, Kind, PointOfInstantiation, | 
|  | 279 | InstantiationRange, FunctionTemplate, nullptr, | 
| Richard Smith | 54f18e8 | 2016-08-31 02:15:21 +0000 | [diff] [blame] | 280 | TemplateArgs, &DeductionInfo) { | 
|  | 281 | assert( | 
| Richard Smith | 696e312 | 2017-02-23 01:43:54 +0000 | [diff] [blame] | 282 | Kind == CodeSynthesisContext::ExplicitTemplateArgumentSubstitution || | 
|  | 283 | Kind == CodeSynthesisContext::DeducedTemplateArgumentSubstitution); | 
| Richard Smith | 54f18e8 | 2016-08-31 02:15:21 +0000 | [diff] [blame] | 284 | } | 
| Douglas Gregor | ff6cbdf | 2009-07-01 22:01:06 +0000 | [diff] [blame] | 285 |  | 
| Benjamin Kramer | 7761a04 | 2015-03-06 16:36:50 +0000 | [diff] [blame] | 286 | Sema::InstantiatingTemplate::InstantiatingTemplate( | 
|  | 287 | Sema &SemaRef, SourceLocation PointOfInstantiation, | 
| Richard Smith | 0e617ec | 2016-12-27 07:56:27 +0000 | [diff] [blame] | 288 | TemplateDecl *Template, | 
|  | 289 | ArrayRef<TemplateArgument> TemplateArgs, | 
|  | 290 | sema::TemplateDeductionInfo &DeductionInfo, SourceRange InstantiationRange) | 
|  | 291 | : InstantiatingTemplate( | 
|  | 292 | SemaRef, | 
| Richard Smith | 696e312 | 2017-02-23 01:43:54 +0000 | [diff] [blame] | 293 | CodeSynthesisContext::DeducedTemplateArgumentSubstitution, | 
| Richard Smith | 0e617ec | 2016-12-27 07:56:27 +0000 | [diff] [blame] | 294 | PointOfInstantiation, InstantiationRange, Template, nullptr, | 
|  | 295 | TemplateArgs, &DeductionInfo) {} | 
|  | 296 |  | 
|  | 297 | Sema::InstantiatingTemplate::InstantiatingTemplate( | 
|  | 298 | Sema &SemaRef, SourceLocation PointOfInstantiation, | 
| Benjamin Kramer | 7761a04 | 2015-03-06 16:36:50 +0000 | [diff] [blame] | 299 | ClassTemplatePartialSpecializationDecl *PartialSpec, | 
|  | 300 | ArrayRef<TemplateArgument> TemplateArgs, | 
|  | 301 | sema::TemplateDeductionInfo &DeductionInfo, SourceRange InstantiationRange) | 
|  | 302 | : InstantiatingTemplate( | 
|  | 303 | SemaRef, | 
| Richard Smith | 696e312 | 2017-02-23 01:43:54 +0000 | [diff] [blame] | 304 | CodeSynthesisContext::DeducedTemplateArgumentSubstitution, | 
| Benjamin Kramer | 7761a04 | 2015-03-06 16:36:50 +0000 | [diff] [blame] | 305 | PointOfInstantiation, InstantiationRange, PartialSpec, nullptr, | 
|  | 306 | TemplateArgs, &DeductionInfo) {} | 
| Douglas Gregor | 637d998 | 2009-06-10 23:47:09 +0000 | [diff] [blame] | 307 |  | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 308 | Sema::InstantiatingTemplate::InstantiatingTemplate( | 
|  | 309 | Sema &SemaRef, SourceLocation PointOfInstantiation, | 
|  | 310 | VarTemplatePartialSpecializationDecl *PartialSpec, | 
|  | 311 | ArrayRef<TemplateArgument> TemplateArgs, | 
|  | 312 | sema::TemplateDeductionInfo &DeductionInfo, SourceRange InstantiationRange) | 
| Benjamin Kramer | 7761a04 | 2015-03-06 16:36:50 +0000 | [diff] [blame] | 313 | : InstantiatingTemplate( | 
|  | 314 | SemaRef, | 
| Richard Smith | 696e312 | 2017-02-23 01:43:54 +0000 | [diff] [blame] | 315 | CodeSynthesisContext::DeducedTemplateArgumentSubstitution, | 
| Benjamin Kramer | 7761a04 | 2015-03-06 16:36:50 +0000 | [diff] [blame] | 316 | PointOfInstantiation, InstantiationRange, PartialSpec, nullptr, | 
|  | 317 | TemplateArgs, &DeductionInfo) {} | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 318 |  | 
| Benjamin Kramer | 7761a04 | 2015-03-06 16:36:50 +0000 | [diff] [blame] | 319 | Sema::InstantiatingTemplate::InstantiatingTemplate( | 
|  | 320 | Sema &SemaRef, SourceLocation PointOfInstantiation, ParmVarDecl *Param, | 
|  | 321 | ArrayRef<TemplateArgument> TemplateArgs, SourceRange InstantiationRange) | 
|  | 322 | : InstantiatingTemplate( | 
|  | 323 | SemaRef, | 
| Richard Smith | 696e312 | 2017-02-23 01:43:54 +0000 | [diff] [blame] | 324 | CodeSynthesisContext::DefaultFunctionArgumentInstantiation, | 
| Benjamin Kramer | 7761a04 | 2015-03-06 16:36:50 +0000 | [diff] [blame] | 325 | PointOfInstantiation, InstantiationRange, Param, nullptr, | 
|  | 326 | TemplateArgs) {} | 
| Douglas Gregor | e62e6a0 | 2009-11-11 19:13:48 +0000 | [diff] [blame] | 327 |  | 
| Benjamin Kramer | 7761a04 | 2015-03-06 16:36:50 +0000 | [diff] [blame] | 328 | Sema::InstantiatingTemplate::InstantiatingTemplate( | 
|  | 329 | Sema &SemaRef, SourceLocation PointOfInstantiation, NamedDecl *Template, | 
|  | 330 | NonTypeTemplateParmDecl *Param, ArrayRef<TemplateArgument> TemplateArgs, | 
|  | 331 | SourceRange InstantiationRange) | 
|  | 332 | : InstantiatingTemplate( | 
|  | 333 | SemaRef, | 
| Richard Smith | 696e312 | 2017-02-23 01:43:54 +0000 | [diff] [blame] | 334 | CodeSynthesisContext::PriorTemplateArgumentSubstitution, | 
| Benjamin Kramer | 7761a04 | 2015-03-06 16:36:50 +0000 | [diff] [blame] | 335 | PointOfInstantiation, InstantiationRange, Param, Template, | 
|  | 336 | TemplateArgs) {} | 
| Stephan Tolksdorf | 232670f | 2014-03-13 20:34:22 +0000 | [diff] [blame] | 337 |  | 
| Benjamin Kramer | 7761a04 | 2015-03-06 16:36:50 +0000 | [diff] [blame] | 338 | Sema::InstantiatingTemplate::InstantiatingTemplate( | 
|  | 339 | Sema &SemaRef, SourceLocation PointOfInstantiation, NamedDecl *Template, | 
|  | 340 | TemplateTemplateParmDecl *Param, ArrayRef<TemplateArgument> TemplateArgs, | 
|  | 341 | SourceRange InstantiationRange) | 
|  | 342 | : InstantiatingTemplate( | 
|  | 343 | SemaRef, | 
| Richard Smith | 696e312 | 2017-02-23 01:43:54 +0000 | [diff] [blame] | 344 | CodeSynthesisContext::PriorTemplateArgumentSubstitution, | 
| Benjamin Kramer | 7761a04 | 2015-03-06 16:36:50 +0000 | [diff] [blame] | 345 | PointOfInstantiation, InstantiationRange, Param, Template, | 
|  | 346 | TemplateArgs) {} | 
| Douglas Gregor | e62e6a0 | 2009-11-11 19:13:48 +0000 | [diff] [blame] | 347 |  | 
| Benjamin Kramer | 7761a04 | 2015-03-06 16:36:50 +0000 | [diff] [blame] | 348 | Sema::InstantiatingTemplate::InstantiatingTemplate( | 
|  | 349 | Sema &SemaRef, SourceLocation PointOfInstantiation, TemplateDecl *Template, | 
|  | 350 | NamedDecl *Param, ArrayRef<TemplateArgument> TemplateArgs, | 
|  | 351 | SourceRange InstantiationRange) | 
|  | 352 | : InstantiatingTemplate( | 
| Richard Smith | 696e312 | 2017-02-23 01:43:54 +0000 | [diff] [blame] | 353 | SemaRef, CodeSynthesisContext::DefaultTemplateArgumentChecking, | 
| Benjamin Kramer | 7761a04 | 2015-03-06 16:36:50 +0000 | [diff] [blame] | 354 | PointOfInstantiation, InstantiationRange, Param, Template, | 
|  | 355 | TemplateArgs) {} | 
| Anders Carlsson | 657bad4 | 2009-09-05 05:14:19 +0000 | [diff] [blame] | 356 |  | 
| Richard Smith | 1338122 | 2017-02-23 21:43:43 +0000 | [diff] [blame] | 357 | void Sema::pushCodeSynthesisContext(CodeSynthesisContext Ctx) { | 
|  | 358 | Ctx.SavedInNonInstantiationSFINAEContext = InNonInstantiationSFINAEContext; | 
|  | 359 | InNonInstantiationSFINAEContext = false; | 
|  | 360 |  | 
|  | 361 | CodeSynthesisContexts.push_back(Ctx); | 
|  | 362 |  | 
|  | 363 | if (!Ctx.isInstantiationRecord()) | 
|  | 364 | ++NonInstantiationEntries; | 
|  | 365 | } | 
|  | 366 |  | 
|  | 367 | void Sema::popCodeSynthesisContext() { | 
|  | 368 | auto &Active = CodeSynthesisContexts.back(); | 
|  | 369 | if (!Active.isInstantiationRecord()) { | 
|  | 370 | assert(NonInstantiationEntries > 0); | 
|  | 371 | --NonInstantiationEntries; | 
|  | 372 | } | 
|  | 373 |  | 
|  | 374 | InNonInstantiationSFINAEContext = Active.SavedInNonInstantiationSFINAEContext; | 
|  | 375 |  | 
|  | 376 | // Name lookup no longer looks in this template's defining module. | 
|  | 377 | assert(CodeSynthesisContexts.size() >= | 
|  | 378 | CodeSynthesisContextLookupModules.size() && | 
|  | 379 | "forgot to remove a lookup module for a template instantiation"); | 
|  | 380 | if (CodeSynthesisContexts.size() == | 
|  | 381 | CodeSynthesisContextLookupModules.size()) { | 
|  | 382 | if (Module *M = CodeSynthesisContextLookupModules.back()) | 
|  | 383 | LookupModulesCache.erase(M); | 
|  | 384 | CodeSynthesisContextLookupModules.pop_back(); | 
|  | 385 | } | 
|  | 386 |  | 
|  | 387 | // If we've left the code synthesis context for the current context stack, | 
|  | 388 | // stop remembering that we've emitted that stack. | 
|  | 389 | if (CodeSynthesisContexts.size() == | 
|  | 390 | LastEmittedCodeSynthesisContextDepth) | 
|  | 391 | LastEmittedCodeSynthesisContextDepth = 0; | 
|  | 392 |  | 
|  | 393 | CodeSynthesisContexts.pop_back(); | 
|  | 394 | } | 
|  | 395 |  | 
| Douglas Gregor | 8567358 | 2009-05-18 17:01:57 +0000 | [diff] [blame] | 396 | void Sema::InstantiatingTemplate::Clear() { | 
|  | 397 | if (!Invalid) { | 
| Richard Smith | 1338122 | 2017-02-23 21:43:43 +0000 | [diff] [blame] | 398 | if (!AlreadyInstantiating) { | 
|  | 399 | auto &Active = SemaRef.CodeSynthesisContexts.back(); | 
| Richard Smith | 54f18e8 | 2016-08-31 02:15:21 +0000 | [diff] [blame] | 400 | SemaRef.InstantiatingSpecializations.erase( | 
|  | 401 | std::make_pair(Active.Entity, Active.Kind)); | 
| Richard Smith | 1338122 | 2017-02-23 21:43:43 +0000 | [diff] [blame] | 402 | } | 
| Richard Smith | 54f18e8 | 2016-08-31 02:15:21 +0000 | [diff] [blame] | 403 |  | 
| Gabor Horvath | 207e7b1 | 2018-02-10 14:04:45 +0000 | [diff] [blame] | 404 | atTemplateEnd(SemaRef.TemplateInstCallbacks, SemaRef, | 
|  | 405 | SemaRef.CodeSynthesisContexts.back()); | 
| Richard Smith | 1338122 | 2017-02-23 21:43:43 +0000 | [diff] [blame] | 406 |  | 
| Gabor Horvath | 207e7b1 | 2018-02-10 14:04:45 +0000 | [diff] [blame] | 407 | SemaRef.popCodeSynthesisContext(); | 
| Douglas Gregor | 8567358 | 2009-05-18 17:01:57 +0000 | [diff] [blame] | 408 | Invalid = true; | 
|  | 409 | } | 
| Douglas Gregor | fcd5db3 | 2009-03-10 00:06:19 +0000 | [diff] [blame] | 410 | } | 
|  | 411 |  | 
| Douglas Gregor | 79cf603 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 412 | bool Sema::InstantiatingTemplate::CheckInstantiationDepth( | 
|  | 413 | SourceLocation PointOfInstantiation, | 
|  | 414 | SourceRange InstantiationRange) { | 
| Douglas Gregor | 84d49a2 | 2009-11-11 21:54:23 +0000 | [diff] [blame] | 415 | assert(SemaRef.NonInstantiationEntries <= | 
| Richard Smith | 696e312 | 2017-02-23 01:43:54 +0000 | [diff] [blame] | 416 | SemaRef.CodeSynthesisContexts.size()); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 417 | if ((SemaRef.CodeSynthesisContexts.size() - | 
| Douglas Gregor | 84d49a2 | 2009-11-11 21:54:23 +0000 | [diff] [blame] | 418 | SemaRef.NonInstantiationEntries) | 
| David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 419 | <= SemaRef.getLangOpts().InstantiationDepth) | 
| Douglas Gregor | 79cf603 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 420 | return false; | 
|  | 421 |  | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 422 | SemaRef.Diag(PointOfInstantiation, | 
| Douglas Gregor | 79cf603 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 423 | diag::err_template_recursion_depth_exceeded) | 
| David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 424 | << SemaRef.getLangOpts().InstantiationDepth | 
| Douglas Gregor | 79cf603 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 425 | << InstantiationRange; | 
|  | 426 | SemaRef.Diag(PointOfInstantiation, diag::note_template_recursion_depth) | 
| David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 427 | << SemaRef.getLangOpts().InstantiationDepth; | 
| Douglas Gregor | 79cf603 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 428 | return true; | 
|  | 429 | } | 
|  | 430 |  | 
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 431 | /// Prints the current instantiation stack through a series of | 
| Douglas Gregor | 4ea568f | 2009-03-10 18:03:33 +0000 | [diff] [blame] | 432 | /// notes. | 
|  | 433 | void Sema::PrintInstantiationStack() { | 
| Douglas Gregor | ffed1cb | 2010-04-20 07:18:24 +0000 | [diff] [blame] | 434 | // Determine which template instantiations to skip, if any. | 
| Richard Smith | 696e312 | 2017-02-23 01:43:54 +0000 | [diff] [blame] | 435 | unsigned SkipStart = CodeSynthesisContexts.size(), SkipEnd = SkipStart; | 
| Douglas Gregor | ffed1cb | 2010-04-20 07:18:24 +0000 | [diff] [blame] | 436 | unsigned Limit = Diags.getTemplateBacktraceLimit(); | 
| Richard Smith | 696e312 | 2017-02-23 01:43:54 +0000 | [diff] [blame] | 437 | if (Limit && Limit < CodeSynthesisContexts.size()) { | 
| Douglas Gregor | ffed1cb | 2010-04-20 07:18:24 +0000 | [diff] [blame] | 438 | SkipStart = Limit / 2 + Limit % 2; | 
| Richard Smith | 696e312 | 2017-02-23 01:43:54 +0000 | [diff] [blame] | 439 | SkipEnd = CodeSynthesisContexts.size() - Limit / 2; | 
| Douglas Gregor | ffed1cb | 2010-04-20 07:18:24 +0000 | [diff] [blame] | 440 | } | 
|  | 441 |  | 
| Douglas Gregor | ff6cbdf | 2009-07-01 22:01:06 +0000 | [diff] [blame] | 442 | // FIXME: In all of these cases, we need to show the template arguments | 
| Douglas Gregor | ffed1cb | 2010-04-20 07:18:24 +0000 | [diff] [blame] | 443 | unsigned InstantiationIdx = 0; | 
| Richard Smith | 696e312 | 2017-02-23 01:43:54 +0000 | [diff] [blame] | 444 | for (SmallVectorImpl<CodeSynthesisContext>::reverse_iterator | 
|  | 445 | Active = CodeSynthesisContexts.rbegin(), | 
|  | 446 | ActiveEnd = CodeSynthesisContexts.rend(); | 
| Douglas Gregor | 4ea568f | 2009-03-10 18:03:33 +0000 | [diff] [blame] | 447 | Active != ActiveEnd; | 
| Douglas Gregor | ffed1cb | 2010-04-20 07:18:24 +0000 | [diff] [blame] | 448 | ++Active, ++InstantiationIdx) { | 
|  | 449 | // Skip this instantiation? | 
|  | 450 | if (InstantiationIdx >= SkipStart && InstantiationIdx < SkipEnd) { | 
|  | 451 | if (InstantiationIdx == SkipStart) { | 
|  | 452 | // Note that we're skipping instantiations. | 
| Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 453 | Diags.Report(Active->PointOfInstantiation, | 
| Douglas Gregor | ffed1cb | 2010-04-20 07:18:24 +0000 | [diff] [blame] | 454 | diag::note_instantiation_contexts_suppressed) | 
| Richard Smith | 696e312 | 2017-02-23 01:43:54 +0000 | [diff] [blame] | 455 | << unsigned(CodeSynthesisContexts.size() - Limit); | 
| Douglas Gregor | ffed1cb | 2010-04-20 07:18:24 +0000 | [diff] [blame] | 456 | } | 
|  | 457 | continue; | 
|  | 458 | } | 
|  | 459 |  | 
| Douglas Gregor | 79cf603 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 460 | switch (Active->Kind) { | 
| Richard Smith | 696e312 | 2017-02-23 01:43:54 +0000 | [diff] [blame] | 461 | case CodeSynthesisContext::TemplateInstantiation: { | 
| Nick Lewycky | cc8990f | 2012-11-16 08:40:59 +0000 | [diff] [blame] | 462 | Decl *D = Active->Entity; | 
| Douglas Gregor | 8567358 | 2009-05-18 17:01:57 +0000 | [diff] [blame] | 463 | if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(D)) { | 
|  | 464 | unsigned DiagID = diag::note_template_member_class_here; | 
|  | 465 | if (isa<ClassTemplateSpecializationDecl>(Record)) | 
|  | 466 | DiagID = diag::note_template_class_instantiation_here; | 
| Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 467 | Diags.Report(Active->PointOfInstantiation, DiagID) | 
| Richard Smith | 792c22d | 2016-12-24 04:09:05 +0000 | [diff] [blame] | 468 | << Record << Active->InstantiationRange; | 
| Douglas Gregor | a6ef8f0 | 2009-07-24 20:34:43 +0000 | [diff] [blame] | 469 | } else if (FunctionDecl *Function = dyn_cast<FunctionDecl>(D)) { | 
| Douglas Gregor | 4adbc6d | 2009-06-26 00:10:03 +0000 | [diff] [blame] | 470 | unsigned DiagID; | 
|  | 471 | if (Function->getPrimaryTemplate()) | 
|  | 472 | DiagID = diag::note_function_template_spec_here; | 
|  | 473 | else | 
|  | 474 | DiagID = diag::note_template_member_function_here; | 
| Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 475 | Diags.Report(Active->PointOfInstantiation, DiagID) | 
| Douglas Gregor | 8567358 | 2009-05-18 17:01:57 +0000 | [diff] [blame] | 476 | << Function | 
|  | 477 | << Active->InstantiationRange; | 
| Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 478 | } else if (VarDecl *VD = dyn_cast<VarDecl>(D)) { | 
| Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 479 | Diags.Report(Active->PointOfInstantiation, | 
| Larisse Voufo | dbd6577 | 2013-08-14 20:15:02 +0000 | [diff] [blame] | 480 | VD->isStaticDataMember()? | 
|  | 481 | diag::note_template_static_data_member_def_here | 
|  | 482 | : diag::note_template_variable_def_here) | 
| Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 483 | << VD | 
|  | 484 | << Active->InstantiationRange; | 
| Richard Smith | 4b38ded | 2012-03-14 23:13:10 +0000 | [diff] [blame] | 485 | } else if (EnumDecl *ED = dyn_cast<EnumDecl>(D)) { | 
|  | 486 | Diags.Report(Active->PointOfInstantiation, | 
|  | 487 | diag::note_template_enum_def_here) | 
|  | 488 | << ED | 
|  | 489 | << Active->InstantiationRange; | 
| Reid Kleckner | d60b82f | 2014-11-17 23:36:45 +0000 | [diff] [blame] | 490 | } else if (FieldDecl *FD = dyn_cast<FieldDecl>(D)) { | 
|  | 491 | Diags.Report(Active->PointOfInstantiation, | 
|  | 492 | diag::note_template_nsdmi_here) | 
|  | 493 | << FD << Active->InstantiationRange; | 
| Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 494 | } else { | 
|  | 495 | Diags.Report(Active->PointOfInstantiation, | 
|  | 496 | diag::note_template_type_alias_instantiation_here) | 
|  | 497 | << cast<TypeAliasTemplateDecl>(D) | 
| Douglas Gregor | a6ef8f0 | 2009-07-24 20:34:43 +0000 | [diff] [blame] | 498 | << Active->InstantiationRange; | 
| Douglas Gregor | 8567358 | 2009-05-18 17:01:57 +0000 | [diff] [blame] | 499 | } | 
| Douglas Gregor | 79cf603 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 500 | break; | 
|  | 501 | } | 
|  | 502 |  | 
| Richard Smith | 696e312 | 2017-02-23 01:43:54 +0000 | [diff] [blame] | 503 | case CodeSynthesisContext::DefaultTemplateArgumentInstantiation: { | 
| Richard Smith | 54f18e8 | 2016-08-31 02:15:21 +0000 | [diff] [blame] | 504 | TemplateDecl *Template = cast<TemplateDecl>(Active->Template); | 
| Benjamin Kramer | 9170e91 | 2013-02-22 15:46:01 +0000 | [diff] [blame] | 505 | SmallVector<char, 128> TemplateArgsStr; | 
|  | 506 | llvm::raw_svector_ostream OS(TemplateArgsStr); | 
|  | 507 | Template->printName(OS); | 
| Serge Pavlov | 03e672c | 2017-11-28 16:14:14 +0000 | [diff] [blame] | 508 | printTemplateArgumentList(OS, Active->template_arguments(), | 
|  | 509 | getPrintingPolicy()); | 
| Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 510 | Diags.Report(Active->PointOfInstantiation, | 
| Douglas Gregor | 79cf603 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 511 | diag::note_default_arg_instantiation_here) | 
| Benjamin Kramer | 9170e91 | 2013-02-22 15:46:01 +0000 | [diff] [blame] | 512 | << OS.str() | 
| Douglas Gregor | 79cf603 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 513 | << Active->InstantiationRange; | 
|  | 514 | break; | 
|  | 515 | } | 
| Douglas Gregor | 637d998 | 2009-06-10 23:47:09 +0000 | [diff] [blame] | 516 |  | 
| Richard Smith | 696e312 | 2017-02-23 01:43:54 +0000 | [diff] [blame] | 517 | case CodeSynthesisContext::ExplicitTemplateArgumentSubstitution: { | 
| Nick Lewycky | cc8990f | 2012-11-16 08:40:59 +0000 | [diff] [blame] | 518 | FunctionTemplateDecl *FnTmpl = cast<FunctionTemplateDecl>(Active->Entity); | 
| Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 519 | Diags.Report(Active->PointOfInstantiation, | 
| Douglas Gregor | ff6cbdf | 2009-07-01 22:01:06 +0000 | [diff] [blame] | 520 | diag::note_explicit_template_arg_substitution_here) | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 521 | << FnTmpl | 
|  | 522 | << getTemplateArgumentBindingsText(FnTmpl->getTemplateParameters(), | 
|  | 523 | Active->TemplateArgs, | 
| Douglas Gregor | 607f141 | 2010-03-30 20:35:20 +0000 | [diff] [blame] | 524 | Active->NumTemplateArgs) | 
|  | 525 | << Active->InstantiationRange; | 
| Douglas Gregor | 637d998 | 2009-06-10 23:47:09 +0000 | [diff] [blame] | 526 | break; | 
|  | 527 | } | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 528 |  | 
| Richard Smith | 696e312 | 2017-02-23 01:43:54 +0000 | [diff] [blame] | 529 | case CodeSynthesisContext::DeducedTemplateArgumentSubstitution: { | 
| Richard Smith | e68a38f | 2016-12-24 04:20:31 +0000 | [diff] [blame] | 530 | if (FunctionTemplateDecl *FnTmpl = | 
|  | 531 | dyn_cast<FunctionTemplateDecl>(Active->Entity)) { | 
| Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 532 | Diags.Report(Active->PointOfInstantiation, | 
| Douglas Gregor | ff6cbdf | 2009-07-01 22:01:06 +0000 | [diff] [blame] | 533 | diag::note_function_template_deduction_instantiation_here) | 
| Douglas Gregor | 607f141 | 2010-03-30 20:35:20 +0000 | [diff] [blame] | 534 | << FnTmpl | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 535 | << getTemplateArgumentBindingsText(FnTmpl->getTemplateParameters(), | 
|  | 536 | Active->TemplateArgs, | 
| Douglas Gregor | 607f141 | 2010-03-30 20:35:20 +0000 | [diff] [blame] | 537 | Active->NumTemplateArgs) | 
|  | 538 | << Active->InstantiationRange; | 
| Richard Smith | e68a38f | 2016-12-24 04:20:31 +0000 | [diff] [blame] | 539 | } else { | 
|  | 540 | bool IsVar = isa<VarTemplateDecl>(Active->Entity) || | 
|  | 541 | isa<VarTemplateSpecializationDecl>(Active->Entity); | 
| Richard Smith | 0e617ec | 2016-12-27 07:56:27 +0000 | [diff] [blame] | 542 | bool IsTemplate = false; | 
| Richard Smith | e68a38f | 2016-12-24 04:20:31 +0000 | [diff] [blame] | 543 | TemplateParameterList *Params; | 
| Richard Smith | 0e617ec | 2016-12-27 07:56:27 +0000 | [diff] [blame] | 544 | if (auto *D = dyn_cast<TemplateDecl>(Active->Entity)) { | 
|  | 545 | IsTemplate = true; | 
|  | 546 | Params = D->getTemplateParameters(); | 
|  | 547 | } else if (auto *D = dyn_cast<ClassTemplatePartialSpecializationDecl>( | 
| Richard Smith | e68a38f | 2016-12-24 04:20:31 +0000 | [diff] [blame] | 548 | Active->Entity)) { | 
|  | 549 | Params = D->getTemplateParameters(); | 
|  | 550 | } else if (auto *D = dyn_cast<VarTemplatePartialSpecializationDecl>( | 
|  | 551 | Active->Entity)) { | 
|  | 552 | Params = D->getTemplateParameters(); | 
|  | 553 | } else { | 
|  | 554 | llvm_unreachable("unexpected template kind"); | 
|  | 555 | } | 
|  | 556 |  | 
| Richard Smith | e68a38f | 2016-12-24 04:20:31 +0000 | [diff] [blame] | 557 | Diags.Report(Active->PointOfInstantiation, | 
|  | 558 | diag::note_deduced_template_arg_substitution_here) | 
| Richard Smith | 0e617ec | 2016-12-27 07:56:27 +0000 | [diff] [blame] | 559 | << IsVar << IsTemplate << cast<NamedDecl>(Active->Entity) | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 560 | << getTemplateArgumentBindingsText(Params, Active->TemplateArgs, | 
| Richard Smith | e68a38f | 2016-12-24 04:20:31 +0000 | [diff] [blame] | 561 | Active->NumTemplateArgs) | 
|  | 562 | << Active->InstantiationRange; | 
| Douglas Gregor | ff6cbdf | 2009-07-01 22:01:06 +0000 | [diff] [blame] | 563 | } | 
|  | 564 | break; | 
| Richard Smith | e68a38f | 2016-12-24 04:20:31 +0000 | [diff] [blame] | 565 | } | 
| Douglas Gregor | 637d998 | 2009-06-10 23:47:09 +0000 | [diff] [blame] | 566 |  | 
| Richard Smith | 696e312 | 2017-02-23 01:43:54 +0000 | [diff] [blame] | 567 | case CodeSynthesisContext::DefaultFunctionArgumentInstantiation: { | 
| Nick Lewycky | cc8990f | 2012-11-16 08:40:59 +0000 | [diff] [blame] | 568 | ParmVarDecl *Param = cast<ParmVarDecl>(Active->Entity); | 
| Anders Carlsson | 657bad4 | 2009-09-05 05:14:19 +0000 | [diff] [blame] | 569 | FunctionDecl *FD = cast<FunctionDecl>(Param->getDeclContext()); | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 570 |  | 
| Benjamin Kramer | 9170e91 | 2013-02-22 15:46:01 +0000 | [diff] [blame] | 571 | SmallVector<char, 128> TemplateArgsStr; | 
|  | 572 | llvm::raw_svector_ostream OS(TemplateArgsStr); | 
|  | 573 | FD->printName(OS); | 
| Serge Pavlov | 03e672c | 2017-11-28 16:14:14 +0000 | [diff] [blame] | 574 | printTemplateArgumentList(OS, Active->template_arguments(), | 
|  | 575 | getPrintingPolicy()); | 
| Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 576 | Diags.Report(Active->PointOfInstantiation, | 
| Anders Carlsson | 657bad4 | 2009-09-05 05:14:19 +0000 | [diff] [blame] | 577 | diag::note_default_function_arg_instantiation_here) | 
| Benjamin Kramer | 9170e91 | 2013-02-22 15:46:01 +0000 | [diff] [blame] | 578 | << OS.str() | 
| Anders Carlsson | 657bad4 | 2009-09-05 05:14:19 +0000 | [diff] [blame] | 579 | << Active->InstantiationRange; | 
|  | 580 | break; | 
|  | 581 | } | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 582 |  | 
| Richard Smith | 696e312 | 2017-02-23 01:43:54 +0000 | [diff] [blame] | 583 | case CodeSynthesisContext::PriorTemplateArgumentSubstitution: { | 
| Nick Lewycky | cc8990f | 2012-11-16 08:40:59 +0000 | [diff] [blame] | 584 | NamedDecl *Parm = cast<NamedDecl>(Active->Entity); | 
| Douglas Gregor | e62e6a0 | 2009-11-11 19:13:48 +0000 | [diff] [blame] | 585 | std::string Name; | 
|  | 586 | if (!Parm->getName().empty()) | 
|  | 587 | Name = std::string(" '") + Parm->getName().str() + "'"; | 
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 588 |  | 
|  | 589 | TemplateParameterList *TemplateParams = nullptr; | 
| Douglas Gregor | ca4686d | 2011-01-04 23:35:54 +0000 | [diff] [blame] | 590 | if (TemplateDecl *Template = dyn_cast<TemplateDecl>(Active->Template)) | 
|  | 591 | TemplateParams = Template->getTemplateParameters(); | 
|  | 592 | else | 
|  | 593 | TemplateParams = | 
|  | 594 | cast<ClassTemplatePartialSpecializationDecl>(Active->Template) | 
|  | 595 | ->getTemplateParameters(); | 
| Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 596 | Diags.Report(Active->PointOfInstantiation, | 
| Douglas Gregor | e62e6a0 | 2009-11-11 19:13:48 +0000 | [diff] [blame] | 597 | diag::note_prior_template_arg_substitution) | 
|  | 598 | << isa<TemplateTemplateParmDecl>(Parm) | 
|  | 599 | << Name | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 600 | << getTemplateArgumentBindingsText(TemplateParams, | 
|  | 601 | Active->TemplateArgs, | 
| Douglas Gregor | e62e6a0 | 2009-11-11 19:13:48 +0000 | [diff] [blame] | 602 | Active->NumTemplateArgs) | 
|  | 603 | << Active->InstantiationRange; | 
|  | 604 | break; | 
|  | 605 | } | 
| Douglas Gregor | 84d49a2 | 2009-11-11 21:54:23 +0000 | [diff] [blame] | 606 |  | 
| Richard Smith | 696e312 | 2017-02-23 01:43:54 +0000 | [diff] [blame] | 607 | case CodeSynthesisContext::DefaultTemplateArgumentChecking: { | 
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 608 | TemplateParameterList *TemplateParams = nullptr; | 
| Douglas Gregor | ca4686d | 2011-01-04 23:35:54 +0000 | [diff] [blame] | 609 | if (TemplateDecl *Template = dyn_cast<TemplateDecl>(Active->Template)) | 
|  | 610 | TemplateParams = Template->getTemplateParameters(); | 
|  | 611 | else | 
|  | 612 | TemplateParams = | 
|  | 613 | cast<ClassTemplatePartialSpecializationDecl>(Active->Template) | 
|  | 614 | ->getTemplateParameters(); | 
|  | 615 |  | 
| Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 616 | Diags.Report(Active->PointOfInstantiation, | 
| Douglas Gregor | 84d49a2 | 2009-11-11 21:54:23 +0000 | [diff] [blame] | 617 | diag::note_template_default_arg_checking) | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 618 | << getTemplateArgumentBindingsText(TemplateParams, | 
|  | 619 | Active->TemplateArgs, | 
| Douglas Gregor | 84d49a2 | 2009-11-11 21:54:23 +0000 | [diff] [blame] | 620 | Active->NumTemplateArgs) | 
|  | 621 | << Active->InstantiationRange; | 
|  | 622 | break; | 
|  | 623 | } | 
| Richard Smith | f623c96 | 2012-04-17 00:58:00 +0000 | [diff] [blame] | 624 |  | 
| Richard Smith | 5159bbad | 2018-09-05 22:30:37 +0000 | [diff] [blame] | 625 | case CodeSynthesisContext::ExceptionSpecEvaluation: | 
|  | 626 | Diags.Report(Active->PointOfInstantiation, | 
|  | 627 | diag::note_evaluating_exception_spec_here) | 
|  | 628 | << cast<FunctionDecl>(Active->Entity); | 
|  | 629 | break; | 
|  | 630 |  | 
| Richard Smith | 696e312 | 2017-02-23 01:43:54 +0000 | [diff] [blame] | 631 | case CodeSynthesisContext::ExceptionSpecInstantiation: | 
| Richard Smith | f623c96 | 2012-04-17 00:58:00 +0000 | [diff] [blame] | 632 | Diags.Report(Active->PointOfInstantiation, | 
|  | 633 | diag::note_template_exception_spec_instantiation_here) | 
| Nick Lewycky | cc8990f | 2012-11-16 08:40:59 +0000 | [diff] [blame] | 634 | << cast<FunctionDecl>(Active->Entity) | 
| Richard Smith | f623c96 | 2012-04-17 00:58:00 +0000 | [diff] [blame] | 635 | << Active->InstantiationRange; | 
|  | 636 | break; | 
| Richard Smith | 1338122 | 2017-02-23 21:43:43 +0000 | [diff] [blame] | 637 |  | 
|  | 638 | case CodeSynthesisContext::DeclaringSpecialMember: | 
|  | 639 | Diags.Report(Active->PointOfInstantiation, | 
|  | 640 | diag::note_in_declaration_of_implicit_special_member) | 
|  | 641 | << cast<CXXRecordDecl>(Active->Entity) << Active->SpecialMember; | 
|  | 642 | break; | 
| Richard Smith | 883dbc4 | 2017-05-25 22:47:05 +0000 | [diff] [blame] | 643 |  | 
| Gabor Horvath | 207e7b1 | 2018-02-10 14:04:45 +0000 | [diff] [blame] | 644 | case CodeSynthesisContext::DefiningSynthesizedFunction: { | 
| Richard Smith | 883dbc4 | 2017-05-25 22:47:05 +0000 | [diff] [blame] | 645 | // FIXME: For synthesized members other than special members, produce a note. | 
|  | 646 | auto *MD = dyn_cast<CXXMethodDecl>(Active->Entity); | 
|  | 647 | auto CSM = MD ? getSpecialMember(MD) : CXXInvalid; | 
|  | 648 | if (CSM != CXXInvalid) { | 
|  | 649 | Diags.Report(Active->PointOfInstantiation, | 
|  | 650 | diag::note_member_synthesized_at) | 
|  | 651 | << CSM << Context.getTagDeclType(MD->getParent()); | 
|  | 652 | } | 
|  | 653 | break; | 
| Douglas Gregor | 79cf603 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 654 | } | 
| Gabor Horvath | 207e7b1 | 2018-02-10 14:04:45 +0000 | [diff] [blame] | 655 |  | 
|  | 656 | case CodeSynthesisContext::Memoization: | 
|  | 657 | break; | 
|  | 658 | } | 
| Douglas Gregor | 4ea568f | 2009-03-10 18:03:33 +0000 | [diff] [blame] | 659 | } | 
|  | 660 | } | 
|  | 661 |  | 
| David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 662 | Optional<TemplateDeductionInfo *> Sema::isSFINAEContext() const { | 
| Douglas Gregor | edb7685 | 2011-01-27 22:31:44 +0000 | [diff] [blame] | 663 | if (InNonInstantiationSFINAEContext) | 
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 664 | return Optional<TemplateDeductionInfo *>(nullptr); | 
| Douglas Gregor | edb7685 | 2011-01-27 22:31:44 +0000 | [diff] [blame] | 665 |  | 
| Richard Smith | 696e312 | 2017-02-23 01:43:54 +0000 | [diff] [blame] | 666 | for (SmallVectorImpl<CodeSynthesisContext>::const_reverse_iterator | 
|  | 667 | Active = CodeSynthesisContexts.rbegin(), | 
|  | 668 | ActiveEnd = CodeSynthesisContexts.rend(); | 
| Douglas Gregor | 3383451 | 2009-06-14 07:33:30 +0000 | [diff] [blame] | 669 | Active != ActiveEnd; | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 670 | ++Active) | 
| Douglas Gregor | 84d49a2 | 2009-11-11 21:54:23 +0000 | [diff] [blame] | 671 | { | 
| Richard Smith | 1338122 | 2017-02-23 21:43:43 +0000 | [diff] [blame] | 672 | switch (Active->Kind) { | 
| Richard Smith | 696e312 | 2017-02-23 01:43:54 +0000 | [diff] [blame] | 673 | case CodeSynthesisContext::TemplateInstantiation: | 
| Richard Smith | 72249ba | 2012-04-26 07:24:08 +0000 | [diff] [blame] | 674 | // An instantiation of an alias template may or may not be a SFINAE | 
|  | 675 | // context, depending on what else is on the stack. | 
| Nick Lewycky | cc8990f | 2012-11-16 08:40:59 +0000 | [diff] [blame] | 676 | if (isa<TypeAliasTemplateDecl>(Active->Entity)) | 
| Richard Smith | 72249ba | 2012-04-26 07:24:08 +0000 | [diff] [blame] | 677 | break; | 
|  | 678 | // Fall through. | 
| Richard Smith | 696e312 | 2017-02-23 01:43:54 +0000 | [diff] [blame] | 679 | case CodeSynthesisContext::DefaultFunctionArgumentInstantiation: | 
|  | 680 | case CodeSynthesisContext::ExceptionSpecInstantiation: | 
| Douglas Gregor | ff6cbdf | 2009-07-01 22:01:06 +0000 | [diff] [blame] | 681 | // This is a template instantiation, so there is no SFINAE. | 
| David Blaikie | 7a30dc5 | 2013-02-21 01:47:18 +0000 | [diff] [blame] | 682 | return None; | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 683 |  | 
| Richard Smith | 696e312 | 2017-02-23 01:43:54 +0000 | [diff] [blame] | 684 | case CodeSynthesisContext::DefaultTemplateArgumentInstantiation: | 
|  | 685 | case CodeSynthesisContext::PriorTemplateArgumentSubstitution: | 
|  | 686 | case CodeSynthesisContext::DefaultTemplateArgumentChecking: | 
| Douglas Gregor | e62e6a0 | 2009-11-11 19:13:48 +0000 | [diff] [blame] | 687 | // A default template argument instantiation and substitution into | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 688 | // template parameters with arguments for prior parameters may or may | 
| Douglas Gregor | e62e6a0 | 2009-11-11 19:13:48 +0000 | [diff] [blame] | 689 | // not be a SFINAE context; look further up the stack. | 
| Douglas Gregor | 3383451 | 2009-06-14 07:33:30 +0000 | [diff] [blame] | 690 | break; | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 691 |  | 
| Richard Smith | 696e312 | 2017-02-23 01:43:54 +0000 | [diff] [blame] | 692 | case CodeSynthesisContext::ExplicitTemplateArgumentSubstitution: | 
|  | 693 | case CodeSynthesisContext::DeducedTemplateArgumentSubstitution: | 
| Douglas Gregor | ff6cbdf | 2009-07-01 22:01:06 +0000 | [diff] [blame] | 694 | // We're either substitution explicitly-specified template arguments | 
|  | 695 | // or deduced template arguments, so SFINAE applies. | 
| Douglas Gregor | 5bb5e4a | 2010-10-12 23:32:35 +0000 | [diff] [blame] | 696 | assert(Active->DeductionInfo && "Missing deduction info pointer"); | 
|  | 697 | return Active->DeductionInfo; | 
| Richard Smith | 1338122 | 2017-02-23 21:43:43 +0000 | [diff] [blame] | 698 |  | 
|  | 699 | case CodeSynthesisContext::DeclaringSpecialMember: | 
| Richard Smith | 883dbc4 | 2017-05-25 22:47:05 +0000 | [diff] [blame] | 700 | case CodeSynthesisContext::DefiningSynthesizedFunction: | 
| Richard Smith | 1338122 | 2017-02-23 21:43:43 +0000 | [diff] [blame] | 701 | // This happens in a context unrelated to template instantiation, so | 
|  | 702 | // there is no SFINAE. | 
|  | 703 | return None; | 
| Gabor Horvath | 207e7b1 | 2018-02-10 14:04:45 +0000 | [diff] [blame] | 704 |  | 
| Richard Smith | 5159bbad | 2018-09-05 22:30:37 +0000 | [diff] [blame] | 705 | case CodeSynthesisContext::ExceptionSpecEvaluation: | 
|  | 706 | // FIXME: This should not be treated as a SFINAE context, because | 
|  | 707 | // we will cache an incorrect exception specification. However, clang | 
|  | 708 | // bootstrap relies this! See PR31692. | 
|  | 709 | break; | 
|  | 710 |  | 
| Gabor Horvath | 207e7b1 | 2018-02-10 14:04:45 +0000 | [diff] [blame] | 711 | case CodeSynthesisContext::Memoization: | 
|  | 712 | break; | 
| Douglas Gregor | 3383451 | 2009-06-14 07:33:30 +0000 | [diff] [blame] | 713 | } | 
| Richard Smith | 1338122 | 2017-02-23 21:43:43 +0000 | [diff] [blame] | 714 |  | 
|  | 715 | // The inner context was transparent for SFINAE. If it occurred within a | 
|  | 716 | // non-instantiation SFINAE context, then SFINAE applies. | 
|  | 717 | if (Active->SavedInNonInstantiationSFINAEContext) | 
|  | 718 | return Optional<TemplateDeductionInfo *>(nullptr); | 
| Douglas Gregor | 3383451 | 2009-06-14 07:33:30 +0000 | [diff] [blame] | 719 | } | 
|  | 720 |  | 
| David Blaikie | 7a30dc5 | 2013-02-21 01:47:18 +0000 | [diff] [blame] | 721 | return None; | 
| Douglas Gregor | 3383451 | 2009-06-14 07:33:30 +0000 | [diff] [blame] | 722 | } | 
|  | 723 |  | 
| Douglas Gregor | fe1e110 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 724 | //===----------------------------------------------------------------------===/ | 
|  | 725 | // Template Instantiation for Types | 
|  | 726 | //===----------------------------------------------------------------------===/ | 
| Douglas Gregor | 17c0d7b | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 727 | namespace { | 
| Douglas Gregor | 14cf752 | 2010-04-30 18:55:50 +0000 | [diff] [blame] | 728 | class TemplateInstantiator : public TreeTransform<TemplateInstantiator> { | 
| Douglas Gregor | 01afeef | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 729 | const MultiLevelTemplateArgumentList &TemplateArgs; | 
| Douglas Gregor | 17c0d7b | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 730 | SourceLocation Loc; | 
|  | 731 | DeclarationName Entity; | 
| Douglas Gregor | fe1e110 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 732 |  | 
| Douglas Gregor | 17c0d7b | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 733 | public: | 
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 734 | typedef TreeTransform<TemplateInstantiator> inherited; | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 735 |  | 
|  | 736 | TemplateInstantiator(Sema &SemaRef, | 
| Douglas Gregor | 01afeef | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 737 | const MultiLevelTemplateArgumentList &TemplateArgs, | 
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 738 | SourceLocation Loc, | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 739 | DeclarationName Entity) | 
|  | 740 | : inherited(SemaRef), TemplateArgs(TemplateArgs), Loc(Loc), | 
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 741 | Entity(Entity) { } | 
| Douglas Gregor | 17c0d7b | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 742 |  | 
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 743 | /// Determine whether the given type \p T has already been | 
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 744 | /// transformed. | 
|  | 745 | /// | 
|  | 746 | /// For the purposes of template instantiation, a type has already been | 
|  | 747 | /// transformed if it is NULL or if it is not dependent. | 
| Douglas Gregor | 5597ab4 | 2010-05-07 23:12:07 +0000 | [diff] [blame] | 748 | bool AlreadyTransformed(QualType T); | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 749 |  | 
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 750 | /// Returns the location of the entity being instantiated, if known. | 
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 751 | SourceLocation getBaseLocation() { return Loc; } | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 752 |  | 
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 753 | /// Returns the name of the entity being instantiated, if any. | 
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 754 | DeclarationName getBaseEntity() { return Entity; } | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 755 |  | 
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 756 | /// Sets the "base" location and entity when that | 
| Douglas Gregor | ef6ab41 | 2009-10-27 06:26:26 +0000 | [diff] [blame] | 757 | /// information is known based on another transformation. | 
|  | 758 | void setBase(SourceLocation Loc, DeclarationName Entity) { | 
|  | 759 | this->Loc = Loc; | 
|  | 760 | this->Entity = Entity; | 
|  | 761 | } | 
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 762 |  | 
|  | 763 | bool TryExpandParameterPacks(SourceLocation EllipsisLoc, | 
|  | 764 | SourceRange PatternRange, | 
| Robert Wilhelm | 16e94b9 | 2013-08-09 18:02:13 +0000 | [diff] [blame] | 765 | ArrayRef<UnexpandedParameterPack> Unexpanded, | 
|  | 766 | bool &ShouldExpand, bool &RetainExpansion, | 
| David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 767 | Optional<unsigned> &NumExpansions) { | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 768 | return getSema().CheckParameterPacksForExpansion(EllipsisLoc, | 
| Douglas Gregor | 76aca7b | 2010-12-21 00:52:54 +0000 | [diff] [blame] | 769 | PatternRange, Unexpanded, | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 770 | TemplateArgs, | 
| Douglas Gregor | 76aca7b | 2010-12-21 00:52:54 +0000 | [diff] [blame] | 771 | ShouldExpand, | 
| Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 772 | RetainExpansion, | 
| Douglas Gregor | 76aca7b | 2010-12-21 00:52:54 +0000 | [diff] [blame] | 773 | NumExpansions); | 
|  | 774 | } | 
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 775 |  | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 776 | void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { | 
| Douglas Gregor | f301011 | 2011-01-07 16:43:16 +0000 | [diff] [blame] | 777 | SemaRef.CurrentInstantiationScope->MakeInstantiatedLocalArgPack(Pack); | 
|  | 778 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 779 |  | 
| Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 780 | TemplateArgument ForgetPartiallySubstitutedPack() { | 
|  | 781 | TemplateArgument Result; | 
|  | 782 | if (NamedDecl *PartialPack | 
|  | 783 | = SemaRef.CurrentInstantiationScope->getPartiallySubstitutedPack()){ | 
|  | 784 | MultiLevelTemplateArgumentList &TemplateArgs | 
|  | 785 | = const_cast<MultiLevelTemplateArgumentList &>(this->TemplateArgs); | 
|  | 786 | unsigned Depth, Index; | 
| Benjamin Kramer | 867ea1d | 2014-03-02 13:01:17 +0000 | [diff] [blame] | 787 | std::tie(Depth, Index) = getDepthAndIndex(PartialPack); | 
| Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 788 | if (TemplateArgs.hasTemplateArgument(Depth, Index)) { | 
|  | 789 | Result = TemplateArgs(Depth, Index); | 
|  | 790 | TemplateArgs.setArgument(Depth, Index, TemplateArgument()); | 
|  | 791 | } | 
|  | 792 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 793 |  | 
| Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 794 | return Result; | 
|  | 795 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 796 |  | 
| Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 797 | void RememberPartiallySubstitutedPack(TemplateArgument Arg) { | 
|  | 798 | if (Arg.isNull()) | 
|  | 799 | return; | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 800 |  | 
| Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 801 | if (NamedDecl *PartialPack | 
|  | 802 | = SemaRef.CurrentInstantiationScope->getPartiallySubstitutedPack()){ | 
|  | 803 | MultiLevelTemplateArgumentList &TemplateArgs | 
|  | 804 | = const_cast<MultiLevelTemplateArgumentList &>(this->TemplateArgs); | 
|  | 805 | unsigned Depth, Index; | 
| Benjamin Kramer | 867ea1d | 2014-03-02 13:01:17 +0000 | [diff] [blame] | 806 | std::tie(Depth, Index) = getDepthAndIndex(PartialPack); | 
| Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 807 | TemplateArgs.setArgument(Depth, Index, Arg); | 
|  | 808 | } | 
|  | 809 | } | 
|  | 810 |  | 
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 811 | /// Transform the given declaration by instantiating a reference to | 
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 812 | /// this declaration. | 
| Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 813 | Decl *TransformDecl(SourceLocation Loc, Decl *D); | 
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 814 |  | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 815 | void transformAttrs(Decl *Old, Decl *New) { | 
| Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 816 | SemaRef.InstantiateAttrs(TemplateArgs, Old, New); | 
|  | 817 | } | 
|  | 818 |  | 
|  | 819 | void transformedLocalDecl(Decl *Old, Decl *New) { | 
| Richard Smith | c38498f | 2015-04-27 21:27:54 +0000 | [diff] [blame] | 820 | // If we've instantiated the call operator of a lambda or the call | 
|  | 821 | // operator template of a generic lambda, update the "instantiation of" | 
|  | 822 | // information. | 
|  | 823 | auto *NewMD = dyn_cast<CXXMethodDecl>(New); | 
|  | 824 | if (NewMD && isLambdaCallOperator(NewMD)) { | 
|  | 825 | auto *OldMD = dyn_cast<CXXMethodDecl>(Old); | 
|  | 826 | if (auto *NewTD = NewMD->getDescribedFunctionTemplate()) | 
|  | 827 | NewTD->setInstantiatedFromMemberTemplate( | 
|  | 828 | OldMD->getDescribedFunctionTemplate()); | 
|  | 829 | else | 
|  | 830 | NewMD->setInstantiationOfMemberFunction(OldMD, | 
|  | 831 | TSK_ImplicitInstantiation); | 
|  | 832 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 833 |  | 
| Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 834 | SemaRef.CurrentInstantiationScope->InstantiatedLocal(Old, New); | 
| Richard Smith | c7649dc | 2016-03-23 20:07:07 +0000 | [diff] [blame] | 835 |  | 
|  | 836 | // We recreated a local declaration, but not by instantiating it. There | 
|  | 837 | // may be pending dependent diagnostics to produce. | 
|  | 838 | if (auto *DC = dyn_cast<DeclContext>(Old)) | 
|  | 839 | SemaRef.PerformDependentDiagnostics(DC, TemplateArgs); | 
| Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 840 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 841 |  | 
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 842 | /// Transform the definition of the given declaration by | 
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 843 | /// instantiating it. | 
| Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 844 | Decl *TransformDefinition(SourceLocation Loc, Decl *D); | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 845 |  | 
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 846 | /// Transform the first qualifier within a scope by instantiating the | 
| Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 847 | /// declaration. | 
|  | 848 | NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 849 |  | 
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 850 | /// Rebuild the exception declaration and register the declaration | 
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 851 | /// as an instantiated local. | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 852 | VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, | 
| John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 853 | TypeSourceInfo *Declarator, | 
| Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 854 | SourceLocation StartLoc, | 
|  | 855 | SourceLocation NameLoc, | 
|  | 856 | IdentifierInfo *Name); | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 857 |  | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 858 | /// Rebuild the Objective-C exception declaration and register the | 
| Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 859 | /// declaration as an instantiated local. | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 860 | VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl, | 
| Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 861 | TypeSourceInfo *TSInfo, QualType T); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 862 |  | 
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 863 | /// Check for tag mismatches when instantiating an | 
| John McCall | 7f41d98 | 2009-09-11 04:59:25 +0000 | [diff] [blame] | 864 | /// elaborated type. | 
| John McCall | 954b5de | 2010-11-04 19:04:38 +0000 | [diff] [blame] | 865 | QualType RebuildElaboratedType(SourceLocation KeywordLoc, | 
|  | 866 | ElaboratedTypeKeyword Keyword, | 
| Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 867 | NestedNameSpecifierLoc QualifierLoc, | 
|  | 868 | QualType T); | 
| John McCall | 7f41d98 | 2009-09-11 04:59:25 +0000 | [diff] [blame] | 869 |  | 
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 870 | TemplateName | 
|  | 871 | TransformTemplateName(CXXScopeSpec &SS, TemplateName Name, | 
|  | 872 | SourceLocation NameLoc, | 
|  | 873 | QualType ObjectType = QualType(), | 
| Richard Smith | fd3dae0 | 2017-01-20 00:20:39 +0000 | [diff] [blame] | 874 | NamedDecl *FirstQualifierInScope = nullptr, | 
|  | 875 | bool AllowInjectedClassName = false); | 
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 876 |  | 
| Tyler Nowicki | c724a83e | 2014-10-12 20:46:07 +0000 | [diff] [blame] | 877 | const LoopHintAttr *TransformLoopHintAttr(const LoopHintAttr *LH); | 
|  | 878 |  | 
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 879 | ExprResult TransformPredefinedExpr(PredefinedExpr *E); | 
|  | 880 | ExprResult TransformDeclRefExpr(DeclRefExpr *E); | 
|  | 881 | ExprResult TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E); | 
| Richard Smith | b15fe3a | 2012-09-12 00:56:43 +0000 | [diff] [blame] | 882 |  | 
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 883 | ExprResult TransformTemplateParmRefExpr(DeclRefExpr *E, | 
| Douglas Gregor | eb5a39d | 2010-12-24 00:15:10 +0000 | [diff] [blame] | 884 | NonTypeTemplateParmDecl *D); | 
| Douglas Gregor | cdbc539 | 2011-01-15 01:15:58 +0000 | [diff] [blame] | 885 | ExprResult TransformSubstNonTypeTemplateParmPackExpr( | 
|  | 886 | SubstNonTypeTemplateParmPackExpr *E); | 
| Richard Smith | b15fe3a | 2012-09-12 00:56:43 +0000 | [diff] [blame] | 887 |  | 
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 888 | /// Rebuild a DeclRefExpr for a ParmVarDecl reference. | 
| Richard Smith | b15fe3a | 2012-09-12 00:56:43 +0000 | [diff] [blame] | 889 | ExprResult RebuildParmVarDeclRefExpr(ParmVarDecl *PD, SourceLocation Loc); | 
|  | 890 |  | 
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 891 | /// Transform a reference to a function parameter pack. | 
| Richard Smith | b15fe3a | 2012-09-12 00:56:43 +0000 | [diff] [blame] | 892 | ExprResult TransformFunctionParmPackRefExpr(DeclRefExpr *E, | 
|  | 893 | ParmVarDecl *PD); | 
|  | 894 |  | 
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 895 | /// Transform a FunctionParmPackExpr which was built when we couldn't | 
| Richard Smith | b15fe3a | 2012-09-12 00:56:43 +0000 | [diff] [blame] | 896 | /// expand a function parameter pack reference which refers to an expanded | 
|  | 897 | /// pack. | 
|  | 898 | ExprResult TransformFunctionParmPackExpr(FunctionParmPackExpr *E); | 
|  | 899 |  | 
| Hans Wennborg | e113c20 | 2014-09-18 16:01:32 +0000 | [diff] [blame] | 900 | QualType TransformFunctionProtoType(TypeLocBuilder &TLB, | 
| Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 901 | FunctionProtoTypeLoc TL) { | 
|  | 902 | // Call the base version; it will forward to our overridden version below. | 
|  | 903 | return inherited::TransformFunctionProtoType(TLB, TL); | 
|  | 904 | } | 
|  | 905 |  | 
|  | 906 | template<typename Fn> | 
| Douglas Gregor | 3024f07 | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 907 | QualType TransformFunctionProtoType(TypeLocBuilder &TLB, | 
|  | 908 | FunctionProtoTypeLoc TL, | 
|  | 909 | CXXRecordDecl *ThisContext, | 
| Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 910 | unsigned ThisTypeQuals, | 
|  | 911 | Fn TransformExceptionSpec); | 
| Douglas Gregor | 3024f07 | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 912 |  | 
| Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 913 | ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm, | 
| John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 914 | int indexAdjustment, | 
| David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 915 | Optional<unsigned> NumExpansions, | 
| Douglas Gregor | 0dd22bc | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 916 | bool ExpectParameterPack); | 
| John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 917 |  | 
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 918 | /// Transforms a template type parameter type by performing | 
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 919 | /// substitution of the corresponding template type argument. | 
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 920 | QualType TransformTemplateTypeParmType(TypeLocBuilder &TLB, | 
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 921 | TemplateTypeParmTypeLoc TL); | 
| Nick Lewycky | c96c37f | 2010-07-06 19:51:49 +0000 | [diff] [blame] | 922 |  | 
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 923 | /// Transforms an already-substituted template type parameter pack | 
| Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 924 | /// into either itself (if we aren't substituting into its pack expansion) | 
|  | 925 | /// or the appropriate substituted argument. | 
|  | 926 | QualType TransformSubstTemplateTypeParmPackType(TypeLocBuilder &TLB, | 
|  | 927 | SubstTemplateTypeParmPackTypeLoc TL); | 
|  | 928 |  | 
| Richard Smith | 2589b980 | 2012-07-25 03:56:55 +0000 | [diff] [blame] | 929 | ExprResult TransformLambdaExpr(LambdaExpr *E) { | 
|  | 930 | LocalInstantiationScope Scope(SemaRef, /*CombineWithOuterScope=*/true); | 
|  | 931 | return TreeTransform<TemplateInstantiator>::TransformLambdaExpr(E); | 
|  | 932 | } | 
|  | 933 |  | 
| David Majnemer | b100410 | 2014-03-02 18:46:05 +0000 | [diff] [blame] | 934 | TemplateParameterList *TransformTemplateParameterList( | 
| Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 935 | TemplateParameterList *OrigTPL)  { | 
|  | 936 | if (!OrigTPL || !OrigTPL->size()) return OrigTPL; | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 937 |  | 
| Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 938 | DeclContext *Owner = OrigTPL->getParam(0)->getDeclContext(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 939 | TemplateDeclInstantiator  DeclInstantiator(getSema(), | 
| Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 940 | /* DeclContext *Owner */ Owner, TemplateArgs); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 941 | return DeclInstantiator.SubstTemplateParams(OrigTPL); | 
| Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 942 | } | 
| John McCall | 7c454bb | 2011-07-15 05:09:51 +0000 | [diff] [blame] | 943 | private: | 
|  | 944 | ExprResult transformNonTypeTemplateParmRef(NonTypeTemplateParmDecl *parm, | 
|  | 945 | SourceLocation loc, | 
| Richard Smith | 3434900 | 2012-07-09 03:07:20 +0000 | [diff] [blame] | 946 | TemplateArgument arg); | 
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 947 | }; | 
| Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 948 | } | 
| Douglas Gregor | 0431825 | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 949 |  | 
| Douglas Gregor | 5597ab4 | 2010-05-07 23:12:07 +0000 | [diff] [blame] | 950 | bool TemplateInstantiator::AlreadyTransformed(QualType T) { | 
|  | 951 | if (T.isNull()) | 
|  | 952 | return true; | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 953 |  | 
| Douglas Gregor | 678d76c | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 954 | if (T->isInstantiationDependentType() || T->isVariablyModifiedType()) | 
| Douglas Gregor | 5597ab4 | 2010-05-07 23:12:07 +0000 | [diff] [blame] | 955 | return false; | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 956 |  | 
| Douglas Gregor | 5597ab4 | 2010-05-07 23:12:07 +0000 | [diff] [blame] | 957 | getSema().MarkDeclarationsReferencedInType(Loc, T); | 
|  | 958 | return true; | 
|  | 959 | } | 
|  | 960 |  | 
| Eli Friedman | 8917ad5 | 2013-07-19 19:40:38 +0000 | [diff] [blame] | 961 | static TemplateArgument | 
|  | 962 | getPackSubstitutedTemplateArgument(Sema &S, TemplateArgument Arg) { | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 963 | assert(S.ArgumentPackSubstitutionIndex >= 0); | 
| Eli Friedman | 8917ad5 | 2013-07-19 19:40:38 +0000 | [diff] [blame] | 964 | assert(S.ArgumentPackSubstitutionIndex < (int)Arg.pack_size()); | 
|  | 965 | Arg = Arg.pack_begin()[S.ArgumentPackSubstitutionIndex]; | 
|  | 966 | if (Arg.isPackExpansion()) | 
|  | 967 | Arg = Arg.getPackExpansionPattern(); | 
|  | 968 | return Arg; | 
|  | 969 | } | 
|  | 970 |  | 
| Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 971 | Decl *TemplateInstantiator::TransformDecl(SourceLocation Loc, Decl *D) { | 
| Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 972 | if (!D) | 
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 973 | return nullptr; | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 974 |  | 
| Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 975 | if (TemplateTemplateParmDecl *TTP = dyn_cast<TemplateTemplateParmDecl>(D)) { | 
| Douglas Gregor | 01afeef | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 976 | if (TTP->getDepth() < TemplateArgs.getNumLevels()) { | 
| Douglas Gregor | b9397108 | 2010-02-05 19:54:12 +0000 | [diff] [blame] | 977 | // If the corresponding template argument is NULL or non-existent, it's | 
|  | 978 | // because we are performing instantiation from explicitly-specified | 
|  | 979 | // template arguments in a function template, but there were some | 
|  | 980 | // arguments left unspecified. | 
|  | 981 | if (!TemplateArgs.hasTemplateArgument(TTP->getDepth(), | 
|  | 982 | TTP->getPosition())) | 
|  | 983 | return D; | 
|  | 984 |  | 
| Douglas Gregor | f550077 | 2011-01-05 15:48:55 +0000 | [diff] [blame] | 985 | TemplateArgument Arg = TemplateArgs(TTP->getDepth(), TTP->getPosition()); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 986 |  | 
| Douglas Gregor | f550077 | 2011-01-05 15:48:55 +0000 | [diff] [blame] | 987 | if (TTP->isParameterPack()) { | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 988 | assert(Arg.getKind() == TemplateArgument::Pack && | 
| Douglas Gregor | f550077 | 2011-01-05 15:48:55 +0000 | [diff] [blame] | 989 | "Missing argument pack"); | 
| Eli Friedman | 8917ad5 | 2013-07-19 19:40:38 +0000 | [diff] [blame] | 990 | Arg = getPackSubstitutedTemplateArgument(getSema(), Arg); | 
| Douglas Gregor | f550077 | 2011-01-05 15:48:55 +0000 | [diff] [blame] | 991 | } | 
|  | 992 |  | 
| Richard Smith | 1abacfc | 2017-08-29 22:14:43 +0000 | [diff] [blame] | 993 | TemplateName Template = Arg.getAsTemplate().getNameToSubstitute(); | 
| Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 994 | assert(!Template.isNull() && Template.getAsTemplateDecl() && | 
| Douglas Gregor | 01afeef | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 995 | "Wrong kind of template template argument"); | 
| Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 996 | return Template.getAsTemplateDecl(); | 
| Douglas Gregor | 01afeef | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 997 | } | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 998 |  | 
| Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 999 | // Fall through to find the instantiated declaration for this template | 
|  | 1000 | // template parameter. | 
| Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1001 | } | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1002 |  | 
| Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 1003 | return SemaRef.FindInstantiatedDecl(Loc, cast<NamedDecl>(D), TemplateArgs); | 
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 1004 | } | 
|  | 1005 |  | 
| Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 1006 | Decl *TemplateInstantiator::TransformDefinition(SourceLocation Loc, Decl *D) { | 
| John McCall | 76d824f | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 1007 | Decl *Inst = getSema().SubstDecl(D, getSema().CurContext, TemplateArgs); | 
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1008 | if (!Inst) | 
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 1009 | return nullptr; | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1010 |  | 
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1011 | getSema().CurrentInstantiationScope->InstantiatedLocal(D, Inst); | 
|  | 1012 | return Inst; | 
|  | 1013 | } | 
|  | 1014 |  | 
| Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 1015 | NamedDecl * | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1016 | TemplateInstantiator::TransformFirstQualifierInScope(NamedDecl *D, | 
| Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 1017 | SourceLocation Loc) { | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1018 | // If the first part of the nested-name-specifier was a template type | 
| Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 1019 | // parameter, instantiate that type parameter down to a tag type. | 
|  | 1020 | if (TemplateTypeParmDecl *TTPD = dyn_cast_or_null<TemplateTypeParmDecl>(D)) { | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1021 | const TemplateTypeParmType *TTP | 
| Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 1022 | = cast<TemplateTypeParmType>(getSema().Context.getTypeDeclType(TTPD)); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1023 |  | 
| Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 1024 | if (TTP->getDepth() < TemplateArgs.getNumLevels()) { | 
| Douglas Gregor | 53c3f4e | 2010-12-20 22:48:17 +0000 | [diff] [blame] | 1025 | // FIXME: This needs testing w/ member access expressions. | 
|  | 1026 | TemplateArgument Arg = TemplateArgs(TTP->getDepth(), TTP->getIndex()); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1027 |  | 
| Douglas Gregor | 53c3f4e | 2010-12-20 22:48:17 +0000 | [diff] [blame] | 1028 | if (TTP->isParameterPack()) { | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1029 | assert(Arg.getKind() == TemplateArgument::Pack && | 
| Douglas Gregor | 53c3f4e | 2010-12-20 22:48:17 +0000 | [diff] [blame] | 1030 | "Missing argument pack"); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1031 |  | 
| Douglas Gregor | e1d60df | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 1032 | if (getSema().ArgumentPackSubstitutionIndex == -1) | 
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 1033 | return nullptr; | 
|  | 1034 |  | 
| Eli Friedman | 8917ad5 | 2013-07-19 19:40:38 +0000 | [diff] [blame] | 1035 | Arg = getPackSubstitutedTemplateArgument(getSema(), Arg); | 
| Douglas Gregor | 53c3f4e | 2010-12-20 22:48:17 +0000 | [diff] [blame] | 1036 | } | 
|  | 1037 |  | 
|  | 1038 | QualType T = Arg.getAsType(); | 
| Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 1039 | if (T.isNull()) | 
| Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 1040 | return cast_or_null<NamedDecl>(TransformDecl(Loc, D)); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1041 |  | 
| Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 1042 | if (const TagType *Tag = T->getAs<TagType>()) | 
|  | 1043 | return Tag->getDecl(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1044 |  | 
| Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 1045 | // The resulting type is not a tag; complain. | 
|  | 1046 | getSema().Diag(Loc, diag::err_nested_name_spec_non_tag) << T; | 
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 1047 | return nullptr; | 
| Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 1048 | } | 
|  | 1049 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1050 |  | 
| Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 1051 | return cast_or_null<NamedDecl>(TransformDecl(Loc, D)); | 
| Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 1052 | } | 
|  | 1053 |  | 
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1054 | VarDecl * | 
|  | 1055 | TemplateInstantiator::RebuildExceptionDecl(VarDecl *ExceptionDecl, | 
| John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1056 | TypeSourceInfo *Declarator, | 
| Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1057 | SourceLocation StartLoc, | 
|  | 1058 | SourceLocation NameLoc, | 
|  | 1059 | IdentifierInfo *Name) { | 
| Douglas Gregor | 9f0e1aa | 2010-09-09 17:09:21 +0000 | [diff] [blame] | 1060 | VarDecl *Var = inherited::RebuildExceptionDecl(ExceptionDecl, Declarator, | 
| Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1061 | StartLoc, NameLoc, Name); | 
| Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1062 | if (Var) | 
|  | 1063 | getSema().CurrentInstantiationScope->InstantiatedLocal(ExceptionDecl, Var); | 
|  | 1064 | return Var; | 
|  | 1065 | } | 
|  | 1066 |  | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1067 | VarDecl *TemplateInstantiator::RebuildObjCExceptionDecl(VarDecl *ExceptionDecl, | 
|  | 1068 | TypeSourceInfo *TSInfo, | 
| Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1069 | QualType T) { | 
|  | 1070 | VarDecl *Var = inherited::RebuildObjCExceptionDecl(ExceptionDecl, TSInfo, T); | 
|  | 1071 | if (Var) | 
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1072 | getSema().CurrentInstantiationScope->InstantiatedLocal(ExceptionDecl, Var); | 
|  | 1073 | return Var; | 
|  | 1074 | } | 
|  | 1075 |  | 
| John McCall | 7f41d98 | 2009-09-11 04:59:25 +0000 | [diff] [blame] | 1076 | QualType | 
| John McCall | 954b5de | 2010-11-04 19:04:38 +0000 | [diff] [blame] | 1077 | TemplateInstantiator::RebuildElaboratedType(SourceLocation KeywordLoc, | 
|  | 1078 | ElaboratedTypeKeyword Keyword, | 
| Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 1079 | NestedNameSpecifierLoc QualifierLoc, | 
| Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 1080 | QualType T) { | 
| John McCall | 7f41d98 | 2009-09-11 04:59:25 +0000 | [diff] [blame] | 1081 | if (const TagType *TT = T->getAs<TagType>()) { | 
|  | 1082 | TagDecl* TD = TT->getDecl(); | 
|  | 1083 |  | 
| John McCall | 954b5de | 2010-11-04 19:04:38 +0000 | [diff] [blame] | 1084 | SourceLocation TagLocation = KeywordLoc; | 
| John McCall | 7f41d98 | 2009-09-11 04:59:25 +0000 | [diff] [blame] | 1085 |  | 
| John McCall | 7f41d98 | 2009-09-11 04:59:25 +0000 | [diff] [blame] | 1086 | IdentifierInfo *Id = TD->getIdentifier(); | 
|  | 1087 |  | 
|  | 1088 | // TODO: should we even warn on struct/class mismatches for this?  Seems | 
|  | 1089 | // like it's likely to produce a lot of spurious errors. | 
| Richard Smith | 80b3c5a | 2012-08-17 00:12:27 +0000 | [diff] [blame] | 1090 | if (Id && Keyword != ETK_None && Keyword != ETK_Typename) { | 
| Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 1091 | TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword); | 
| Richard Trieu | caa33d3 | 2011-06-10 03:11:26 +0000 | [diff] [blame] | 1092 | if (!SemaRef.isAcceptableTagRedeclaration(TD, Kind, /*isDefinition*/false, | 
| Justin Bogner | c6ecb7c | 2015-07-10 23:05:47 +0000 | [diff] [blame] | 1093 | TagLocation, Id)) { | 
| Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 1094 | SemaRef.Diag(TagLocation, diag::err_use_with_wrong_tag) | 
|  | 1095 | << Id | 
|  | 1096 | << FixItHint::CreateReplacement(SourceRange(TagLocation), | 
|  | 1097 | TD->getKindName()); | 
|  | 1098 | SemaRef.Diag(TD->getLocation(), diag::note_previous_use); | 
|  | 1099 | } | 
| John McCall | 7f41d98 | 2009-09-11 04:59:25 +0000 | [diff] [blame] | 1100 | } | 
|  | 1101 | } | 
|  | 1102 |  | 
| John McCall | 954b5de | 2010-11-04 19:04:38 +0000 | [diff] [blame] | 1103 | return TreeTransform<TemplateInstantiator>::RebuildElaboratedType(KeywordLoc, | 
|  | 1104 | Keyword, | 
| Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 1105 | QualifierLoc, | 
|  | 1106 | T); | 
| John McCall | 7f41d98 | 2009-09-11 04:59:25 +0000 | [diff] [blame] | 1107 | } | 
|  | 1108 |  | 
| Richard Smith | fd3dae0 | 2017-01-20 00:20:39 +0000 | [diff] [blame] | 1109 | TemplateName TemplateInstantiator::TransformTemplateName( | 
|  | 1110 | CXXScopeSpec &SS, TemplateName Name, SourceLocation NameLoc, | 
|  | 1111 | QualType ObjectType, NamedDecl *FirstQualifierInScope, | 
|  | 1112 | bool AllowInjectedClassName) { | 
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 1113 | if (TemplateTemplateParmDecl *TTP | 
|  | 1114 | = dyn_cast_or_null<TemplateTemplateParmDecl>(Name.getAsTemplateDecl())) { | 
|  | 1115 | if (TTP->getDepth() < TemplateArgs.getNumLevels()) { | 
|  | 1116 | // If the corresponding template argument is NULL or non-existent, it's | 
|  | 1117 | // because we are performing instantiation from explicitly-specified | 
|  | 1118 | // template arguments in a function template, but there were some | 
|  | 1119 | // arguments left unspecified. | 
|  | 1120 | if (!TemplateArgs.hasTemplateArgument(TTP->getDepth(), | 
|  | 1121 | TTP->getPosition())) | 
|  | 1122 | return Name; | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1123 |  | 
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 1124 | TemplateArgument Arg = TemplateArgs(TTP->getDepth(), TTP->getPosition()); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1125 |  | 
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 1126 | if (TTP->isParameterPack()) { | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1127 | assert(Arg.getKind() == TemplateArgument::Pack && | 
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 1128 | "Missing argument pack"); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1129 |  | 
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 1130 | if (getSema().ArgumentPackSubstitutionIndex == -1) { | 
|  | 1131 | // We have the template argument pack to substitute, but we're not | 
|  | 1132 | // actually expanding the enclosing pack expansion yet. So, just | 
|  | 1133 | // keep the entire argument pack. | 
|  | 1134 | return getSema().Context.getSubstTemplateTemplateParmPack(TTP, Arg); | 
|  | 1135 | } | 
| Eli Friedman | 8917ad5 | 2013-07-19 19:40:38 +0000 | [diff] [blame] | 1136 |  | 
|  | 1137 | Arg = getPackSubstitutedTemplateArgument(getSema(), Arg); | 
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 1138 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1139 |  | 
| Richard Smith | 1abacfc | 2017-08-29 22:14:43 +0000 | [diff] [blame] | 1140 | TemplateName Template = Arg.getAsTemplate().getNameToSubstitute(); | 
| Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 1141 | assert(!Template.isNull() && "Null template template argument"); | 
| Richard Smith | 1abacfc | 2017-08-29 22:14:43 +0000 | [diff] [blame] | 1142 | assert(!Template.getAsQualifiedTemplateName() && | 
|  | 1143 | "template decl to substitute is qualified?"); | 
| John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 1144 |  | 
|  | 1145 | Template = getSema().Context.getSubstTemplateTemplateParm(TTP, Template); | 
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 1146 | return Template; | 
|  | 1147 | } | 
|  | 1148 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1149 |  | 
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 1150 | if (SubstTemplateTemplateParmPackStorage *SubstPack | 
|  | 1151 | = Name.getAsSubstTemplateTemplateParmPack()) { | 
|  | 1152 | if (getSema().ArgumentPackSubstitutionIndex == -1) | 
|  | 1153 | return Name; | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1154 |  | 
| Eli Friedman | 8917ad5 | 2013-07-19 19:40:38 +0000 | [diff] [blame] | 1155 | TemplateArgument Arg = SubstPack->getArgumentPack(); | 
|  | 1156 | Arg = getPackSubstitutedTemplateArgument(getSema(), Arg); | 
| Richard Smith | 1abacfc | 2017-08-29 22:14:43 +0000 | [diff] [blame] | 1157 | return Arg.getAsTemplate().getNameToSubstitute(); | 
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 1158 | } | 
| Richard Smith | fd3dae0 | 2017-01-20 00:20:39 +0000 | [diff] [blame] | 1159 |  | 
|  | 1160 | return inherited::TransformTemplateName(SS, Name, NameLoc, ObjectType, | 
|  | 1161 | FirstQualifierInScope, | 
|  | 1162 | AllowInjectedClassName); | 
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 1163 | } | 
|  | 1164 |  | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1165 | ExprResult | 
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 1166 | TemplateInstantiator::TransformPredefinedExpr(PredefinedExpr *E) { | 
| Anders Carlsson | 0b209a8 | 2009-09-11 01:22:35 +0000 | [diff] [blame] | 1167 | if (!E->isTypeDependent()) | 
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 1168 | return E; | 
| Anders Carlsson | 0b209a8 | 2009-09-11 01:22:35 +0000 | [diff] [blame] | 1169 |  | 
| Wei Pan | c354d21 | 2013-09-16 13:57:27 +0000 | [diff] [blame] | 1170 | return getSema().BuildPredefinedExpr(E->getLocation(), E->getIdentType()); | 
| Anders Carlsson | 0b209a8 | 2009-09-11 01:22:35 +0000 | [diff] [blame] | 1171 | } | 
|  | 1172 |  | 
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1173 | ExprResult | 
| John McCall | 13481c5 | 2010-02-06 08:42:39 +0000 | [diff] [blame] | 1174 | TemplateInstantiator::TransformTemplateParmRefExpr(DeclRefExpr *E, | 
| Douglas Gregor | 6c379e2 | 2010-02-08 23:41:45 +0000 | [diff] [blame] | 1175 | NonTypeTemplateParmDecl *NTTP) { | 
| John McCall | 13481c5 | 2010-02-06 08:42:39 +0000 | [diff] [blame] | 1176 | // If the corresponding template argument is NULL or non-existent, it's | 
|  | 1177 | // because we are performing instantiation from explicitly-specified | 
|  | 1178 | // template arguments in a function template, but there were some | 
|  | 1179 | // arguments left unspecified. | 
|  | 1180 | if (!TemplateArgs.hasTemplateArgument(NTTP->getDepth(), | 
|  | 1181 | NTTP->getPosition())) | 
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 1182 | return E; | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1183 |  | 
| Douglas Gregor | eb5a39d | 2010-12-24 00:15:10 +0000 | [diff] [blame] | 1184 | TemplateArgument Arg = TemplateArgs(NTTP->getDepth(), NTTP->getPosition()); | 
| Richard Smith | b4f9625 | 2017-02-21 06:30:38 +0000 | [diff] [blame] | 1185 |  | 
|  | 1186 | if (TemplateArgs.getNumLevels() != TemplateArgs.getNumSubstitutedLevels()) { | 
|  | 1187 | // We're performing a partial substitution, so the substituted argument | 
|  | 1188 | // could be dependent. As a result we can't create a SubstNonType*Expr | 
|  | 1189 | // node now, since that represents a fully-substituted argument. | 
|  | 1190 | // FIXME: We should have some AST representation for this. | 
|  | 1191 | if (Arg.getKind() == TemplateArgument::Pack) { | 
|  | 1192 | // FIXME: This won't work for alias templates. | 
|  | 1193 | assert(Arg.pack_size() == 1 && Arg.pack_begin()->isPackExpansion() && | 
|  | 1194 | "unexpected pack arguments in partial substitution"); | 
|  | 1195 | Arg = Arg.pack_begin()->getPackExpansionPattern(); | 
|  | 1196 | } | 
|  | 1197 | assert(Arg.getKind() == TemplateArgument::Expression && | 
|  | 1198 | "unexpected nontype template argument kind in partial substitution"); | 
|  | 1199 | return Arg.getAsExpr(); | 
|  | 1200 | } | 
|  | 1201 |  | 
| Douglas Gregor | eb5a39d | 2010-12-24 00:15:10 +0000 | [diff] [blame] | 1202 | if (NTTP->isParameterPack()) { | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1203 | assert(Arg.getKind() == TemplateArgument::Pack && | 
| Douglas Gregor | eb5a39d | 2010-12-24 00:15:10 +0000 | [diff] [blame] | 1204 | "Missing argument pack"); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1205 |  | 
| Douglas Gregor | eb5a39d | 2010-12-24 00:15:10 +0000 | [diff] [blame] | 1206 | if (getSema().ArgumentPackSubstitutionIndex == -1) { | 
| Douglas Gregor | cdbc539 | 2011-01-15 01:15:58 +0000 | [diff] [blame] | 1207 | // We have an argument pack, but we can't select a particular argument | 
|  | 1208 | // out of it yet. Therefore, we'll build an expression to hold on to that | 
|  | 1209 | // argument pack. | 
|  | 1210 | QualType TargetType = SemaRef.SubstType(NTTP->getType(), TemplateArgs, | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1211 | E->getLocation(), | 
| Douglas Gregor | cdbc539 | 2011-01-15 01:15:58 +0000 | [diff] [blame] | 1212 | NTTP->getDeclName()); | 
|  | 1213 | if (TargetType.isNull()) | 
|  | 1214 | return ExprError(); | 
| Richard Smith | f1f20e6 | 2018-02-14 02:07:53 +0000 | [diff] [blame] | 1215 |  | 
|  | 1216 | return new (SemaRef.Context) SubstNonTypeTemplateParmPackExpr( | 
|  | 1217 | TargetType.getNonLValueExprType(SemaRef.Context), | 
|  | 1218 | TargetType->isReferenceType() ? VK_LValue : VK_RValue, NTTP, | 
|  | 1219 | E->getLocation(), Arg); | 
| Douglas Gregor | eb5a39d | 2010-12-24 00:15:10 +0000 | [diff] [blame] | 1220 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1221 |  | 
| Eli Friedman | 8917ad5 | 2013-07-19 19:40:38 +0000 | [diff] [blame] | 1222 | Arg = getPackSubstitutedTemplateArgument(getSema(), Arg); | 
| Douglas Gregor | eb5a39d | 2010-12-24 00:15:10 +0000 | [diff] [blame] | 1223 | } | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1224 |  | 
| John McCall | 7c454bb | 2011-07-15 05:09:51 +0000 | [diff] [blame] | 1225 | return transformNonTypeTemplateParmRef(NTTP, E->getLocation(), Arg); | 
|  | 1226 | } | 
|  | 1227 |  | 
| Tyler Nowicki | c724a83e | 2014-10-12 20:46:07 +0000 | [diff] [blame] | 1228 | const LoopHintAttr * | 
|  | 1229 | TemplateInstantiator::TransformLoopHintAttr(const LoopHintAttr *LH) { | 
|  | 1230 | Expr *TransformedExpr = getDerived().TransformExpr(LH->getValue()).get(); | 
|  | 1231 |  | 
|  | 1232 | if (TransformedExpr == LH->getValue()) | 
|  | 1233 | return LH; | 
|  | 1234 |  | 
|  | 1235 | // Generate error if there is a problem with the value. | 
|  | 1236 | if (getSema().CheckLoopHintExpr(TransformedExpr, LH->getLocation())) | 
|  | 1237 | return LH; | 
|  | 1238 |  | 
|  | 1239 | // Create new LoopHintValueAttr with integral expression in place of the | 
|  | 1240 | // non-type template parameter. | 
|  | 1241 | return LoopHintAttr::CreateImplicit( | 
|  | 1242 | getSema().Context, LH->getSemanticSpelling(), LH->getOption(), | 
|  | 1243 | LH->getState(), TransformedExpr, LH->getRange()); | 
|  | 1244 | } | 
|  | 1245 |  | 
| John McCall | 7c454bb | 2011-07-15 05:09:51 +0000 | [diff] [blame] | 1246 | ExprResult TemplateInstantiator::transformNonTypeTemplateParmRef( | 
|  | 1247 | NonTypeTemplateParmDecl *parm, | 
|  | 1248 | SourceLocation loc, | 
| Richard Smith | 3434900 | 2012-07-09 03:07:20 +0000 | [diff] [blame] | 1249 | TemplateArgument arg) { | 
| John McCall | 7c454bb | 2011-07-15 05:09:51 +0000 | [diff] [blame] | 1250 | ExprResult result; | 
|  | 1251 | QualType type; | 
|  | 1252 |  | 
| John McCall | 13481c5 | 2010-02-06 08:42:39 +0000 | [diff] [blame] | 1253 | // The template argument itself might be an expression, in which | 
|  | 1254 | // case we just return that expression. | 
| John McCall | 7c454bb | 2011-07-15 05:09:51 +0000 | [diff] [blame] | 1255 | if (arg.getKind() == TemplateArgument::Expression) { | 
|  | 1256 | Expr *argExpr = arg.getAsExpr(); | 
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 1257 | result = argExpr; | 
| John McCall | 7c454bb | 2011-07-15 05:09:51 +0000 | [diff] [blame] | 1258 | type = argExpr->getType(); | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1259 |  | 
| Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 1260 | } else if (arg.getKind() == TemplateArgument::Declaration || | 
|  | 1261 | arg.getKind() == TemplateArgument::NullPtr) { | 
| Douglas Gregor | 31f55dc | 2012-04-06 22:40:38 +0000 | [diff] [blame] | 1262 | ValueDecl *VD; | 
| Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 1263 | if (arg.getKind() == TemplateArgument::Declaration) { | 
| George Burgess IV | 00f70bd | 2018-03-01 05:43:23 +0000 | [diff] [blame] | 1264 | VD = arg.getAsDecl(); | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1265 |  | 
| Douglas Gregor | 31f55dc | 2012-04-06 22:40:38 +0000 | [diff] [blame] | 1266 | // Find the instantiation of the template argument.  This is | 
|  | 1267 | // required for nested templates. | 
|  | 1268 | VD = cast_or_null<ValueDecl>( | 
|  | 1269 | getSema().FindInstantiatedDecl(loc, VD, TemplateArgs)); | 
|  | 1270 | if (!VD) | 
|  | 1271 | return ExprError(); | 
|  | 1272 | } else { | 
|  | 1273 | // Propagate NULL template argument. | 
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 1274 | VD = nullptr; | 
| Douglas Gregor | 31f55dc | 2012-04-06 22:40:38 +0000 | [diff] [blame] | 1275 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1276 |  | 
| John McCall | 15dda37 | 2010-02-06 10:23:53 +0000 | [diff] [blame] | 1277 | // Derive the type we want the substituted decl to have.  This had | 
|  | 1278 | // better be non-dependent, or these checks will have serious problems. | 
| John McCall | 7c454bb | 2011-07-15 05:09:51 +0000 | [diff] [blame] | 1279 | if (parm->isExpandedParameterPack()) { | 
|  | 1280 | type = parm->getExpansionType(SemaRef.ArgumentPackSubstitutionIndex); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1281 | } else if (parm->isParameterPack() && | 
| John McCall | 7c454bb | 2011-07-15 05:09:51 +0000 | [diff] [blame] | 1282 | isa<PackExpansionType>(parm->getType())) { | 
|  | 1283 | type = SemaRef.SubstType( | 
|  | 1284 | cast<PackExpansionType>(parm->getType())->getPattern(), | 
|  | 1285 | TemplateArgs, loc, parm->getDeclName()); | 
|  | 1286 | } else { | 
| Richard Smith | 5f27438 | 2016-09-28 23:55:27 +0000 | [diff] [blame] | 1287 | type = SemaRef.SubstType(VD ? arg.getParamTypeForDecl() : arg.getNullPtrType(), | 
|  | 1288 | TemplateArgs, loc, parm->getDeclName()); | 
| John McCall | 7c454bb | 2011-07-15 05:09:51 +0000 | [diff] [blame] | 1289 | } | 
|  | 1290 | assert(!type.isNull() && "type substitution failed for param type"); | 
|  | 1291 | assert(!type->isDependentType() && "param type still dependent"); | 
|  | 1292 | result = SemaRef.BuildExpressionFromDeclTemplateArgument(arg, type, loc); | 
| John McCall | 13481c5 | 2010-02-06 08:42:39 +0000 | [diff] [blame] | 1293 |  | 
| John McCall | 7c454bb | 2011-07-15 05:09:51 +0000 | [diff] [blame] | 1294 | if (!result.isInvalid()) type = result.get()->getType(); | 
|  | 1295 | } else { | 
|  | 1296 | result = SemaRef.BuildExpressionFromIntegralTemplateArgument(arg, loc); | 
|  | 1297 |  | 
|  | 1298 | // Note that this type can be different from the type of 'result', | 
|  | 1299 | // e.g. if it's an enum type. | 
|  | 1300 | type = arg.getIntegralType(); | 
|  | 1301 | } | 
|  | 1302 | if (result.isInvalid()) return ExprError(); | 
|  | 1303 |  | 
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 1304 | Expr *resultExpr = result.get(); | 
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 1305 | return new (SemaRef.Context) SubstNonTypeTemplateParmExpr( | 
|  | 1306 | type, resultExpr->getValueKind(), loc, parm, resultExpr); | 
| John McCall | 13481c5 | 2010-02-06 08:42:39 +0000 | [diff] [blame] | 1307 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1308 |  | 
|  | 1309 | ExprResult | 
| Douglas Gregor | cdbc539 | 2011-01-15 01:15:58 +0000 | [diff] [blame] | 1310 | TemplateInstantiator::TransformSubstNonTypeTemplateParmPackExpr( | 
|  | 1311 | SubstNonTypeTemplateParmPackExpr *E) { | 
|  | 1312 | if (getSema().ArgumentPackSubstitutionIndex == -1) { | 
|  | 1313 | // We aren't expanding the parameter pack, so just return ourselves. | 
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 1314 | return E; | 
| Douglas Gregor | cdbc539 | 2011-01-15 01:15:58 +0000 | [diff] [blame] | 1315 | } | 
| Eli Friedman | 8917ad5 | 2013-07-19 19:40:38 +0000 | [diff] [blame] | 1316 |  | 
|  | 1317 | TemplateArgument Arg = E->getArgumentPack(); | 
|  | 1318 | Arg = getPackSubstitutedTemplateArgument(getSema(), Arg); | 
| John McCall | 7c454bb | 2011-07-15 05:09:51 +0000 | [diff] [blame] | 1319 | return transformNonTypeTemplateParmRef(E->getParameterPack(), | 
|  | 1320 | E->getParameterPackLocation(), | 
|  | 1321 | Arg); | 
| Douglas Gregor | cdbc539 | 2011-01-15 01:15:58 +0000 | [diff] [blame] | 1322 | } | 
| John McCall | 13481c5 | 2010-02-06 08:42:39 +0000 | [diff] [blame] | 1323 |  | 
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1324 | ExprResult | 
| Richard Smith | b15fe3a | 2012-09-12 00:56:43 +0000 | [diff] [blame] | 1325 | TemplateInstantiator::RebuildParmVarDeclRefExpr(ParmVarDecl *PD, | 
|  | 1326 | SourceLocation Loc) { | 
|  | 1327 | DeclarationNameInfo NameInfo(PD->getDeclName(), Loc); | 
|  | 1328 | return getSema().BuildDeclarationNameExpr(CXXScopeSpec(), NameInfo, PD); | 
|  | 1329 | } | 
|  | 1330 |  | 
|  | 1331 | ExprResult | 
|  | 1332 | TemplateInstantiator::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) { | 
|  | 1333 | if (getSema().ArgumentPackSubstitutionIndex != -1) { | 
|  | 1334 | // We can expand this parameter pack now. | 
|  | 1335 | ParmVarDecl *D = E->getExpansion(getSema().ArgumentPackSubstitutionIndex); | 
|  | 1336 | ValueDecl *VD = cast_or_null<ValueDecl>(TransformDecl(E->getExprLoc(), D)); | 
|  | 1337 | if (!VD) | 
|  | 1338 | return ExprError(); | 
|  | 1339 | return RebuildParmVarDeclRefExpr(cast<ParmVarDecl>(VD), E->getExprLoc()); | 
|  | 1340 | } | 
|  | 1341 |  | 
|  | 1342 | QualType T = TransformType(E->getType()); | 
|  | 1343 | if (T.isNull()) | 
|  | 1344 | return ExprError(); | 
|  | 1345 |  | 
|  | 1346 | // Transform each of the parameter expansions into the corresponding | 
|  | 1347 | // parameters in the instantiation of the function decl. | 
| James Y Knight | 48fefa3 | 2015-09-30 14:04:23 +0000 | [diff] [blame] | 1348 | SmallVector<ParmVarDecl *, 8> Parms; | 
| Richard Smith | b15fe3a | 2012-09-12 00:56:43 +0000 | [diff] [blame] | 1349 | Parms.reserve(E->getNumExpansions()); | 
|  | 1350 | for (FunctionParmPackExpr::iterator I = E->begin(), End = E->end(); | 
|  | 1351 | I != End; ++I) { | 
|  | 1352 | ParmVarDecl *D = | 
|  | 1353 | cast_or_null<ParmVarDecl>(TransformDecl(E->getExprLoc(), *I)); | 
|  | 1354 | if (!D) | 
|  | 1355 | return ExprError(); | 
|  | 1356 | Parms.push_back(D); | 
|  | 1357 | } | 
|  | 1358 |  | 
|  | 1359 | return FunctionParmPackExpr::Create(getSema().Context, T, | 
|  | 1360 | E->getParameterPack(), | 
|  | 1361 | E->getParameterPackLocation(), Parms); | 
|  | 1362 | } | 
|  | 1363 |  | 
|  | 1364 | ExprResult | 
|  | 1365 | TemplateInstantiator::TransformFunctionParmPackRefExpr(DeclRefExpr *E, | 
|  | 1366 | ParmVarDecl *PD) { | 
|  | 1367 | typedef LocalInstantiationScope::DeclArgumentPack DeclArgumentPack; | 
|  | 1368 | llvm::PointerUnion<Decl *, DeclArgumentPack *> *Found | 
|  | 1369 | = getSema().CurrentInstantiationScope->findInstantiationOf(PD); | 
|  | 1370 | assert(Found && "no instantiation for parameter pack"); | 
|  | 1371 |  | 
|  | 1372 | Decl *TransformedDecl; | 
|  | 1373 | if (DeclArgumentPack *Pack = Found->dyn_cast<DeclArgumentPack *>()) { | 
| Nico Weber | c153d24 | 2014-07-28 00:02:09 +0000 | [diff] [blame] | 1374 | // If this is a reference to a function parameter pack which we can | 
|  | 1375 | // substitute but can't yet expand, build a FunctionParmPackExpr for it. | 
| Richard Smith | b15fe3a | 2012-09-12 00:56:43 +0000 | [diff] [blame] | 1376 | if (getSema().ArgumentPackSubstitutionIndex == -1) { | 
|  | 1377 | QualType T = TransformType(E->getType()); | 
|  | 1378 | if (T.isNull()) | 
|  | 1379 | return ExprError(); | 
|  | 1380 | return FunctionParmPackExpr::Create(getSema().Context, T, PD, | 
|  | 1381 | E->getExprLoc(), *Pack); | 
|  | 1382 | } | 
|  | 1383 |  | 
|  | 1384 | TransformedDecl = (*Pack)[getSema().ArgumentPackSubstitutionIndex]; | 
|  | 1385 | } else { | 
|  | 1386 | TransformedDecl = Found->get<Decl*>(); | 
|  | 1387 | } | 
|  | 1388 |  | 
|  | 1389 | // We have either an unexpanded pack or a specific expansion. | 
|  | 1390 | return RebuildParmVarDeclRefExpr(cast<ParmVarDecl>(TransformedDecl), | 
|  | 1391 | E->getExprLoc()); | 
|  | 1392 | } | 
|  | 1393 |  | 
|  | 1394 | ExprResult | 
| John McCall | 13481c5 | 2010-02-06 08:42:39 +0000 | [diff] [blame] | 1395 | TemplateInstantiator::TransformDeclRefExpr(DeclRefExpr *E) { | 
|  | 1396 | NamedDecl *D = E->getDecl(); | 
| Richard Smith | b15fe3a | 2012-09-12 00:56:43 +0000 | [diff] [blame] | 1397 |  | 
|  | 1398 | // Handle references to non-type template parameters and non-type template | 
|  | 1399 | // parameter packs. | 
| John McCall | 13481c5 | 2010-02-06 08:42:39 +0000 | [diff] [blame] | 1400 | if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(D)) { | 
|  | 1401 | if (NTTP->getDepth() < TemplateArgs.getNumLevels()) | 
|  | 1402 | return TransformTemplateParmRefExpr(E, NTTP); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1403 |  | 
| Douglas Gregor | 954de17 | 2009-10-31 17:21:17 +0000 | [diff] [blame] | 1404 | // We have a non-type template parameter that isn't fully substituted; | 
|  | 1405 | // FindInstantiatedDecl will find it in the local instantiation scope. | 
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1406 | } | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1407 |  | 
| Richard Smith | b15fe3a | 2012-09-12 00:56:43 +0000 | [diff] [blame] | 1408 | // Handle references to function parameter packs. | 
|  | 1409 | if (ParmVarDecl *PD = dyn_cast<ParmVarDecl>(D)) | 
|  | 1410 | if (PD->isParameterPack()) | 
|  | 1411 | return TransformFunctionParmPackRefExpr(E, PD); | 
|  | 1412 |  | 
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 1413 | return TreeTransform<TemplateInstantiator>::TransformDeclRefExpr(E); | 
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1414 | } | 
|  | 1415 |  | 
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1416 | ExprResult TemplateInstantiator::TransformCXXDefaultArgExpr( | 
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 1417 | CXXDefaultArgExpr *E) { | 
| Sebastian Redl | 14236c8 | 2009-11-08 13:56:19 +0000 | [diff] [blame] | 1418 | assert(!cast<FunctionDecl>(E->getParam()->getDeclContext())-> | 
|  | 1419 | getDescribedFunctionTemplate() && | 
|  | 1420 | "Default arg expressions are never formed in dependent cases."); | 
| Douglas Gregor | 033f675 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 1421 | return SemaRef.BuildCXXDefaultArgExpr(E->getUsedLocation(), | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1422 | cast<FunctionDecl>(E->getParam()->getDeclContext()), | 
| Douglas Gregor | 033f675 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 1423 | E->getParam()); | 
| Sebastian Redl | 14236c8 | 2009-11-08 13:56:19 +0000 | [diff] [blame] | 1424 | } | 
|  | 1425 |  | 
| Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 1426 | template<typename Fn> | 
| Douglas Gregor | 3024f07 | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 1427 | QualType TemplateInstantiator::TransformFunctionProtoType(TypeLocBuilder &TLB, | 
|  | 1428 | FunctionProtoTypeLoc TL, | 
|  | 1429 | CXXRecordDecl *ThisContext, | 
| Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 1430 | unsigned ThisTypeQuals, | 
|  | 1431 | Fn TransformExceptionSpec) { | 
| Douglas Gregor | 3024f07 | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 1432 | // We need a local instantiation scope for this function prototype. | 
|  | 1433 | LocalInstantiationScope Scope(SemaRef, /*CombineWithOuterScope=*/true); | 
| Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 1434 | return inherited::TransformFunctionProtoType( | 
|  | 1435 | TLB, TL, ThisContext, ThisTypeQuals, TransformExceptionSpec); | 
| Douglas Gregor | 3024f07 | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 1436 | } | 
|  | 1437 |  | 
| John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 1438 | ParmVarDecl * | 
| Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 1439 | TemplateInstantiator::TransformFunctionTypeParam(ParmVarDecl *OldParm, | 
| John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 1440 | int indexAdjustment, | 
| David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 1441 | Optional<unsigned> NumExpansions, | 
| Douglas Gregor | 0dd22bc | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 1442 | bool ExpectParameterPack) { | 
| John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 1443 | return SemaRef.SubstParmVarDecl(OldParm, TemplateArgs, indexAdjustment, | 
| Douglas Gregor | 0dd22bc | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 1444 | NumExpansions, ExpectParameterPack); | 
| John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 1445 | } | 
|  | 1446 |  | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1447 | QualType | 
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 1448 | TemplateInstantiator::TransformTemplateTypeParmType(TypeLocBuilder &TLB, | 
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 1449 | TemplateTypeParmTypeLoc TL) { | 
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1450 | const TemplateTypeParmType *T = TL.getTypePtr(); | 
| Douglas Gregor | 01afeef | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 1451 | if (T->getDepth() < TemplateArgs.getNumLevels()) { | 
| Douglas Gregor | fe1e110 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 1452 | // Replace the template type parameter with its corresponding | 
|  | 1453 | // template argument. | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1454 |  | 
|  | 1455 | // If the corresponding template argument is NULL or doesn't exist, it's | 
|  | 1456 | // because we are performing instantiation from explicitly-specified | 
|  | 1457 | // template arguments in a function template class, but there were some | 
| Douglas Gregor | e3f1f35 | 2009-07-01 00:28:38 +0000 | [diff] [blame] | 1458 | // arguments left unspecified. | 
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 1459 | if (!TemplateArgs.hasTemplateArgument(T->getDepth(), T->getIndex())) { | 
|  | 1460 | TemplateTypeParmTypeLoc NewTL | 
|  | 1461 | = TLB.push<TemplateTypeParmTypeLoc>(TL.getType()); | 
|  | 1462 | NewTL.setNameLoc(TL.getNameLoc()); | 
|  | 1463 | return TL.getType(); | 
|  | 1464 | } | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1465 |  | 
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 1466 | TemplateArgument Arg = TemplateArgs(T->getDepth(), T->getIndex()); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1467 |  | 
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 1468 | if (T->isParameterPack()) { | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1469 | assert(Arg.getKind() == TemplateArgument::Pack && | 
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 1470 | "Missing argument pack"); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1471 |  | 
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 1472 | if (getSema().ArgumentPackSubstitutionIndex == -1) { | 
| Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 1473 | // We have the template argument pack, but we're not expanding the | 
|  | 1474 | // enclosing pack expansion yet. Just save the template argument | 
|  | 1475 | // pack for later substitution. | 
|  | 1476 | QualType Result | 
|  | 1477 | = getSema().Context.getSubstTemplateTypeParmPackType(T, Arg); | 
|  | 1478 | SubstTemplateTypeParmPackTypeLoc NewTL | 
|  | 1479 | = TLB.push<SubstTemplateTypeParmPackTypeLoc>(Result); | 
|  | 1480 | NewTL.setNameLoc(TL.getNameLoc()); | 
|  | 1481 | return Result; | 
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 1482 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1483 |  | 
| Eli Friedman | 8917ad5 | 2013-07-19 19:40:38 +0000 | [diff] [blame] | 1484 | Arg = getPackSubstitutedTemplateArgument(getSema(), Arg); | 
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 1485 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1486 |  | 
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 1487 | assert(Arg.getKind() == TemplateArgument::Type && | 
| Douglas Gregor | fe1e110 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 1488 | "Template argument kind mismatch"); | 
| Douglas Gregor | 01afeef | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 1489 |  | 
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 1490 | QualType Replacement = Arg.getAsType(); | 
| John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 1491 |  | 
|  | 1492 | // TODO: only do this uniquing once, at the start of instantiation. | 
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 1493 | QualType Result | 
|  | 1494 | = getSema().Context.getSubstTemplateTypeParmType(T, Replacement); | 
|  | 1495 | SubstTemplateTypeParmTypeLoc NewTL | 
|  | 1496 | = TLB.push<SubstTemplateTypeParmTypeLoc>(Result); | 
|  | 1497 | NewTL.setNameLoc(TL.getNameLoc()); | 
|  | 1498 | return Result; | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1499 | } | 
| Douglas Gregor | fe1e110 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 1500 |  | 
|  | 1501 | // The template type parameter comes from an inner template (e.g., | 
|  | 1502 | // the template parameter list of a member template inside the | 
|  | 1503 | // template we are instantiating). Create a new template type | 
|  | 1504 | // parameter with the template "level" reduced by one. | 
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 1505 | TemplateTypeParmDecl *NewTTPDecl = nullptr; | 
| Chandler Carruth | 0883632 | 2011-05-01 00:51:33 +0000 | [diff] [blame] | 1506 | if (TemplateTypeParmDecl *OldTTPDecl = T->getDecl()) | 
|  | 1507 | NewTTPDecl = cast_or_null<TemplateTypeParmDecl>( | 
|  | 1508 | TransformDecl(TL.getNameLoc(), OldTTPDecl)); | 
|  | 1509 |  | 
| Richard Smith | b4f9625 | 2017-02-21 06:30:38 +0000 | [diff] [blame] | 1510 | QualType Result = getSema().Context.getTemplateTypeParmType( | 
|  | 1511 | T->getDepth() - TemplateArgs.getNumSubstitutedLevels(), T->getIndex(), | 
|  | 1512 | T->isParameterPack(), NewTTPDecl); | 
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 1513 | TemplateTypeParmTypeLoc NewTL = TLB.push<TemplateTypeParmTypeLoc>(Result); | 
|  | 1514 | NewTL.setNameLoc(TL.getNameLoc()); | 
|  | 1515 | return Result; | 
| Douglas Gregor | 17c0d7b | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 1516 | } | 
| Douglas Gregor | fe1e110 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 1517 |  | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1518 | QualType | 
| Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 1519 | TemplateInstantiator::TransformSubstTemplateTypeParmPackType( | 
|  | 1520 | TypeLocBuilder &TLB, | 
|  | 1521 | SubstTemplateTypeParmPackTypeLoc TL) { | 
|  | 1522 | if (getSema().ArgumentPackSubstitutionIndex == -1) { | 
|  | 1523 | // We aren't expanding the parameter pack, so just return ourselves. | 
|  | 1524 | SubstTemplateTypeParmPackTypeLoc NewTL | 
|  | 1525 | = TLB.push<SubstTemplateTypeParmPackTypeLoc>(TL.getType()); | 
|  | 1526 | NewTL.setNameLoc(TL.getNameLoc()); | 
|  | 1527 | return TL.getType(); | 
|  | 1528 | } | 
| Eli Friedman | 8917ad5 | 2013-07-19 19:40:38 +0000 | [diff] [blame] | 1529 |  | 
|  | 1530 | TemplateArgument Arg = TL.getTypePtr()->getArgumentPack(); | 
|  | 1531 | Arg = getPackSubstitutedTemplateArgument(getSema(), Arg); | 
|  | 1532 | QualType Result = Arg.getAsType(); | 
|  | 1533 |  | 
| Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 1534 | Result = getSema().Context.getSubstTemplateTypeParmType( | 
|  | 1535 | TL.getTypePtr()->getReplacedParameter(), | 
|  | 1536 | Result); | 
|  | 1537 | SubstTemplateTypeParmTypeLoc NewTL | 
|  | 1538 | = TLB.push<SubstTemplateTypeParmTypeLoc>(Result); | 
|  | 1539 | NewTL.setNameLoc(TL.getNameLoc()); | 
|  | 1540 | return Result; | 
|  | 1541 | } | 
|  | 1542 |  | 
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1543 | /// Perform substitution on the type T with a given set of template | 
| John McCall | 76d824f | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 1544 | /// arguments. | 
| Douglas Gregor | fe1e110 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 1545 | /// | 
|  | 1546 | /// This routine substitutes the given template arguments into the | 
|  | 1547 | /// type T and produces the instantiated type. | 
|  | 1548 | /// | 
|  | 1549 | /// \param T the type into which the template arguments will be | 
|  | 1550 | /// substituted. If this type is not dependent, it will be returned | 
|  | 1551 | /// immediately. | 
|  | 1552 | /// | 
| James Dennett | 634962f | 2012-06-14 21:40:34 +0000 | [diff] [blame] | 1553 | /// \param Args the template arguments that will be | 
| Douglas Gregor | fe1e110 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 1554 | /// substituted for the top-level template parameters within T. | 
|  | 1555 | /// | 
| Douglas Gregor | fe1e110 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 1556 | /// \param Loc the location in the source code where this substitution | 
|  | 1557 | /// is being performed. It will typically be the location of the | 
|  | 1558 | /// declarator (if we're instantiating the type of some declaration) | 
|  | 1559 | /// or the location of the type in the source code (if, e.g., we're | 
|  | 1560 | /// instantiating the type of a cast expression). | 
|  | 1561 | /// | 
|  | 1562 | /// \param Entity the name of the entity associated with a declaration | 
|  | 1563 | /// being instantiated (if any). May be empty to indicate that there | 
|  | 1564 | /// is no such entity (if, e.g., this is a type that occurs as part of | 
|  | 1565 | /// a cast expression) or that the entity has no name (e.g., an | 
|  | 1566 | /// unnamed function parameter). | 
|  | 1567 | /// | 
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 1568 | /// \param AllowDeducedTST Whether a DeducedTemplateSpecializationType is | 
|  | 1569 | /// acceptable as the top level type of the result. | 
|  | 1570 | /// | 
| Douglas Gregor | fe1e110 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 1571 | /// \returns If the instantiation succeeds, the instantiated | 
|  | 1572 | /// type. Otherwise, produces diagnostics and returns a NULL type. | 
| John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1573 | TypeSourceInfo *Sema::SubstType(TypeSourceInfo *T, | 
| John McCall | 609459e | 2009-10-21 00:58:09 +0000 | [diff] [blame] | 1574 | const MultiLevelTemplateArgumentList &Args, | 
|  | 1575 | SourceLocation Loc, | 
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 1576 | DeclarationName Entity, | 
|  | 1577 | bool AllowDeducedTST) { | 
| Richard Smith | 696e312 | 2017-02-23 01:43:54 +0000 | [diff] [blame] | 1578 | assert(!CodeSynthesisContexts.empty() && | 
| John McCall | 609459e | 2009-10-21 00:58:09 +0000 | [diff] [blame] | 1579 | "Cannot perform an instantiation without some context on the " | 
|  | 1580 | "instantiation stack"); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1581 |  | 
|  | 1582 | if (!T->getType()->isInstantiationDependentType() && | 
| Douglas Gregor | 5a5073e | 2010-05-24 17:22:01 +0000 | [diff] [blame] | 1583 | !T->getType()->isVariablyModifiedType()) | 
| John McCall | 609459e | 2009-10-21 00:58:09 +0000 | [diff] [blame] | 1584 | return T; | 
|  | 1585 |  | 
|  | 1586 | TemplateInstantiator Instantiator(*this, Args, Loc, Entity); | 
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 1587 | return AllowDeducedTST ? Instantiator.TransformTypeWithDeducedTST(T) | 
|  | 1588 | : Instantiator.TransformType(T); | 
| John McCall | 609459e | 2009-10-21 00:58:09 +0000 | [diff] [blame] | 1589 | } | 
|  | 1590 |  | 
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 1591 | TypeSourceInfo *Sema::SubstType(TypeLoc TL, | 
|  | 1592 | const MultiLevelTemplateArgumentList &Args, | 
|  | 1593 | SourceLocation Loc, | 
|  | 1594 | DeclarationName Entity) { | 
| Richard Smith | 696e312 | 2017-02-23 01:43:54 +0000 | [diff] [blame] | 1595 | assert(!CodeSynthesisContexts.empty() && | 
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 1596 | "Cannot perform an instantiation without some context on the " | 
|  | 1597 | "instantiation stack"); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1598 |  | 
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 1599 | if (TL.getType().isNull()) | 
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 1600 | return nullptr; | 
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 1601 |  | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1602 | if (!TL.getType()->isInstantiationDependentType() && | 
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 1603 | !TL.getType()->isVariablyModifiedType()) { | 
|  | 1604 | // FIXME: Make a copy of the TypeLoc data here, so that we can | 
|  | 1605 | // return a new TypeSourceInfo. Inefficient! | 
|  | 1606 | TypeLocBuilder TLB; | 
|  | 1607 | TLB.pushFullCopy(TL); | 
|  | 1608 | return TLB.getTypeSourceInfo(Context, TL.getType()); | 
|  | 1609 | } | 
|  | 1610 |  | 
|  | 1611 | TemplateInstantiator Instantiator(*this, Args, Loc, Entity); | 
|  | 1612 | TypeLocBuilder TLB; | 
|  | 1613 | TLB.reserve(TL.getFullDataSize()); | 
|  | 1614 | QualType Result = Instantiator.TransformType(TLB, TL); | 
|  | 1615 | if (Result.isNull()) | 
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 1616 | return nullptr; | 
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 1617 |  | 
|  | 1618 | return TLB.getTypeSourceInfo(Context, Result); | 
|  | 1619 | } | 
|  | 1620 |  | 
| John McCall | 609459e | 2009-10-21 00:58:09 +0000 | [diff] [blame] | 1621 | /// Deprecated form of the above. | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1622 | QualType Sema::SubstType(QualType T, | 
| Douglas Gregor | 01afeef | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 1623 | const MultiLevelTemplateArgumentList &TemplateArgs, | 
| John McCall | 76d824f | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 1624 | SourceLocation Loc, DeclarationName Entity) { | 
| Richard Smith | 696e312 | 2017-02-23 01:43:54 +0000 | [diff] [blame] | 1625 | assert(!CodeSynthesisContexts.empty() && | 
| Douglas Gregor | 79cf603 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 1626 | "Cannot perform an instantiation without some context on the " | 
|  | 1627 | "instantiation stack"); | 
|  | 1628 |  | 
| Douglas Gregor | 5a5073e | 2010-05-24 17:22:01 +0000 | [diff] [blame] | 1629 | // If T is not a dependent type or a variably-modified type, there | 
|  | 1630 | // is nothing to do. | 
| Douglas Gregor | 678d76c | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 1631 | if (!T->isInstantiationDependentType() && !T->isVariablyModifiedType()) | 
| Douglas Gregor | fe1e110 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 1632 | return T; | 
|  | 1633 |  | 
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 1634 | TemplateInstantiator Instantiator(*this, TemplateArgs, Loc, Entity); | 
|  | 1635 | return Instantiator.TransformType(T); | 
| Douglas Gregor | fe1e110 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 1636 | } | 
| Douglas Gregor | 463421d | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 1637 |  | 
| John McCall | b29f78f | 2010-04-09 17:38:44 +0000 | [diff] [blame] | 1638 | static bool NeedsInstantiationAsFunctionType(TypeSourceInfo *T) { | 
| Nico Weber | c097337 | 2016-02-01 22:31:51 +0000 | [diff] [blame] | 1639 | if (T->getType()->isInstantiationDependentType() || | 
| Douglas Gregor | 678d76c | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 1640 | T->getType()->isVariablyModifiedType()) | 
| John McCall | b29f78f | 2010-04-09 17:38:44 +0000 | [diff] [blame] | 1641 | return true; | 
|  | 1642 |  | 
| Abramo Bagnara | 6d81063 | 2010-12-14 22:11:44 +0000 | [diff] [blame] | 1643 | TypeLoc TL = T->getTypeLoc().IgnoreParens(); | 
| David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 1644 | if (!TL.getAs<FunctionProtoTypeLoc>()) | 
| John McCall | b29f78f | 2010-04-09 17:38:44 +0000 | [diff] [blame] | 1645 | return false; | 
|  | 1646 |  | 
| David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 1647 | FunctionProtoTypeLoc FP = TL.castAs<FunctionProtoTypeLoc>(); | 
| Nico Weber | c097337 | 2016-02-01 22:31:51 +0000 | [diff] [blame] | 1648 | for (ParmVarDecl *P : FP.getParams()) { | 
| Reid Kleckner | a09e44c | 2013-07-31 21:00:18 +0000 | [diff] [blame] | 1649 | // This must be synthesized from a typedef. | 
|  | 1650 | if (!P) continue; | 
|  | 1651 |  | 
| Nico Weber | c097337 | 2016-02-01 22:31:51 +0000 | [diff] [blame] | 1652 | // If there are any parameters, a new TypeSourceInfo that refers to the | 
|  | 1653 | // instantiated parameters must be built. | 
|  | 1654 | return true; | 
| John McCall | b29f78f | 2010-04-09 17:38:44 +0000 | [diff] [blame] | 1655 | } | 
|  | 1656 |  | 
|  | 1657 | return false; | 
|  | 1658 | } | 
|  | 1659 |  | 
|  | 1660 | /// A form of SubstType intended specifically for instantiating the | 
|  | 1661 | /// type of a FunctionDecl.  Its purpose is solely to force the | 
| Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 1662 | /// instantiation of default-argument expressions and to avoid | 
|  | 1663 | /// instantiating an exception-specification. | 
| John McCall | b29f78f | 2010-04-09 17:38:44 +0000 | [diff] [blame] | 1664 | TypeSourceInfo *Sema::SubstFunctionDeclType(TypeSourceInfo *T, | 
|  | 1665 | const MultiLevelTemplateArgumentList &Args, | 
|  | 1666 | SourceLocation Loc, | 
| Douglas Gregor | 3024f07 | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 1667 | DeclarationName Entity, | 
|  | 1668 | CXXRecordDecl *ThisContext, | 
|  | 1669 | unsigned ThisTypeQuals) { | 
| Richard Smith | 696e312 | 2017-02-23 01:43:54 +0000 | [diff] [blame] | 1670 | assert(!CodeSynthesisContexts.empty() && | 
| John McCall | b29f78f | 2010-04-09 17:38:44 +0000 | [diff] [blame] | 1671 | "Cannot perform an instantiation without some context on the " | 
|  | 1672 | "instantiation stack"); | 
| Nico Weber | c097337 | 2016-02-01 22:31:51 +0000 | [diff] [blame] | 1673 |  | 
| John McCall | b29f78f | 2010-04-09 17:38:44 +0000 | [diff] [blame] | 1674 | if (!NeedsInstantiationAsFunctionType(T)) | 
|  | 1675 | return T; | 
|  | 1676 |  | 
|  | 1677 | TemplateInstantiator Instantiator(*this, Args, Loc, Entity); | 
|  | 1678 |  | 
|  | 1679 | TypeLocBuilder TLB; | 
|  | 1680 |  | 
|  | 1681 | TypeLoc TL = T->getTypeLoc(); | 
|  | 1682 | TLB.reserve(TL.getFullDataSize()); | 
|  | 1683 |  | 
| Douglas Gregor | 3024f07 | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 1684 | QualType Result; | 
| David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 1685 |  | 
| Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 1686 | if (FunctionProtoTypeLoc Proto = | 
|  | 1687 | TL.IgnoreParens().getAs<FunctionProtoTypeLoc>()) { | 
|  | 1688 | // Instantiate the type, other than its exception specification. The | 
|  | 1689 | // exception specification is instantiated in InitFunctionInstantiation | 
|  | 1690 | // once we've built the FunctionDecl. | 
|  | 1691 | // FIXME: Set the exception specification to EST_Uninstantiated here, | 
|  | 1692 | // instead of rebuilding the function type again later. | 
|  | 1693 | Result = Instantiator.TransformFunctionProtoType( | 
|  | 1694 | TLB, Proto, ThisContext, ThisTypeQuals, | 
|  | 1695 | [](FunctionProtoType::ExceptionSpecInfo &ESI, | 
|  | 1696 | bool &Changed) { return false; }); | 
| Douglas Gregor | 3024f07 | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 1697 | } else { | 
|  | 1698 | Result = Instantiator.TransformType(TLB, TL); | 
|  | 1699 | } | 
| John McCall | b29f78f | 2010-04-09 17:38:44 +0000 | [diff] [blame] | 1700 | if (Result.isNull()) | 
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 1701 | return nullptr; | 
| John McCall | b29f78f | 2010-04-09 17:38:44 +0000 | [diff] [blame] | 1702 |  | 
|  | 1703 | return TLB.getTypeSourceInfo(Context, Result); | 
|  | 1704 | } | 
|  | 1705 |  | 
| Richard Smith | cd19815 | 2017-06-07 21:46:22 +0000 | [diff] [blame] | 1706 | bool Sema::SubstExceptionSpec(SourceLocation Loc, | 
|  | 1707 | FunctionProtoType::ExceptionSpecInfo &ESI, | 
|  | 1708 | SmallVectorImpl<QualType> &ExceptionStorage, | 
|  | 1709 | const MultiLevelTemplateArgumentList &Args) { | 
|  | 1710 | assert(ESI.Type != EST_Uninstantiated); | 
|  | 1711 |  | 
|  | 1712 | bool Changed = false; | 
|  | 1713 | TemplateInstantiator Instantiator(*this, Args, Loc, DeclarationName()); | 
|  | 1714 | return Instantiator.TransformExceptionSpec(Loc, ESI, ExceptionStorage, | 
|  | 1715 | Changed); | 
|  | 1716 | } | 
|  | 1717 |  | 
| Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 1718 | void Sema::SubstExceptionSpec(FunctionDecl *New, const FunctionProtoType *Proto, | 
|  | 1719 | const MultiLevelTemplateArgumentList &Args) { | 
|  | 1720 | FunctionProtoType::ExceptionSpecInfo ESI = | 
|  | 1721 | Proto->getExtProtoInfo().ExceptionSpec; | 
| Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 1722 |  | 
|  | 1723 | SmallVector<QualType, 4> ExceptionStorage; | 
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 1724 | if (SubstExceptionSpec(New->getTypeSourceInfo()->getTypeLoc().getEndLoc(), | 
| Richard Smith | cd19815 | 2017-06-07 21:46:22 +0000 | [diff] [blame] | 1725 | ESI, ExceptionStorage, Args)) | 
| Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 1726 | // On error, recover by dropping the exception specification. | 
|  | 1727 | ESI.Type = EST_None; | 
|  | 1728 |  | 
|  | 1729 | UpdateExceptionSpec(New, ESI); | 
|  | 1730 | } | 
|  | 1731 |  | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1732 | ParmVarDecl *Sema::SubstParmVarDecl(ParmVarDecl *OldParm, | 
| Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 1733 | const MultiLevelTemplateArgumentList &TemplateArgs, | 
| John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 1734 | int indexAdjustment, | 
| David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 1735 | Optional<unsigned> NumExpansions, | 
| Douglas Gregor | 0dd22bc | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 1736 | bool ExpectParameterPack) { | 
| Douglas Gregor | 940bca7 | 2010-04-12 07:48:19 +0000 | [diff] [blame] | 1737 | TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); | 
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 1738 | TypeSourceInfo *NewDI = nullptr; | 
|  | 1739 |  | 
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 1740 | TypeLoc OldTL = OldDI->getTypeLoc(); | 
| David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 1741 | if (PackExpansionTypeLoc ExpansionTL = OldTL.getAs<PackExpansionTypeLoc>()) { | 
|  | 1742 |  | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1743 | // We have a function parameter pack. Substitute into the pattern of the | 
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 1744 | // expansion. | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1745 | NewDI = SubstType(ExpansionTL.getPatternLoc(), TemplateArgs, | 
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 1746 | OldParm->getLocation(), OldParm->getDeclName()); | 
|  | 1747 | if (!NewDI) | 
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 1748 | return nullptr; | 
|  | 1749 |  | 
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 1750 | if (NewDI->getType()->containsUnexpandedParameterPack()) { | 
|  | 1751 | // We still have unexpanded parameter packs, which means that | 
|  | 1752 | // our function parameter is still a function parameter pack. | 
|  | 1753 | // Therefore, make its type a pack expansion type. | 
| Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 1754 | NewDI = CheckPackExpansion(NewDI, ExpansionTL.getEllipsisLoc(), | 
| Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 1755 | NumExpansions); | 
| Douglas Gregor | 0dd22bc | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 1756 | } else if (ExpectParameterPack) { | 
|  | 1757 | // We expected to get a parameter pack but didn't (because the type | 
|  | 1758 | // itself is not a pack expansion type), so complain. This can occur when | 
|  | 1759 | // the substitution goes through an alias template that "loses" the | 
|  | 1760 | // pack expansion. | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1761 | Diag(OldParm->getLocation(), | 
| Douglas Gregor | 0dd22bc | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 1762 | diag::err_function_parameter_pack_without_parameter_packs) | 
|  | 1763 | << NewDI->getType(); | 
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 1764 | return nullptr; | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1765 | } | 
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 1766 | } else { | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1767 | NewDI = SubstType(OldDI, TemplateArgs, OldParm->getLocation(), | 
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 1768 | OldParm->getDeclName()); | 
|  | 1769 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1770 |  | 
| Douglas Gregor | 940bca7 | 2010-04-12 07:48:19 +0000 | [diff] [blame] | 1771 | if (!NewDI) | 
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 1772 | return nullptr; | 
| Douglas Gregor | 940bca7 | 2010-04-12 07:48:19 +0000 | [diff] [blame] | 1773 |  | 
|  | 1774 | if (NewDI->getType()->isVoidType()) { | 
|  | 1775 | Diag(OldParm->getLocation(), diag::err_param_with_void_type); | 
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 1776 | return nullptr; | 
| Douglas Gregor | 940bca7 | 2010-04-12 07:48:19 +0000 | [diff] [blame] | 1777 | } | 
|  | 1778 |  | 
|  | 1779 | ParmVarDecl *NewParm = CheckParameter(Context.getTranslationUnitDecl(), | 
| Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1780 | OldParm->getInnerLocStart(), | 
| Douglas Gregor | 940bca7 | 2010-04-12 07:48:19 +0000 | [diff] [blame] | 1781 | OldParm->getLocation(), | 
| Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1782 | OldParm->getIdentifier(), | 
|  | 1783 | NewDI->getType(), NewDI, | 
| Rafael Espindola | 6ae7e50 | 2013-04-03 19:27:57 +0000 | [diff] [blame] | 1784 | OldParm->getStorageClass()); | 
| Douglas Gregor | 940bca7 | 2010-04-12 07:48:19 +0000 | [diff] [blame] | 1785 | if (!NewParm) | 
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 1786 | return nullptr; | 
|  | 1787 |  | 
| Douglas Gregor | 940bca7 | 2010-04-12 07:48:19 +0000 | [diff] [blame] | 1788 | // Mark the (new) default argument as uninstantiated (if any). | 
|  | 1789 | if (OldParm->hasUninstantiatedDefaultArg()) { | 
|  | 1790 | Expr *Arg = OldParm->getUninstantiatedDefaultArg(); | 
|  | 1791 | NewParm->setUninstantiatedDefaultArg(Arg); | 
| Douglas Gregor | 758cb67 | 2010-10-12 18:23:32 +0000 | [diff] [blame] | 1792 | } else if (OldParm->hasUnparsedDefaultArg()) { | 
|  | 1793 | NewParm->setUnparsedDefaultArg(); | 
|  | 1794 | UnparsedDefaultArgInstantiations[OldParm].push_back(NewParm); | 
| Serge Pavlov | 3739f5e7 | 2015-06-29 17:50:19 +0000 | [diff] [blame] | 1795 | } else if (Expr *Arg = OldParm->getDefaultArg()) { | 
|  | 1796 | FunctionDecl *OwningFunc = cast<FunctionDecl>(OldParm->getDeclContext()); | 
| Serge Pavlov | 73c6a24 | 2015-08-23 10:22:28 +0000 | [diff] [blame] | 1797 | if (OwningFunc->isLexicallyWithinFunctionOrMethod()) { | 
|  | 1798 | // Instantiate default arguments for methods of local classes (DR1484) | 
|  | 1799 | // and non-defining declarations. | 
|  | 1800 | Sema::ContextRAII SavedContext(*this, OwningFunc); | 
| Akira Hatanaka | d644e02 | 2016-12-16 03:19:41 +0000 | [diff] [blame] | 1801 | LocalInstantiationScope Local(*this, true); | 
| Serge Pavlov | 3739f5e7 | 2015-06-29 17:50:19 +0000 | [diff] [blame] | 1802 | ExprResult NewArg = SubstExpr(Arg, TemplateArgs); | 
| John McCall | dc40b61 | 2015-12-11 01:56:36 +0000 | [diff] [blame] | 1803 | if (NewArg.isUsable()) { | 
|  | 1804 | // It would be nice if we still had this. | 
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 1805 | SourceLocation EqualLoc = NewArg.get()->getBeginLoc(); | 
| John McCall | dc40b61 | 2015-12-11 01:56:36 +0000 | [diff] [blame] | 1806 | SetParamDefaultArgument(NewParm, NewArg.get(), EqualLoc); | 
|  | 1807 | } | 
| Serge Pavlov | 3739f5e7 | 2015-06-29 17:50:19 +0000 | [diff] [blame] | 1808 | } else { | 
|  | 1809 | // FIXME: if we non-lazily instantiated non-dependent default args for | 
|  | 1810 | // non-dependent parameter types we could remove a bunch of duplicate | 
|  | 1811 | // conversion warnings for such arguments. | 
|  | 1812 | NewParm->setUninstantiatedDefaultArg(Arg); | 
|  | 1813 | } | 
|  | 1814 | } | 
| Douglas Gregor | 940bca7 | 2010-04-12 07:48:19 +0000 | [diff] [blame] | 1815 |  | 
|  | 1816 | NewParm->setHasInheritedDefaultArg(OldParm->hasInheritedDefaultArg()); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1817 |  | 
| Douglas Gregor | f301011 | 2011-01-07 16:43:16 +0000 | [diff] [blame] | 1818 | if (OldParm->isParameterPack() && !NewParm->isParameterPack()) { | 
| Richard Smith | 928be49 | 2012-01-25 02:14:59 +0000 | [diff] [blame] | 1819 | // Add the new parameter to the instantiated parameter pack. | 
| Douglas Gregor | f301011 | 2011-01-07 16:43:16 +0000 | [diff] [blame] | 1820 | CurrentInstantiationScope->InstantiatedLocalPackArg(OldParm, NewParm); | 
|  | 1821 | } else { | 
|  | 1822 | // Introduce an Old -> New mapping | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1823 | CurrentInstantiationScope->InstantiatedLocal(OldParm, NewParm); | 
| Douglas Gregor | f301011 | 2011-01-07 16:43:16 +0000 | [diff] [blame] | 1824 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1825 |  | 
| Argyrios Kyrtzidis | 3816ed4 | 2010-07-19 10:14:41 +0000 | [diff] [blame] | 1826 | // FIXME: OldParm may come from a FunctionProtoType, in which case CurContext | 
|  | 1827 | // can be anything, is this right ? | 
| Fariborz Jahanian | 714447b | 2010-07-13 21:05:02 +0000 | [diff] [blame] | 1828 | NewParm->setDeclContext(CurContext); | 
| John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 1829 |  | 
|  | 1830 | NewParm->setScopeInfo(OldParm->getFunctionScopeDepth(), | 
|  | 1831 | OldParm->getFunctionScopeIndex() + indexAdjustment); | 
| Jordan Rose | a0a86be | 2013-03-08 22:25:36 +0000 | [diff] [blame] | 1832 |  | 
|  | 1833 | InstantiateAttrs(TemplateArgs, OldParm, NewParm); | 
|  | 1834 |  | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1835 | return NewParm; | 
| Douglas Gregor | 940bca7 | 2010-04-12 07:48:19 +0000 | [diff] [blame] | 1836 | } | 
|  | 1837 |  | 
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1838 | /// Substitute the given template arguments into the given set of | 
| Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 1839 | /// parameters, producing the set of parameter types that would be generated | 
|  | 1840 | /// from such a substitution. | 
| David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 1841 | bool Sema::SubstParmTypes( | 
|  | 1842 | SourceLocation Loc, ArrayRef<ParmVarDecl *> Params, | 
|  | 1843 | const FunctionProtoType::ExtParameterInfo *ExtParamInfos, | 
|  | 1844 | const MultiLevelTemplateArgumentList &TemplateArgs, | 
|  | 1845 | SmallVectorImpl<QualType> &ParamTypes, | 
|  | 1846 | SmallVectorImpl<ParmVarDecl *> *OutParams, | 
|  | 1847 | ExtParameterInfoBuilder &ParamInfos) { | 
| Richard Smith | 696e312 | 2017-02-23 01:43:54 +0000 | [diff] [blame] | 1848 | assert(!CodeSynthesisContexts.empty() && | 
| Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 1849 | "Cannot perform an instantiation without some context on the " | 
|  | 1850 | "instantiation stack"); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1851 |  | 
|  | 1852 | TemplateInstantiator Instantiator(*this, TemplateArgs, Loc, | 
| Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 1853 | DeclarationName()); | 
| David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 1854 | return Instantiator.TransformFunctionTypeParams( | 
|  | 1855 | Loc, Params, nullptr, ExtParamInfos, ParamTypes, OutParams, ParamInfos); | 
| Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 1856 | } | 
|  | 1857 |  | 
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1858 | /// Perform substitution on the base class specifiers of the | 
| John McCall | 76d824f | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 1859 | /// given class template specialization. | 
| Douglas Gregor | 463421d | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 1860 | /// | 
|  | 1861 | /// Produces a diagnostic and returns true on error, returns false and | 
|  | 1862 | /// attaches the instantiated base classes to the class template | 
|  | 1863 | /// specialization if successful. | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1864 | bool | 
| John McCall | 76d824f | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 1865 | Sema::SubstBaseSpecifiers(CXXRecordDecl *Instantiation, | 
|  | 1866 | CXXRecordDecl *Pattern, | 
| Douglas Gregor | 01afeef | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 1867 | const MultiLevelTemplateArgumentList &TemplateArgs) { | 
| Douglas Gregor | 463421d | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 1868 | bool Invalid = false; | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1869 | SmallVector<CXXBaseSpecifier*, 4> InstantiatedBases; | 
| Richard Trieu | b584133 | 2015-04-15 01:21:42 +0000 | [diff] [blame] | 1870 | for (const auto &Base : Pattern->bases()) { | 
| Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1871 | if (!Base.getType()->isDependentType()) { | 
|  | 1872 | if (const CXXRecordDecl *RD = Base.getType()->getAsCXXRecordDecl()) { | 
| Matt Beaumont-Gay | 76d0b46 | 2013-06-21 18:58:32 +0000 | [diff] [blame] | 1873 | if (RD->isInvalidDecl()) | 
|  | 1874 | Instantiation->setInvalidDecl(); | 
|  | 1875 | } | 
| Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1876 | InstantiatedBases.push_back(new (Context) CXXBaseSpecifier(Base)); | 
| Douglas Gregor | 463421d | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 1877 | continue; | 
|  | 1878 | } | 
|  | 1879 |  | 
| Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 1880 | SourceLocation EllipsisLoc; | 
| Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 1881 | TypeSourceInfo *BaseTypeLoc; | 
| Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1882 | if (Base.isPackExpansion()) { | 
| Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 1883 | // This is a pack expansion. See whether we should expand it now, or | 
|  | 1884 | // wait until later. | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1885 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; | 
| Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1886 | collectUnexpandedParameterPacks(Base.getTypeSourceInfo()->getTypeLoc(), | 
| Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 1887 | Unexpanded); | 
|  | 1888 | bool ShouldExpand = false; | 
| Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 1889 | bool RetainExpansion = false; | 
| David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 1890 | Optional<unsigned> NumExpansions; | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1891 | if (CheckParameterPacksForExpansion(Base.getEllipsisLoc(), | 
| Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1892 | Base.getSourceRange(), | 
| David Blaikie | b9c168a | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 1893 | Unexpanded, | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1894 | TemplateArgs, ShouldExpand, | 
| Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 1895 | RetainExpansion, | 
| Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 1896 | NumExpansions)) { | 
| Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 1897 | Invalid = true; | 
| Douglas Gregor | 44e7df6 | 2011-01-04 00:32:56 +0000 | [diff] [blame] | 1898 | continue; | 
| Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 1899 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1900 |  | 
| Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 1901 | // If we should expand this pack expansion now, do so. | 
|  | 1902 | if (ShouldExpand) { | 
| Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 1903 | for (unsigned I = 0; I != *NumExpansions; ++I) { | 
| Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 1904 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(*this, I); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1905 |  | 
| Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1906 | TypeSourceInfo *BaseTypeLoc = SubstType(Base.getTypeSourceInfo(), | 
| Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 1907 | TemplateArgs, | 
| Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1908 | Base.getSourceRange().getBegin(), | 
| Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 1909 | DeclarationName()); | 
|  | 1910 | if (!BaseTypeLoc) { | 
|  | 1911 | Invalid = true; | 
|  | 1912 | continue; | 
|  | 1913 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1914 |  | 
| Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 1915 | if (CXXBaseSpecifier *InstantiatedBase | 
|  | 1916 | = CheckBaseSpecifier(Instantiation, | 
| Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1917 | Base.getSourceRange(), | 
|  | 1918 | Base.isVirtual(), | 
|  | 1919 | Base.getAccessSpecifierAsWritten(), | 
| Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 1920 | BaseTypeLoc, | 
|  | 1921 | SourceLocation())) | 
|  | 1922 | InstantiatedBases.push_back(InstantiatedBase); | 
|  | 1923 | else | 
|  | 1924 | Invalid = true; | 
|  | 1925 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1926 |  | 
| Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 1927 | continue; | 
|  | 1928 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1929 |  | 
| Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 1930 | // The resulting base specifier will (still) be a pack expansion. | 
| Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1931 | EllipsisLoc = Base.getEllipsisLoc(); | 
| Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 1932 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(*this, -1); | 
| Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1933 | BaseTypeLoc = SubstType(Base.getTypeSourceInfo(), | 
| Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 1934 | TemplateArgs, | 
| Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1935 | Base.getSourceRange().getBegin(), | 
| Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 1936 | DeclarationName()); | 
|  | 1937 | } else { | 
| Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1938 | BaseTypeLoc = SubstType(Base.getTypeSourceInfo(), | 
| Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 1939 | TemplateArgs, | 
| Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1940 | Base.getSourceRange().getBegin(), | 
| Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 1941 | DeclarationName()); | 
| Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 1942 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1943 |  | 
| Nick Lewycky | 19b9f95 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 1944 | if (!BaseTypeLoc) { | 
| Douglas Gregor | 463421d | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 1945 | Invalid = true; | 
|  | 1946 | continue; | 
|  | 1947 | } | 
|  | 1948 |  | 
|  | 1949 | if (CXXBaseSpecifier *InstantiatedBase | 
| Douglas Gregor | 8ea8fd4 | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 1950 | = CheckBaseSpecifier(Instantiation, | 
| Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1951 | Base.getSourceRange(), | 
|  | 1952 | Base.isVirtual(), | 
|  | 1953 | Base.getAccessSpecifierAsWritten(), | 
| Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 1954 | BaseTypeLoc, | 
|  | 1955 | EllipsisLoc)) | 
| Douglas Gregor | 463421d | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 1956 | InstantiatedBases.push_back(InstantiatedBase); | 
|  | 1957 | else | 
|  | 1958 | Invalid = true; | 
|  | 1959 | } | 
|  | 1960 |  | 
| Craig Topper | aa700cb | 2015-12-27 21:55:19 +0000 | [diff] [blame] | 1961 | if (!Invalid && AttachBaseSpecifiers(Instantiation, InstantiatedBases)) | 
| Douglas Gregor | 463421d | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 1962 | Invalid = true; | 
|  | 1963 |  | 
|  | 1964 | return Invalid; | 
|  | 1965 | } | 
|  | 1966 |  | 
| DeLesley Hutchins | 30398dd | 2012-01-20 22:50:54 +0000 | [diff] [blame] | 1967 | // Defined via #include from SemaTemplateInstantiateDecl.cpp | 
| Benjamin Kramer | bf8da9d | 2012-02-06 11:13:08 +0000 | [diff] [blame] | 1968 | namespace clang { | 
|  | 1969 | namespace sema { | 
|  | 1970 | Attr *instantiateTemplateAttribute(const Attr *At, ASTContext &C, Sema &S, | 
|  | 1971 | const MultiLevelTemplateArgumentList &TemplateArgs); | 
| Erich Keane | a32910d | 2017-03-23 18:51:54 +0000 | [diff] [blame] | 1972 | Attr *instantiateTemplateAttributeForDecl( | 
|  | 1973 | const Attr *At, ASTContext &C, Sema &S, | 
|  | 1974 | const MultiLevelTemplateArgumentList &TemplateArgs); | 
| Benjamin Kramer | bf8da9d | 2012-02-06 11:13:08 +0000 | [diff] [blame] | 1975 | } | 
|  | 1976 | } | 
| DeLesley Hutchins | 30398dd | 2012-01-20 22:50:54 +0000 | [diff] [blame] | 1977 |  | 
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1978 | /// Instantiate the definition of a class from a given pattern. | 
| Douglas Gregor | 8ea8fd4 | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 1979 | /// | 
|  | 1980 | /// \param PointOfInstantiation The point of instantiation within the | 
|  | 1981 | /// source code. | 
|  | 1982 | /// | 
|  | 1983 | /// \param Instantiation is the declaration whose definition is being | 
|  | 1984 | /// instantiated. This will be either a class template specialization | 
|  | 1985 | /// or a member class of a class template specialization. | 
|  | 1986 | /// | 
|  | 1987 | /// \param Pattern is the pattern from which the instantiation | 
|  | 1988 | /// occurs. This will be either the declaration of a class template or | 
|  | 1989 | /// the declaration of a member class of a class template. | 
|  | 1990 | /// | 
|  | 1991 | /// \param TemplateArgs The template arguments to be substituted into | 
|  | 1992 | /// the pattern. | 
|  | 1993 | /// | 
| Douglas Gregor | 34ec2ef | 2009-09-04 22:48:11 +0000 | [diff] [blame] | 1994 | /// \param TSK the kind of implicit or explicit instantiation to perform. | 
| Douglas Gregor | 8a2e601 | 2009-08-24 15:23:48 +0000 | [diff] [blame] | 1995 | /// | 
|  | 1996 | /// \param Complain whether to complain if the class cannot be instantiated due | 
|  | 1997 | /// to the lack of a definition. | 
|  | 1998 | /// | 
| Douglas Gregor | 8ea8fd4 | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 1999 | /// \returns true if an error occurred, false otherwise. | 
|  | 2000 | bool | 
|  | 2001 | Sema::InstantiateClass(SourceLocation PointOfInstantiation, | 
|  | 2002 | CXXRecordDecl *Instantiation, CXXRecordDecl *Pattern, | 
| Douglas Gregor | 01afeef | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 2003 | const MultiLevelTemplateArgumentList &TemplateArgs, | 
| Douglas Gregor | 34ec2ef | 2009-09-04 22:48:11 +0000 | [diff] [blame] | 2004 | TemplateSpecializationKind TSK, | 
| Douglas Gregor | 8a2e601 | 2009-08-24 15:23:48 +0000 | [diff] [blame] | 2005 | bool Complain) { | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2006 | CXXRecordDecl *PatternDef | 
| Douglas Gregor | 0a5a221 | 2010-02-11 01:04:33 +0000 | [diff] [blame] | 2007 | = cast_or_null<CXXRecordDecl>(Pattern->getDefinition()); | 
| Vassil Vassilev | b21ee08 | 2016-08-18 22:01:25 +0000 | [diff] [blame] | 2008 | if (DiagnoseUninstantiableTemplate(PointOfInstantiation, Instantiation, | 
| Richard Smith | 4b38ded | 2012-03-14 23:13:10 +0000 | [diff] [blame] | 2009 | Instantiation->getInstantiatedFromMemberClass(), | 
|  | 2010 | Pattern, PatternDef, TSK, Complain)) | 
| Douglas Gregor | 8ea8fd4 | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 2011 | return true; | 
| Douglas Gregor | 8ea8fd4 | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 2012 | Pattern = PatternDef; | 
|  | 2013 |  | 
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2014 | // Record the point of instantiation. | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2015 | if (MemberSpecializationInfo *MSInfo | 
| Douglas Gregor | d6ba93d | 2009-10-15 15:54:05 +0000 | [diff] [blame] | 2016 | = Instantiation->getMemberSpecializationInfo()) { | 
|  | 2017 | MSInfo->setTemplateSpecializationKind(TSK); | 
|  | 2018 | MSInfo->setPointOfInstantiation(PointOfInstantiation); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2019 | } else if (ClassTemplateSpecializationDecl *Spec | 
| Nico Weber | 3ffc4c9 | 2011-12-20 20:32:49 +0000 | [diff] [blame] | 2020 | = dyn_cast<ClassTemplateSpecializationDecl>(Instantiation)) { | 
| Douglas Gregor | ef6ab41 | 2009-10-27 06:26:26 +0000 | [diff] [blame] | 2021 | Spec->setTemplateSpecializationKind(TSK); | 
|  | 2022 | Spec->setPointOfInstantiation(PointOfInstantiation); | 
| Douglas Gregor | d6ba93d | 2009-10-15 15:54:05 +0000 | [diff] [blame] | 2023 | } | 
| Richard Smith | a108760 | 2014-03-10 00:04:29 +0000 | [diff] [blame] | 2024 |  | 
| Douglas Gregor | f3430ae | 2009-03-25 21:23:52 +0000 | [diff] [blame] | 2025 | InstantiatingTemplate Inst(*this, PointOfInstantiation, Instantiation); | 
| Alp Toker | d4a72d5 | 2013-10-08 08:09:04 +0000 | [diff] [blame] | 2026 | if (Inst.isInvalid()) | 
| Douglas Gregor | 8ea8fd4 | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 2027 | return true; | 
| Richard Smith | 54f18e8 | 2016-08-31 02:15:21 +0000 | [diff] [blame] | 2028 | assert(!Inst.isAlreadyInstantiating() && "should have been caught by caller"); | 
| Jordan Rose | 1e879d8 | 2018-03-23 00:07:18 +0000 | [diff] [blame] | 2029 | PrettyDeclStackTraceEntry CrashInfo(Context, Instantiation, SourceLocation(), | 
| Richard Smith | e19b95d | 2016-05-26 20:23:13 +0000 | [diff] [blame] | 2030 | "instantiating class definition"); | 
| Douglas Gregor | 8ea8fd4 | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 2031 |  | 
|  | 2032 | // Enter the scope of this instantiation. We don't use | 
|  | 2033 | // PushDeclContext because we don't have a scope. | 
| John McCall | 80e58cd | 2010-04-29 00:35:03 +0000 | [diff] [blame] | 2034 | ContextRAII SavedContext(*this, Instantiation); | 
| Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 2035 | EnterExpressionEvaluationContext EvalContext( | 
|  | 2036 | *this, Sema::ExpressionEvaluationContext::PotentiallyEvaluated); | 
| Douglas Gregor | 8ea8fd4 | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 2037 |  | 
| Douglas Gregor | 5112157 | 2010-03-24 01:33:17 +0000 | [diff] [blame] | 2038 | // If this is an instantiation of a local class, merge this local | 
|  | 2039 | // instantiation scope with the enclosing scope. Otherwise, every | 
|  | 2040 | // instantiation of a class has its own local instantiation scope. | 
|  | 2041 | bool MergeWithParentScope = !Instantiation->isDefinedOutsideFunctionOrMethod(); | 
| John McCall | 19c1bfd | 2010-08-25 05:32:35 +0000 | [diff] [blame] | 2042 | LocalInstantiationScope Scope(*this, MergeWithParentScope); | 
| Douglas Gregor | 5112157 | 2010-03-24 01:33:17 +0000 | [diff] [blame] | 2043 |  | 
| Volodymyr Sapsai | 4fbaa62 | 2017-09-21 19:54:12 +0000 | [diff] [blame] | 2044 | // Some class state isn't processed immediately but delayed till class | 
|  | 2045 | // instantiation completes. We may not be ready to handle any delayed state | 
|  | 2046 | // already on the stack as it might correspond to a different class, so save | 
|  | 2047 | // it now and put it back later. | 
|  | 2048 | SavePendingParsedClassStateRAII SavedPendingParsedClassState(*this); | 
| Reid Kleckner | 5b64034 | 2016-02-26 19:51:02 +0000 | [diff] [blame] | 2049 |  | 
| John McCall | 6602bb1 | 2010-08-01 02:01:53 +0000 | [diff] [blame] | 2050 | // Pull attributes from the pattern onto the instantiation. | 
|  | 2051 | InstantiateAttrs(TemplateArgs, Pattern, Instantiation); | 
|  | 2052 |  | 
| Douglas Gregor | 8ea8fd4 | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 2053 | // Start the definition of this instantiation. | 
|  | 2054 | Instantiation->startDefinition(); | 
| Richard Smith | a108760 | 2014-03-10 00:04:29 +0000 | [diff] [blame] | 2055 |  | 
|  | 2056 | // The instantiation is visible here, even if it was first declared in an | 
|  | 2057 | // unimported module. | 
| Richard Smith | 90dc525 | 2017-06-23 01:04:34 +0000 | [diff] [blame] | 2058 | Instantiation->setVisibleDespiteOwningModule(); | 
| Richard Smith | a108760 | 2014-03-10 00:04:29 +0000 | [diff] [blame] | 2059 |  | 
|  | 2060 | // FIXME: This loses the as-written tag kind for an explicit instantiation. | 
| Douglas Gregor | e902956 | 2010-05-06 00:28:52 +0000 | [diff] [blame] | 2061 | Instantiation->setTagKind(Pattern->getTagKind()); | 
| Douglas Gregor | 8ea8fd4 | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 2062 |  | 
| John McCall | 76d824f | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 2063 | // Do substitution on the base class specifiers. | 
|  | 2064 | if (SubstBaseSpecifiers(Instantiation, Pattern, TemplateArgs)) | 
| Douglas Gregor | b9b8b81 | 2012-07-02 21:00:41 +0000 | [diff] [blame] | 2065 | Instantiation->setInvalidDecl(); | 
| Douglas Gregor | 8ea8fd4 | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 2066 |  | 
| Douglas Gregor | 869853e | 2010-11-10 19:44:59 +0000 | [diff] [blame] | 2067 | TemplateDeclInstantiator Instantiator(*this, Instantiation, TemplateArgs); | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2068 | SmallVector<Decl*, 4> Fields; | 
| DeLesley Hutchins | 30398dd | 2012-01-20 22:50:54 +0000 | [diff] [blame] | 2069 | // Delay instantiation of late parsed attributes. | 
|  | 2070 | LateInstantiatedAttrVec LateAttrs; | 
|  | 2071 | Instantiator.enableLateAttributeInstantiation(&LateAttrs); | 
|  | 2072 |  | 
| Aaron Ballman | 629afae | 2014-03-07 19:56:05 +0000 | [diff] [blame] | 2073 | for (auto *Member : Pattern->decls()) { | 
| Argyrios Kyrtzidis | 9a94d9b | 2010-11-04 03:18:57 +0000 | [diff] [blame] | 2074 | // Don't instantiate members not belonging in this semantic context. | 
|  | 2075 | // e.g. for: | 
|  | 2076 | // @code | 
|  | 2077 | //    template <int i> class A { | 
|  | 2078 | //      class B *g; | 
|  | 2079 | //    }; | 
|  | 2080 | // @endcode | 
|  | 2081 | // 'class B' has the template as lexical context but semantically it is | 
|  | 2082 | // introduced in namespace scope. | 
| Aaron Ballman | 629afae | 2014-03-07 19:56:05 +0000 | [diff] [blame] | 2083 | if (Member->getDeclContext() != Pattern) | 
| Argyrios Kyrtzidis | 9a94d9b | 2010-11-04 03:18:57 +0000 | [diff] [blame] | 2084 | continue; | 
|  | 2085 |  | 
| Erik Pilkington | a3a462e | 2018-07-23 22:47:37 +0000 | [diff] [blame] | 2086 | // BlockDecls can appear in a default-member-initializer. They must be the | 
|  | 2087 | // child of a BlockExpr, so we only know how to instantiate them from there. | 
|  | 2088 | if (isa<BlockDecl>(Member)) | 
|  | 2089 | continue; | 
|  | 2090 |  | 
| Aaron Ballman | 629afae | 2014-03-07 19:56:05 +0000 | [diff] [blame] | 2091 | if (Member->isInvalidDecl()) { | 
| Richard Smith | ded9c2e | 2012-07-11 22:37:56 +0000 | [diff] [blame] | 2092 | Instantiation->setInvalidDecl(); | 
| Douglas Gregor | 869853e | 2010-11-10 19:44:59 +0000 | [diff] [blame] | 2093 | continue; | 
|  | 2094 | } | 
|  | 2095 |  | 
| Aaron Ballman | 629afae | 2014-03-07 19:56:05 +0000 | [diff] [blame] | 2096 | Decl *NewMember = Instantiator.Visit(Member); | 
| Douglas Gregor | 8ea8fd4 | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 2097 | if (NewMember) { | 
| Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2098 | if (FieldDecl *Field = dyn_cast<FieldDecl>(NewMember)) { | 
| John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2099 | Fields.push_back(Field); | 
| Richard Smith | 7d137e3 | 2012-03-23 03:33:32 +0000 | [diff] [blame] | 2100 | } else if (EnumDecl *Enum = dyn_cast<EnumDecl>(NewMember)) { | 
|  | 2101 | // C++11 [temp.inst]p1: The implicit instantiation of a class template | 
|  | 2102 | // specialization causes the implicit instantiation of the definitions | 
|  | 2103 | // of unscoped member enumerations. | 
|  | 2104 | // Record a point of instantiation for this implicit instantiation. | 
| Richard Smith | b66d777 | 2012-03-23 23:09:08 +0000 | [diff] [blame] | 2105 | if (TSK == TSK_ImplicitInstantiation && !Enum->isScoped() && | 
|  | 2106 | Enum->isCompleteDefinition()) { | 
| Richard Smith | 7d137e3 | 2012-03-23 03:33:32 +0000 | [diff] [blame] | 2107 | MemberSpecializationInfo *MSInfo =Enum->getMemberSpecializationInfo(); | 
|  | 2108 | assert(MSInfo && "no spec info for member enum specialization"); | 
|  | 2109 | MSInfo->setTemplateSpecializationKind(TSK_ImplicitInstantiation); | 
|  | 2110 | MSInfo->setPointOfInstantiation(PointOfInstantiation); | 
|  | 2111 | } | 
| Richard Smith | ded9c2e | 2012-07-11 22:37:56 +0000 | [diff] [blame] | 2112 | } else if (StaticAssertDecl *SA = dyn_cast<StaticAssertDecl>(NewMember)) { | 
|  | 2113 | if (SA->isFailed()) { | 
|  | 2114 | // A static_assert failed. Bail out; instantiating this | 
|  | 2115 | // class is probably not meaningful. | 
|  | 2116 | Instantiation->setInvalidDecl(); | 
|  | 2117 | break; | 
|  | 2118 | } | 
| Richard Smith | 7d137e3 | 2012-03-23 03:33:32 +0000 | [diff] [blame] | 2119 | } | 
|  | 2120 |  | 
|  | 2121 | if (NewMember->isInvalidDecl()) | 
| Douglas Gregor | b9b8b81 | 2012-07-02 21:00:41 +0000 | [diff] [blame] | 2122 | Instantiation->setInvalidDecl(); | 
| Douglas Gregor | 8ea8fd4 | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 2123 | } else { | 
|  | 2124 | // FIXME: Eventually, a NULL return will mean that one of the | 
| Douglas Gregor | b9b8b81 | 2012-07-02 21:00:41 +0000 | [diff] [blame] | 2125 | // instantiations was a semantic disaster, and we'll want to mark the | 
|  | 2126 | // declaration invalid. | 
|  | 2127 | // For now, we expect to skip some members that we can't yet handle. | 
| Douglas Gregor | 8ea8fd4 | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 2128 | } | 
|  | 2129 | } | 
|  | 2130 |  | 
|  | 2131 | // Finish checking fields. | 
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 2132 | ActOnFields(nullptr, Instantiation->getLocation(), Instantiation, Fields, | 
| Erich Keane | c480f30 | 2018-07-12 21:09:05 +0000 | [diff] [blame] | 2133 | SourceLocation(), SourceLocation(), ParsedAttributesView()); | 
| Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 2134 | CheckCompletedCXXClass(Instantiation); | 
| Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2135 |  | 
| Reid Kleckner | 93f661a | 2015-03-17 21:51:43 +0000 | [diff] [blame] | 2136 | // Default arguments are parsed, if not instantiated. We can go instantiate | 
|  | 2137 | // default arg exprs for default constructors if necessary now. | 
| Hans Wennborg | 99000c2 | 2015-08-15 01:18:16 +0000 | [diff] [blame] | 2138 | ActOnFinishCXXNonNestedClass(Instantiation); | 
| Reid Kleckner | 93f661a | 2015-03-17 21:51:43 +0000 | [diff] [blame] | 2139 |  | 
| DeLesley Hutchins | 30398dd | 2012-01-20 22:50:54 +0000 | [diff] [blame] | 2140 | // Instantiate late parsed attributes, and attach them to their decls. | 
|  | 2141 | // See Sema::InstantiateAttrs | 
|  | 2142 | for (LateInstantiatedAttrVec::iterator I = LateAttrs.begin(), | 
|  | 2143 | E = LateAttrs.end(); I != E; ++I) { | 
|  | 2144 | assert(CurrentInstantiationScope == Instantiator.getStartingScope()); | 
|  | 2145 | CurrentInstantiationScope = I->Scope; | 
| Richard Smith | c3d2ebb | 2013-06-07 02:33:37 +0000 | [diff] [blame] | 2146 |  | 
|  | 2147 | // Allow 'this' within late-parsed attributes. | 
|  | 2148 | NamedDecl *ND = dyn_cast<NamedDecl>(I->NewDecl); | 
|  | 2149 | CXXRecordDecl *ThisContext = | 
|  | 2150 | dyn_cast_or_null<CXXRecordDecl>(ND->getDeclContext()); | 
|  | 2151 | CXXThisScopeRAII ThisScope(*this, ThisContext, /*TypeQuals*/0, | 
|  | 2152 | ND && ND->isCXXInstanceMember()); | 
|  | 2153 |  | 
| DeLesley Hutchins | 30398dd | 2012-01-20 22:50:54 +0000 | [diff] [blame] | 2154 | Attr *NewAttr = | 
|  | 2155 | instantiateTemplateAttribute(I->TmplAttr, Context, *this, TemplateArgs); | 
|  | 2156 | I->NewDecl->addAttr(NewAttr); | 
|  | 2157 | LocalInstantiationScope::deleteScopes(I->Scope, | 
|  | 2158 | Instantiator.getStartingScope()); | 
|  | 2159 | } | 
|  | 2160 | Instantiator.disableLateAttributeInstantiation(); | 
|  | 2161 | LateAttrs.clear(); | 
|  | 2162 |  | 
| Richard Smith | d3b5c908 | 2012-07-27 04:22:15 +0000 | [diff] [blame] | 2163 | ActOnFinishDelayedMemberInitializers(Instantiation); | 
| Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2164 |  | 
| Richard Smith | a108760 | 2014-03-10 00:04:29 +0000 | [diff] [blame] | 2165 | // FIXME: We should do something similar for explicit instantiations so they | 
|  | 2166 | // end up in the right module. | 
| Abramo Bagnara | 12dcbf3 | 2011-11-18 08:08:52 +0000 | [diff] [blame] | 2167 | if (TSK == TSK_ImplicitInstantiation) { | 
| Argyrios Kyrtzidis | e378948 | 2012-02-11 01:59:57 +0000 | [diff] [blame] | 2168 | Instantiation->setLocation(Pattern->getLocation()); | 
| Abramo Bagnara | 12dcbf3 | 2011-11-18 08:08:52 +0000 | [diff] [blame] | 2169 | Instantiation->setLocStart(Pattern->getInnerLocStart()); | 
| Argyrios Kyrtzidis | d798c05 | 2016-07-15 18:11:33 +0000 | [diff] [blame] | 2170 | Instantiation->setBraceRange(Pattern->getBraceRange()); | 
| Abramo Bagnara | 12dcbf3 | 2011-11-18 08:08:52 +0000 | [diff] [blame] | 2171 | } | 
| Abramo Bagnara | fd3a455 | 2011-10-03 20:34:03 +0000 | [diff] [blame] | 2172 |  | 
| Douglas Gregor | b9b8b81 | 2012-07-02 21:00:41 +0000 | [diff] [blame] | 2173 | if (!Instantiation->isInvalidDecl()) { | 
| John McCall | a0a9689 | 2012-08-10 03:15:35 +0000 | [diff] [blame] | 2174 | // Perform any dependent diagnostics from the pattern. | 
|  | 2175 | PerformDependentDiagnostics(Pattern, TemplateArgs); | 
|  | 2176 |  | 
| Douglas Gregor | 869853e | 2010-11-10 19:44:59 +0000 | [diff] [blame] | 2177 | // Instantiate any out-of-line class template partial | 
|  | 2178 | // specializations now. | 
| Richard Smith | 10b55fc | 2013-09-26 03:49:48 +0000 | [diff] [blame] | 2179 | for (TemplateDeclInstantiator::delayed_partial_spec_iterator | 
| Douglas Gregor | 869853e | 2010-11-10 19:44:59 +0000 | [diff] [blame] | 2180 | P = Instantiator.delayed_partial_spec_begin(), | 
|  | 2181 | PEnd = Instantiator.delayed_partial_spec_end(); | 
|  | 2182 | P != PEnd; ++P) { | 
|  | 2183 | if (!Instantiator.InstantiateClassTemplatePartialSpecialization( | 
| Richard Smith | 10b55fc | 2013-09-26 03:49:48 +0000 | [diff] [blame] | 2184 | P->first, P->second)) { | 
|  | 2185 | Instantiation->setInvalidDecl(); | 
|  | 2186 | break; | 
|  | 2187 | } | 
|  | 2188 | } | 
|  | 2189 |  | 
|  | 2190 | // Instantiate any out-of-line variable template partial | 
|  | 2191 | // specializations now. | 
|  | 2192 | for (TemplateDeclInstantiator::delayed_var_partial_spec_iterator | 
|  | 2193 | P = Instantiator.delayed_var_partial_spec_begin(), | 
|  | 2194 | PEnd = Instantiator.delayed_var_partial_spec_end(); | 
|  | 2195 | P != PEnd; ++P) { | 
|  | 2196 | if (!Instantiator.InstantiateVarTemplatePartialSpecialization( | 
|  | 2197 | P->first, P->second)) { | 
| Douglas Gregor | b9b8b81 | 2012-07-02 21:00:41 +0000 | [diff] [blame] | 2198 | Instantiation->setInvalidDecl(); | 
| Douglas Gregor | 869853e | 2010-11-10 19:44:59 +0000 | [diff] [blame] | 2199 | break; | 
|  | 2200 | } | 
|  | 2201 | } | 
|  | 2202 | } | 
|  | 2203 |  | 
| Douglas Gregor | 8ea8fd4 | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 2204 | // Exit the scope of this instantiation. | 
| John McCall | 80e58cd | 2010-04-29 00:35:03 +0000 | [diff] [blame] | 2205 | SavedContext.pop(); | 
| Douglas Gregor | 8ea8fd4 | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 2206 |  | 
| Douglas Gregor | b9b8b81 | 2012-07-02 21:00:41 +0000 | [diff] [blame] | 2207 | if (!Instantiation->isInvalidDecl()) { | 
| Douglas Gregor | 28ad4b5 | 2009-05-26 20:50:29 +0000 | [diff] [blame] | 2208 | Consumer.HandleTagDeclDefinition(Instantiation); | 
|  | 2209 |  | 
| Douglas Gregor | 88d292c | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 2210 | // Always emit the vtable for an explicit instantiation definition | 
|  | 2211 | // of a polymorphic class template specialization. | 
|  | 2212 | if (TSK == TSK_ExplicitInstantiationDefinition) | 
|  | 2213 | MarkVTableUsed(PointOfInstantiation, Instantiation, true); | 
|  | 2214 | } | 
|  | 2215 |  | 
| Douglas Gregor | b9b8b81 | 2012-07-02 21:00:41 +0000 | [diff] [blame] | 2216 | return Instantiation->isInvalidDecl(); | 
| Douglas Gregor | 8ea8fd4 | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 2217 | } | 
|  | 2218 |  | 
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2219 | /// Instantiate the definition of an enum from a given pattern. | 
| Richard Smith | 4b38ded | 2012-03-14 23:13:10 +0000 | [diff] [blame] | 2220 | /// | 
|  | 2221 | /// \param PointOfInstantiation The point of instantiation within the | 
|  | 2222 | ///        source code. | 
|  | 2223 | /// \param Instantiation is the declaration whose definition is being | 
|  | 2224 | ///        instantiated. This will be a member enumeration of a class | 
|  | 2225 | ///        temploid specialization, or a local enumeration within a | 
|  | 2226 | ///        function temploid specialization. | 
|  | 2227 | /// \param Pattern The templated declaration from which the instantiation | 
|  | 2228 | ///        occurs. | 
|  | 2229 | /// \param TemplateArgs The template arguments to be substituted into | 
|  | 2230 | ///        the pattern. | 
|  | 2231 | /// \param TSK The kind of implicit or explicit instantiation to perform. | 
|  | 2232 | /// | 
|  | 2233 | /// \return \c true if an error occurred, \c false otherwise. | 
|  | 2234 | bool Sema::InstantiateEnum(SourceLocation PointOfInstantiation, | 
|  | 2235 | EnumDecl *Instantiation, EnumDecl *Pattern, | 
|  | 2236 | const MultiLevelTemplateArgumentList &TemplateArgs, | 
|  | 2237 | TemplateSpecializationKind TSK) { | 
|  | 2238 | EnumDecl *PatternDef = Pattern->getDefinition(); | 
| Vassil Vassilev | b21ee08 | 2016-08-18 22:01:25 +0000 | [diff] [blame] | 2239 | if (DiagnoseUninstantiableTemplate(PointOfInstantiation, Instantiation, | 
| Richard Smith | 4b38ded | 2012-03-14 23:13:10 +0000 | [diff] [blame] | 2240 | Instantiation->getInstantiatedFromMemberEnum(), | 
|  | 2241 | Pattern, PatternDef, TSK,/*Complain*/true)) | 
|  | 2242 | return true; | 
|  | 2243 | Pattern = PatternDef; | 
|  | 2244 |  | 
|  | 2245 | // Record the point of instantiation. | 
|  | 2246 | if (MemberSpecializationInfo *MSInfo | 
|  | 2247 | = Instantiation->getMemberSpecializationInfo()) { | 
|  | 2248 | MSInfo->setTemplateSpecializationKind(TSK); | 
|  | 2249 | MSInfo->setPointOfInstantiation(PointOfInstantiation); | 
|  | 2250 | } | 
|  | 2251 |  | 
|  | 2252 | InstantiatingTemplate Inst(*this, PointOfInstantiation, Instantiation); | 
| Alp Toker | d4a72d5 | 2013-10-08 08:09:04 +0000 | [diff] [blame] | 2253 | if (Inst.isInvalid()) | 
| Richard Smith | 4b38ded | 2012-03-14 23:13:10 +0000 | [diff] [blame] | 2254 | return true; | 
| Richard Smith | 54f18e8 | 2016-08-31 02:15:21 +0000 | [diff] [blame] | 2255 | if (Inst.isAlreadyInstantiating()) | 
|  | 2256 | return false; | 
| Jordan Rose | 1e879d8 | 2018-03-23 00:07:18 +0000 | [diff] [blame] | 2257 | PrettyDeclStackTraceEntry CrashInfo(Context, Instantiation, SourceLocation(), | 
| Richard Smith | e19b95d | 2016-05-26 20:23:13 +0000 | [diff] [blame] | 2258 | "instantiating enum definition"); | 
| Richard Smith | 4b38ded | 2012-03-14 23:13:10 +0000 | [diff] [blame] | 2259 |  | 
| Richard Smith | a108760 | 2014-03-10 00:04:29 +0000 | [diff] [blame] | 2260 | // The instantiation is visible here, even if it was first declared in an | 
|  | 2261 | // unimported module. | 
| Richard Smith | 90dc525 | 2017-06-23 01:04:34 +0000 | [diff] [blame] | 2262 | Instantiation->setVisibleDespiteOwningModule(); | 
| Richard Smith | a108760 | 2014-03-10 00:04:29 +0000 | [diff] [blame] | 2263 |  | 
| Richard Smith | 4b38ded | 2012-03-14 23:13:10 +0000 | [diff] [blame] | 2264 | // Enter the scope of this instantiation. We don't use | 
|  | 2265 | // PushDeclContext because we don't have a scope. | 
|  | 2266 | ContextRAII SavedContext(*this, Instantiation); | 
| Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 2267 | EnterExpressionEvaluationContext EvalContext( | 
|  | 2268 | *this, Sema::ExpressionEvaluationContext::PotentiallyEvaluated); | 
| Richard Smith | 4b38ded | 2012-03-14 23:13:10 +0000 | [diff] [blame] | 2269 |  | 
|  | 2270 | LocalInstantiationScope Scope(*this, /*MergeWithParentScope*/true); | 
|  | 2271 |  | 
|  | 2272 | // Pull attributes from the pattern onto the instantiation. | 
|  | 2273 | InstantiateAttrs(TemplateArgs, Pattern, Instantiation); | 
|  | 2274 |  | 
|  | 2275 | TemplateDeclInstantiator Instantiator(*this, Instantiation, TemplateArgs); | 
|  | 2276 | Instantiator.InstantiateEnumDefinition(Instantiation, Pattern); | 
|  | 2277 |  | 
|  | 2278 | // Exit the scope of this instantiation. | 
|  | 2279 | SavedContext.pop(); | 
|  | 2280 |  | 
|  | 2281 | return Instantiation->isInvalidDecl(); | 
|  | 2282 | } | 
|  | 2283 |  | 
| Reid Kleckner | d60b82f | 2014-11-17 23:36:45 +0000 | [diff] [blame] | 2284 |  | 
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2285 | /// Instantiate the definition of a field from the given pattern. | 
| Reid Kleckner | d60b82f | 2014-11-17 23:36:45 +0000 | [diff] [blame] | 2286 | /// | 
|  | 2287 | /// \param PointOfInstantiation The point of instantiation within the | 
|  | 2288 | ///        source code. | 
|  | 2289 | /// \param Instantiation is the declaration whose definition is being | 
|  | 2290 | ///        instantiated. This will be a class of a class temploid | 
|  | 2291 | ///        specialization, or a local enumeration within a function temploid | 
|  | 2292 | ///        specialization. | 
|  | 2293 | /// \param Pattern The templated declaration from which the instantiation | 
|  | 2294 | ///        occurs. | 
|  | 2295 | /// \param TemplateArgs The template arguments to be substituted into | 
|  | 2296 | ///        the pattern. | 
|  | 2297 | /// | 
|  | 2298 | /// \return \c true if an error occurred, \c false otherwise. | 
|  | 2299 | bool Sema::InstantiateInClassInitializer( | 
|  | 2300 | SourceLocation PointOfInstantiation, FieldDecl *Instantiation, | 
|  | 2301 | FieldDecl *Pattern, const MultiLevelTemplateArgumentList &TemplateArgs) { | 
|  | 2302 | // If there is no initializer, we don't need to do anything. | 
|  | 2303 | if (!Pattern->hasInClassInitializer()) | 
|  | 2304 | return false; | 
|  | 2305 |  | 
|  | 2306 | assert(Instantiation->getInClassInitStyle() == | 
|  | 2307 | Pattern->getInClassInitStyle() && | 
|  | 2308 | "pattern and instantiation disagree about init style"); | 
|  | 2309 |  | 
|  | 2310 | // Error out if we haven't parsed the initializer of the pattern yet because | 
|  | 2311 | // we are waiting for the closing brace of the outer class. | 
|  | 2312 | Expr *OldInit = Pattern->getInClassInitializer(); | 
|  | 2313 | if (!OldInit) { | 
|  | 2314 | RecordDecl *PatternRD = Pattern->getParent(); | 
|  | 2315 | RecordDecl *OutermostClass = PatternRD->getOuterLexicalRecordContext(); | 
| Richard Smith | 8dbc6b2 | 2016-11-22 22:55:12 +0000 | [diff] [blame] | 2316 | Diag(PointOfInstantiation, | 
|  | 2317 | diag::err_in_class_initializer_not_yet_parsed) | 
|  | 2318 | << OutermostClass << Pattern; | 
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 2319 | Diag(Pattern->getEndLoc(), diag::note_in_class_initializer_not_yet_parsed); | 
| Reid Kleckner | d60b82f | 2014-11-17 23:36:45 +0000 | [diff] [blame] | 2320 | Instantiation->setInvalidDecl(); | 
|  | 2321 | return true; | 
|  | 2322 | } | 
|  | 2323 |  | 
|  | 2324 | InstantiatingTemplate Inst(*this, PointOfInstantiation, Instantiation); | 
|  | 2325 | if (Inst.isInvalid()) | 
|  | 2326 | return true; | 
| Richard Smith | 54f18e8 | 2016-08-31 02:15:21 +0000 | [diff] [blame] | 2327 | if (Inst.isAlreadyInstantiating()) { | 
|  | 2328 | // Error out if we hit an instantiation cycle for this initializer. | 
|  | 2329 | Diag(PointOfInstantiation, diag::err_in_class_initializer_cycle) | 
|  | 2330 | << Instantiation; | 
|  | 2331 | return true; | 
|  | 2332 | } | 
| Jordan Rose | 1e879d8 | 2018-03-23 00:07:18 +0000 | [diff] [blame] | 2333 | PrettyDeclStackTraceEntry CrashInfo(Context, Instantiation, SourceLocation(), | 
| Richard Smith | e19b95d | 2016-05-26 20:23:13 +0000 | [diff] [blame] | 2334 | "instantiating default member init"); | 
| Reid Kleckner | d60b82f | 2014-11-17 23:36:45 +0000 | [diff] [blame] | 2335 |  | 
|  | 2336 | // Enter the scope of this instantiation. We don't use PushDeclContext because | 
|  | 2337 | // we don't have a scope. | 
|  | 2338 | ContextRAII SavedContext(*this, Instantiation->getParent()); | 
| Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 2339 | EnterExpressionEvaluationContext EvalContext( | 
|  | 2340 | *this, Sema::ExpressionEvaluationContext::PotentiallyEvaluated); | 
| Reid Kleckner | d60b82f | 2014-11-17 23:36:45 +0000 | [diff] [blame] | 2341 |  | 
| Serge Pavlov | 907233f | 2015-04-28 17:58:47 +0000 | [diff] [blame] | 2342 | LocalInstantiationScope Scope(*this, true); | 
| Reid Kleckner | d60b82f | 2014-11-17 23:36:45 +0000 | [diff] [blame] | 2343 |  | 
|  | 2344 | // Instantiate the initializer. | 
|  | 2345 | ActOnStartCXXInClassMemberInitializer(); | 
|  | 2346 | CXXThisScopeRAII ThisScope(*this, Instantiation->getParent(), /*TypeQuals=*/0); | 
|  | 2347 |  | 
|  | 2348 | ExprResult NewInit = SubstInitializer(OldInit, TemplateArgs, | 
|  | 2349 | /*CXXDirectInit=*/false); | 
|  | 2350 | Expr *Init = NewInit.get(); | 
|  | 2351 | assert((!Init || !isa<ParenListExpr>(Init)) && "call-style init in class"); | 
|  | 2352 | ActOnFinishCXXInClassMemberInitializer( | 
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 2353 | Instantiation, Init ? Init->getBeginLoc() : SourceLocation(), Init); | 
| Reid Kleckner | d60b82f | 2014-11-17 23:36:45 +0000 | [diff] [blame] | 2354 |  | 
| Richard Smith | 4b054b2 | 2016-08-24 21:25:37 +0000 | [diff] [blame] | 2355 | if (auto *L = getASTMutationListener()) | 
|  | 2356 | L->DefaultMemberInitializerInstantiated(Instantiation); | 
|  | 2357 |  | 
| Reid Kleckner | d60b82f | 2014-11-17 23:36:45 +0000 | [diff] [blame] | 2358 | // Return true if the in-class initializer is still missing. | 
|  | 2359 | return !Instantiation->getInClassInitializer(); | 
|  | 2360 | } | 
|  | 2361 |  | 
| Douglas Gregor | 5bb5e4a | 2010-10-12 23:32:35 +0000 | [diff] [blame] | 2362 | namespace { | 
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2363 | /// A partial specialization whose template arguments have matched | 
| Douglas Gregor | 5bb5e4a | 2010-10-12 23:32:35 +0000 | [diff] [blame] | 2364 | /// a given template-id. | 
|  | 2365 | struct PartialSpecMatchResult { | 
|  | 2366 | ClassTemplatePartialSpecializationDecl *Partial; | 
|  | 2367 | TemplateArgumentList *Args; | 
| Douglas Gregor | 5bb5e4a | 2010-10-12 23:32:35 +0000 | [diff] [blame] | 2368 | }; | 
|  | 2369 | } | 
|  | 2370 |  | 
| Richard Smith | e6d4b77 | 2017-06-07 02:42:27 +0000 | [diff] [blame] | 2371 | bool Sema::usesPartialOrExplicitSpecialization( | 
|  | 2372 | SourceLocation Loc, ClassTemplateSpecializationDecl *ClassTemplateSpec) { | 
|  | 2373 | if (ClassTemplateSpec->getTemplateSpecializationKind() == | 
|  | 2374 | TSK_ExplicitSpecialization) | 
|  | 2375 | return true; | 
|  | 2376 |  | 
|  | 2377 | SmallVector<ClassTemplatePartialSpecializationDecl *, 4> PartialSpecs; | 
|  | 2378 | ClassTemplateSpec->getSpecializedTemplate() | 
|  | 2379 | ->getPartialSpecializations(PartialSpecs); | 
|  | 2380 | for (unsigned I = 0, N = PartialSpecs.size(); I != N; ++I) { | 
|  | 2381 | TemplateDeductionInfo Info(Loc); | 
|  | 2382 | if (!DeduceTemplateArguments(PartialSpecs[I], | 
|  | 2383 | ClassTemplateSpec->getTemplateArgs(), Info)) | 
|  | 2384 | return true; | 
|  | 2385 | } | 
|  | 2386 |  | 
|  | 2387 | return false; | 
|  | 2388 | } | 
|  | 2389 |  | 
| Richard Smith | 32b4376 | 2017-01-08 22:45:21 +0000 | [diff] [blame] | 2390 | /// Get the instantiation pattern to use to instantiate the definition of a | 
|  | 2391 | /// given ClassTemplateSpecializationDecl (either the pattern of the primary | 
|  | 2392 | /// template or of a partial specialization). | 
|  | 2393 | static CXXRecordDecl * | 
|  | 2394 | getPatternForClassTemplateSpecialization( | 
|  | 2395 | Sema &S, SourceLocation PointOfInstantiation, | 
| Larisse Voufo | 72caf2b | 2013-08-22 00:59:14 +0000 | [diff] [blame] | 2396 | ClassTemplateSpecializationDecl *ClassTemplateSpec, | 
|  | 2397 | TemplateSpecializationKind TSK, bool Complain) { | 
| Richard Smith | 32b4376 | 2017-01-08 22:45:21 +0000 | [diff] [blame] | 2398 | Sema::InstantiatingTemplate Inst(S, PointOfInstantiation, ClassTemplateSpec); | 
|  | 2399 | if (Inst.isInvalid() || Inst.isAlreadyInstantiating()) | 
|  | 2400 | return nullptr; | 
|  | 2401 |  | 
| Volodymyr Sapsai | 9b97348 | 2018-05-16 18:28:58 +0000 | [diff] [blame] | 2402 | llvm::PointerUnion<ClassTemplateDecl *, | 
|  | 2403 | ClassTemplatePartialSpecializationDecl *> | 
|  | 2404 | Specialized = ClassTemplateSpec->getSpecializedTemplateOrPartial(); | 
|  | 2405 | if (!Specialized.is<ClassTemplatePartialSpecializationDecl *>()) { | 
|  | 2406 | // Find best matching specialization. | 
|  | 2407 | ClassTemplateDecl *Template = ClassTemplateSpec->getSpecializedTemplate(); | 
| Douglas Gregor | 2373c59 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 2408 |  | 
| Volodymyr Sapsai | 9b97348 | 2018-05-16 18:28:58 +0000 | [diff] [blame] | 2409 | // C++ [temp.class.spec.match]p1: | 
|  | 2410 | //   When a class template is used in a context that requires an | 
|  | 2411 | //   instantiation of the class, it is necessary to determine | 
|  | 2412 | //   whether the instantiation is to be generated using the primary | 
|  | 2413 | //   template or one of the partial specializations. This is done by | 
|  | 2414 | //   matching the template arguments of the class template | 
|  | 2415 | //   specialization with the template argument lists of the partial | 
|  | 2416 | //   specializations. | 
|  | 2417 | typedef PartialSpecMatchResult MatchResult; | 
|  | 2418 | SmallVector<MatchResult, 4> Matched; | 
|  | 2419 | SmallVector<ClassTemplatePartialSpecializationDecl *, 4> PartialSpecs; | 
|  | 2420 | Template->getPartialSpecializations(PartialSpecs); | 
|  | 2421 | TemplateSpecCandidateSet FailedCandidates(PointOfInstantiation); | 
|  | 2422 | for (unsigned I = 0, N = PartialSpecs.size(); I != N; ++I) { | 
|  | 2423 | ClassTemplatePartialSpecializationDecl *Partial = PartialSpecs[I]; | 
|  | 2424 | TemplateDeductionInfo Info(FailedCandidates.getLocation()); | 
|  | 2425 | if (Sema::TemplateDeductionResult Result = S.DeduceTemplateArguments( | 
|  | 2426 | Partial, ClassTemplateSpec->getTemplateArgs(), Info)) { | 
|  | 2427 | // Store the failed-deduction information for use in diagnostics, later. | 
|  | 2428 | // TODO: Actually use the failed-deduction info? | 
|  | 2429 | FailedCandidates.addCandidate().set( | 
|  | 2430 | DeclAccessPair::make(Template, AS_public), Partial, | 
|  | 2431 | MakeDeductionFailureInfo(S.Context, Result, Info)); | 
|  | 2432 | (void)Result; | 
|  | 2433 | } else { | 
|  | 2434 | Matched.push_back(PartialSpecMatchResult()); | 
|  | 2435 | Matched.back().Partial = Partial; | 
|  | 2436 | Matched.back().Args = Info.take(); | 
|  | 2437 | } | 
|  | 2438 | } | 
|  | 2439 |  | 
|  | 2440 | // If we're dealing with a member template where the template parameters | 
|  | 2441 | // have been instantiated, this provides the original template parameters | 
|  | 2442 | // from which the member template's parameters were instantiated. | 
|  | 2443 |  | 
|  | 2444 | if (Matched.size() >= 1) { | 
|  | 2445 | SmallVectorImpl<MatchResult>::iterator Best = Matched.begin(); | 
|  | 2446 | if (Matched.size() == 1) { | 
|  | 2447 | //   -- If exactly one matching specialization is found, the | 
|  | 2448 | //      instantiation is generated from that specialization. | 
|  | 2449 | // We don't need to do anything for this. | 
|  | 2450 | } else { | 
|  | 2451 | //   -- If more than one matching specialization is found, the | 
|  | 2452 | //      partial order rules (14.5.4.2) are used to determine | 
|  | 2453 | //      whether one of the specializations is more specialized | 
|  | 2454 | //      than the others. If none of the specializations is more | 
|  | 2455 | //      specialized than all of the other matching | 
|  | 2456 | //      specializations, then the use of the class template is | 
|  | 2457 | //      ambiguous and the program is ill-formed. | 
|  | 2458 | for (SmallVectorImpl<MatchResult>::iterator P = Best + 1, | 
|  | 2459 | PEnd = Matched.end(); | 
|  | 2460 | P != PEnd; ++P) { | 
|  | 2461 | if (S.getMoreSpecializedPartialSpecialization( | 
|  | 2462 | P->Partial, Best->Partial, PointOfInstantiation) == | 
|  | 2463 | P->Partial) | 
|  | 2464 | Best = P; | 
|  | 2465 | } | 
|  | 2466 |  | 
|  | 2467 | // Determine if the best partial specialization is more specialized than | 
|  | 2468 | // the others. | 
|  | 2469 | bool Ambiguous = false; | 
|  | 2470 | for (SmallVectorImpl<MatchResult>::iterator P = Matched.begin(), | 
|  | 2471 | PEnd = Matched.end(); | 
|  | 2472 | P != PEnd; ++P) { | 
|  | 2473 | if (P != Best && S.getMoreSpecializedPartialSpecialization( | 
|  | 2474 | P->Partial, Best->Partial, | 
|  | 2475 | PointOfInstantiation) != Best->Partial) { | 
|  | 2476 | Ambiguous = true; | 
|  | 2477 | break; | 
|  | 2478 | } | 
|  | 2479 | } | 
|  | 2480 |  | 
|  | 2481 | if (Ambiguous) { | 
|  | 2482 | // Partial ordering did not produce a clear winner. Complain. | 
|  | 2483 | Inst.Clear(); | 
|  | 2484 | ClassTemplateSpec->setInvalidDecl(); | 
|  | 2485 | S.Diag(PointOfInstantiation, | 
|  | 2486 | diag::err_partial_spec_ordering_ambiguous) | 
|  | 2487 | << ClassTemplateSpec; | 
|  | 2488 |  | 
|  | 2489 | // Print the matching partial specializations. | 
|  | 2490 | for (SmallVectorImpl<MatchResult>::iterator P = Matched.begin(), | 
|  | 2491 | PEnd = Matched.end(); | 
|  | 2492 | P != PEnd; ++P) | 
|  | 2493 | S.Diag(P->Partial->getLocation(), diag::note_partial_spec_match) | 
|  | 2494 | << S.getTemplateArgumentBindingsText( | 
|  | 2495 | P->Partial->getTemplateParameters(), *P->Args); | 
|  | 2496 |  | 
|  | 2497 | return nullptr; | 
|  | 2498 | } | 
|  | 2499 | } | 
|  | 2500 |  | 
|  | 2501 | ClassTemplateSpec->setInstantiationOf(Best->Partial, Best->Args); | 
| Douglas Gregor | 181aa4a | 2009-06-12 18:26:56 +0000 | [diff] [blame] | 2502 | } else { | 
| Volodymyr Sapsai | 9b97348 | 2018-05-16 18:28:58 +0000 | [diff] [blame] | 2503 | //   -- If no matches are found, the instantiation is generated | 
|  | 2504 | //      from the primary template. | 
| Douglas Gregor | 181aa4a | 2009-06-12 18:26:56 +0000 | [diff] [blame] | 2505 | } | 
| Douglas Gregor | 2373c59 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 2506 | } | 
|  | 2507 |  | 
| Volodymyr Sapsai | 9b97348 | 2018-05-16 18:28:58 +0000 | [diff] [blame] | 2508 | CXXRecordDecl *Pattern = nullptr; | 
|  | 2509 | Specialized = ClassTemplateSpec->getSpecializedTemplateOrPartial(); | 
|  | 2510 | if (auto *PartialSpec = | 
|  | 2511 | Specialized.dyn_cast<ClassTemplatePartialSpecializationDecl *>()) { | 
| Douglas Gregor | be99939 | 2009-09-15 16:23:51 +0000 | [diff] [blame] | 2512 | // Instantiate using the best class template partial specialization. | 
| Volodymyr Sapsai | 9b97348 | 2018-05-16 18:28:58 +0000 | [diff] [blame] | 2513 | while (PartialSpec->getInstantiatedFromMember()) { | 
| Douglas Gregor | 2161038 | 2009-10-29 00:04:11 +0000 | [diff] [blame] | 2514 | // If we've found an explicit specialization of this class template, | 
|  | 2515 | // stop here and use that as the pattern. | 
| Volodymyr Sapsai | 9b97348 | 2018-05-16 18:28:58 +0000 | [diff] [blame] | 2516 | if (PartialSpec->isMemberSpecialization()) | 
| Douglas Gregor | 2161038 | 2009-10-29 00:04:11 +0000 | [diff] [blame] | 2517 | break; | 
| Volodymyr Sapsai | 9b97348 | 2018-05-16 18:28:58 +0000 | [diff] [blame] | 2518 |  | 
|  | 2519 | PartialSpec = PartialSpec->getInstantiatedFromMember(); | 
| Douglas Gregor | 2161038 | 2009-10-29 00:04:11 +0000 | [diff] [blame] | 2520 | } | 
| Volodymyr Sapsai | 9b97348 | 2018-05-16 18:28:58 +0000 | [diff] [blame] | 2521 | Pattern = PartialSpec; | 
| Douglas Gregor | 170bc42 | 2009-06-12 22:31:52 +0000 | [diff] [blame] | 2522 | } else { | 
| Volodymyr Sapsai | 9b97348 | 2018-05-16 18:28:58 +0000 | [diff] [blame] | 2523 | ClassTemplateDecl *Template = ClassTemplateSpec->getSpecializedTemplate(); | 
|  | 2524 | while (Template->getInstantiatedFromMemberTemplate()) { | 
| Douglas Gregor | cf91555 | 2009-10-13 16:30:37 +0000 | [diff] [blame] | 2525 | // If we've found an explicit specialization of this class template, | 
|  | 2526 | // stop here and use that as the pattern. | 
| Volodymyr Sapsai | 9b97348 | 2018-05-16 18:28:58 +0000 | [diff] [blame] | 2527 | if (Template->isMemberSpecialization()) | 
| Douglas Gregor | cf91555 | 2009-10-13 16:30:37 +0000 | [diff] [blame] | 2528 | break; | 
| Volodymyr Sapsai | 9b97348 | 2018-05-16 18:28:58 +0000 | [diff] [blame] | 2529 |  | 
|  | 2530 | Template = Template->getInstantiatedFromMemberTemplate(); | 
| Douglas Gregor | cf91555 | 2009-10-13 16:30:37 +0000 | [diff] [blame] | 2531 | } | 
| Volodymyr Sapsai | 9b97348 | 2018-05-16 18:28:58 +0000 | [diff] [blame] | 2532 | Pattern = Template->getTemplatedDecl(); | 
| Douglas Gregor | 2373c59 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 2533 | } | 
| Douglas Gregor | 463421d | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 2534 |  | 
| Richard Smith | 32b4376 | 2017-01-08 22:45:21 +0000 | [diff] [blame] | 2535 | return Pattern; | 
|  | 2536 | } | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2537 |  | 
| Richard Smith | 32b4376 | 2017-01-08 22:45:21 +0000 | [diff] [blame] | 2538 | bool Sema::InstantiateClassTemplateSpecialization( | 
|  | 2539 | SourceLocation PointOfInstantiation, | 
|  | 2540 | ClassTemplateSpecializationDecl *ClassTemplateSpec, | 
|  | 2541 | TemplateSpecializationKind TSK, bool Complain) { | 
|  | 2542 | // Perform the actual instantiation on the canonical declaration. | 
|  | 2543 | ClassTemplateSpec = cast<ClassTemplateSpecializationDecl>( | 
|  | 2544 | ClassTemplateSpec->getCanonicalDecl()); | 
|  | 2545 | if (ClassTemplateSpec->isInvalidDecl()) | 
|  | 2546 | return true; | 
|  | 2547 |  | 
|  | 2548 | CXXRecordDecl *Pattern = getPatternForClassTemplateSpecialization( | 
|  | 2549 | *this, PointOfInstantiation, ClassTemplateSpec, TSK, Complain); | 
|  | 2550 | if (!Pattern) | 
|  | 2551 | return true; | 
|  | 2552 |  | 
|  | 2553 | return InstantiateClass(PointOfInstantiation, ClassTemplateSpec, Pattern, | 
|  | 2554 | getTemplateInstantiationArgs(ClassTemplateSpec), TSK, | 
|  | 2555 | Complain); | 
| Douglas Gregor | 463421d | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 2556 | } | 
| Douglas Gregor | 90a1a65 | 2009-03-19 17:26:29 +0000 | [diff] [blame] | 2557 |  | 
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2558 | /// Instantiates the definitions of all of the member | 
| John McCall | 76d824f | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 2559 | /// of the given class, which is an instantiation of a class template | 
|  | 2560 | /// or a member class of a template. | 
| Douglas Gregor | bbbb02d | 2009-05-13 20:28:22 +0000 | [diff] [blame] | 2561 | void | 
|  | 2562 | Sema::InstantiateClassMembers(SourceLocation PointOfInstantiation, | 
| Douglas Gregor | 34ec2ef | 2009-09-04 22:48:11 +0000 | [diff] [blame] | 2563 | CXXRecordDecl *Instantiation, | 
|  | 2564 | const MultiLevelTemplateArgumentList &TemplateArgs, | 
|  | 2565 | TemplateSpecializationKind TSK) { | 
| Richard Smith | eb36ddf | 2014-04-24 22:45:46 +0000 | [diff] [blame] | 2566 | // FIXME: We need to notify the ASTMutationListener that we did all of these | 
|  | 2567 | // things, in case we have an explicit instantiation definition in a PCM, a | 
|  | 2568 | // module, or preamble, and the declaration is in an imported AST. | 
| David Majnemer | 192d179 | 2013-11-27 08:20:38 +0000 | [diff] [blame] | 2569 | assert( | 
|  | 2570 | (TSK == TSK_ExplicitInstantiationDefinition || | 
|  | 2571 | TSK == TSK_ExplicitInstantiationDeclaration || | 
|  | 2572 | (TSK == TSK_ImplicitInstantiation && Instantiation->isLocalClass())) && | 
|  | 2573 | "Unexpected template specialization kind!"); | 
| Aaron Ballman | 629afae | 2014-03-07 19:56:05 +0000 | [diff] [blame] | 2574 | for (auto *D : Instantiation->decls()) { | 
| Douglas Gregor | 1d957a3 | 2009-10-27 18:42:08 +0000 | [diff] [blame] | 2575 | bool SuppressNew = false; | 
| Aaron Ballman | 629afae | 2014-03-07 19:56:05 +0000 | [diff] [blame] | 2576 | if (auto *Function = dyn_cast<FunctionDecl>(D)) { | 
| Douglas Gregor | 1d957a3 | 2009-10-27 18:42:08 +0000 | [diff] [blame] | 2577 | if (FunctionDecl *Pattern | 
|  | 2578 | = Function->getInstantiatedFromMemberFunction()) { | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2579 | MemberSpecializationInfo *MSInfo | 
| Douglas Gregor | 1d957a3 | 2009-10-27 18:42:08 +0000 | [diff] [blame] | 2580 | = Function->getMemberSpecializationInfo(); | 
|  | 2581 | assert(MSInfo && "No member specialization information?"); | 
| Douglas Gregor | 06aa5041 | 2010-04-09 21:02:29 +0000 | [diff] [blame] | 2582 | if (MSInfo->getTemplateSpecializationKind() | 
|  | 2583 | == TSK_ExplicitSpecialization) | 
|  | 2584 | continue; | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2585 |  | 
|  | 2586 | if (CheckSpecializationInstantiationRedecl(PointOfInstantiation, TSK, | 
|  | 2587 | Function, | 
| Douglas Gregor | 1d957a3 | 2009-10-27 18:42:08 +0000 | [diff] [blame] | 2588 | MSInfo->getTemplateSpecializationKind(), | 
| Nico Weber | d75488d | 2010-09-27 21:02:09 +0000 | [diff] [blame] | 2589 | MSInfo->getPointOfInstantiation(), | 
| Douglas Gregor | 1d957a3 | 2009-10-27 18:42:08 +0000 | [diff] [blame] | 2590 | SuppressNew) || | 
|  | 2591 | SuppressNew) | 
| Douglas Gregor | bbe8f46 | 2009-10-08 15:14:33 +0000 | [diff] [blame] | 2592 | continue; | 
| Richard Smith | eb36ddf | 2014-04-24 22:45:46 +0000 | [diff] [blame] | 2593 |  | 
|  | 2594 | // C++11 [temp.explicit]p8: | 
|  | 2595 | //   An explicit instantiation definition that names a class template | 
|  | 2596 | //   specialization explicitly instantiates the class template | 
|  | 2597 | //   specialization and is only an explicit instantiation definition | 
|  | 2598 | //   of members whose definition is visible at the point of | 
|  | 2599 | //   instantiation. | 
|  | 2600 | if (TSK == TSK_ExplicitInstantiationDefinition && !Pattern->isDefined()) | 
| Douglas Gregor | 1d957a3 | 2009-10-27 18:42:08 +0000 | [diff] [blame] | 2601 | continue; | 
|  | 2602 |  | 
| Richard Smith | eb36ddf | 2014-04-24 22:45:46 +0000 | [diff] [blame] | 2603 | Function->setTemplateSpecializationKind(TSK, PointOfInstantiation); | 
|  | 2604 |  | 
|  | 2605 | if (Function->isDefined()) { | 
|  | 2606 | // Let the ASTConsumer know that this function has been explicitly | 
|  | 2607 | // instantiated now, and its linkage might have changed. | 
|  | 2608 | Consumer.HandleTopLevelDecl(DeclGroupRef(Function)); | 
|  | 2609 | } else if (TSK == TSK_ExplicitInstantiationDefinition) { | 
| Douglas Gregor | 1d957a3 | 2009-10-27 18:42:08 +0000 | [diff] [blame] | 2610 | InstantiateFunctionDefinition(PointOfInstantiation, Function); | 
| Richard Smith | eb36ddf | 2014-04-24 22:45:46 +0000 | [diff] [blame] | 2611 | } else if (TSK == TSK_ImplicitInstantiation) { | 
|  | 2612 | PendingLocalImplicitInstantiations.push_back( | 
|  | 2613 | std::make_pair(Function, PointOfInstantiation)); | 
| Douglas Gregor | 1d957a3 | 2009-10-27 18:42:08 +0000 | [diff] [blame] | 2614 | } | 
| Douglas Gregor | bbe8f46 | 2009-10-08 15:14:33 +0000 | [diff] [blame] | 2615 | } | 
| Aaron Ballman | 629afae | 2014-03-07 19:56:05 +0000 | [diff] [blame] | 2616 | } else if (auto *Var = dyn_cast<VarDecl>(D)) { | 
| Richard Smith | 8809a0c | 2013-09-27 20:14:12 +0000 | [diff] [blame] | 2617 | if (isa<VarTemplateSpecializationDecl>(Var)) | 
|  | 2618 | continue; | 
|  | 2619 |  | 
| Douglas Gregor | 86d142a | 2009-10-08 07:24:58 +0000 | [diff] [blame] | 2620 | if (Var->isStaticDataMember()) { | 
| Douglas Gregor | 1d957a3 | 2009-10-27 18:42:08 +0000 | [diff] [blame] | 2621 | MemberSpecializationInfo *MSInfo = Var->getMemberSpecializationInfo(); | 
|  | 2622 | assert(MSInfo && "No member specialization information?"); | 
| Douglas Gregor | 06aa5041 | 2010-04-09 21:02:29 +0000 | [diff] [blame] | 2623 | if (MSInfo->getTemplateSpecializationKind() | 
|  | 2624 | == TSK_ExplicitSpecialization) | 
|  | 2625 | continue; | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2626 |  | 
|  | 2627 | if (CheckSpecializationInstantiationRedecl(PointOfInstantiation, TSK, | 
|  | 2628 | Var, | 
| Douglas Gregor | 1d957a3 | 2009-10-27 18:42:08 +0000 | [diff] [blame] | 2629 | MSInfo->getTemplateSpecializationKind(), | 
| Nico Weber | d75488d | 2010-09-27 21:02:09 +0000 | [diff] [blame] | 2630 | MSInfo->getPointOfInstantiation(), | 
| Douglas Gregor | 1d957a3 | 2009-10-27 18:42:08 +0000 | [diff] [blame] | 2631 | SuppressNew) || | 
|  | 2632 | SuppressNew) | 
| Douglas Gregor | bbe8f46 | 2009-10-08 15:14:33 +0000 | [diff] [blame] | 2633 | continue; | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2634 |  | 
| Douglas Gregor | 1d957a3 | 2009-10-27 18:42:08 +0000 | [diff] [blame] | 2635 | if (TSK == TSK_ExplicitInstantiationDefinition) { | 
|  | 2636 | // C++0x [temp.explicit]p8: | 
|  | 2637 | //   An explicit instantiation definition that names a class template | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2638 | //   specialization explicitly instantiates the class template | 
|  | 2639 | //   specialization and is only an explicit instantiation definition | 
|  | 2640 | //   of members whose definition is visible at the point of | 
| Douglas Gregor | 1d957a3 | 2009-10-27 18:42:08 +0000 | [diff] [blame] | 2641 | //   instantiation. | 
| Richard Smith | 62f19e7 | 2016-06-25 00:15:56 +0000 | [diff] [blame] | 2642 | if (!Var->getInstantiatedFromStaticDataMember()->getDefinition()) | 
| Douglas Gregor | 1d957a3 | 2009-10-27 18:42:08 +0000 | [diff] [blame] | 2643 | continue; | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2644 |  | 
| Douglas Gregor | 1d957a3 | 2009-10-27 18:42:08 +0000 | [diff] [blame] | 2645 | Var->setTemplateSpecializationKind(TSK, PointOfInstantiation); | 
| Richard Smith | 891fc7f | 2017-12-05 01:31:47 +0000 | [diff] [blame] | 2646 | InstantiateVariableDefinition(PointOfInstantiation, Var); | 
| Douglas Gregor | 1d957a3 | 2009-10-27 18:42:08 +0000 | [diff] [blame] | 2647 | } else { | 
|  | 2648 | Var->setTemplateSpecializationKind(TSK, PointOfInstantiation); | 
|  | 2649 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2650 | } | 
| Aaron Ballman | 629afae | 2014-03-07 19:56:05 +0000 | [diff] [blame] | 2651 | } else if (auto *Record = dyn_cast<CXXRecordDecl>(D)) { | 
| Douglas Gregor | 1da2225 | 2010-04-18 18:11:38 +0000 | [diff] [blame] | 2652 | // Always skip the injected-class-name, along with any | 
|  | 2653 | // redeclarations of nested classes, since both would cause us | 
|  | 2654 | // to try to instantiate the members of a class twice. | 
| Richard Smith | 069ecf6 | 2014-11-20 22:56:34 +0000 | [diff] [blame] | 2655 | // Skip closure types; they'll get instantiated when we instantiate | 
|  | 2656 | // the corresponding lambda-expression. | 
|  | 2657 | if (Record->isInjectedClassName() || Record->getPreviousDecl() || | 
|  | 2658 | Record->isLambda()) | 
| Douglas Gregor | d801b06 | 2009-10-07 23:56:10 +0000 | [diff] [blame] | 2659 | continue; | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2660 |  | 
| Douglas Gregor | 1d957a3 | 2009-10-27 18:42:08 +0000 | [diff] [blame] | 2661 | MemberSpecializationInfo *MSInfo = Record->getMemberSpecializationInfo(); | 
|  | 2662 | assert(MSInfo && "No member specialization information?"); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2663 |  | 
| Douglas Gregor | 06aa5041 | 2010-04-09 21:02:29 +0000 | [diff] [blame] | 2664 | if (MSInfo->getTemplateSpecializationKind() | 
|  | 2665 | == TSK_ExplicitSpecialization) | 
|  | 2666 | continue; | 
| Nico Weber | d75488d | 2010-09-27 21:02:09 +0000 | [diff] [blame] | 2667 |  | 
| Shoaib Meenai | a904745 | 2017-04-20 01:11:42 +0000 | [diff] [blame] | 2668 | if ((Context.getTargetInfo().getCXXABI().isMicrosoft() || | 
|  | 2669 | Context.getTargetInfo().getTriple().isWindowsItaniumEnvironment()) && | 
| Hans Wennborg | a86a83b | 2016-05-26 19:42:56 +0000 | [diff] [blame] | 2670 | TSK == TSK_ExplicitInstantiationDeclaration) { | 
| Shoaib Meenai | a904745 | 2017-04-20 01:11:42 +0000 | [diff] [blame] | 2671 | // In MSVC and Windows Itanium mode, explicit instantiation decl of the | 
|  | 2672 | // outer class doesn't affect the inner class. | 
| Hans Wennborg | a86a83b | 2016-05-26 19:42:56 +0000 | [diff] [blame] | 2673 | continue; | 
|  | 2674 | } | 
|  | 2675 |  | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2676 | if (CheckSpecializationInstantiationRedecl(PointOfInstantiation, TSK, | 
|  | 2677 | Record, | 
| Douglas Gregor | 1d957a3 | 2009-10-27 18:42:08 +0000 | [diff] [blame] | 2678 | MSInfo->getTemplateSpecializationKind(), | 
| Nico Weber | d75488d | 2010-09-27 21:02:09 +0000 | [diff] [blame] | 2679 | MSInfo->getPointOfInstantiation(), | 
| Douglas Gregor | 1d957a3 | 2009-10-27 18:42:08 +0000 | [diff] [blame] | 2680 | SuppressNew) || | 
|  | 2681 | SuppressNew) | 
| Douglas Gregor | bbe8f46 | 2009-10-08 15:14:33 +0000 | [diff] [blame] | 2682 | continue; | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2683 |  | 
| Douglas Gregor | 1d957a3 | 2009-10-27 18:42:08 +0000 | [diff] [blame] | 2684 | CXXRecordDecl *Pattern = Record->getInstantiatedFromMemberClass(); | 
|  | 2685 | assert(Pattern && "Missing instantiated-from-template information"); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2686 |  | 
| Douglas Gregor | 0a5a221 | 2010-02-11 01:04:33 +0000 | [diff] [blame] | 2687 | if (!Record->getDefinition()) { | 
|  | 2688 | if (!Pattern->getDefinition()) { | 
| Douglas Gregor | 1d957a3 | 2009-10-27 18:42:08 +0000 | [diff] [blame] | 2689 | // C++0x [temp.explicit]p8: | 
|  | 2690 | //   An explicit instantiation definition that names a class template | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2691 | //   specialization explicitly instantiates the class template | 
|  | 2692 | //   specialization and is only an explicit instantiation definition | 
|  | 2693 | //   of members whose definition is visible at the point of | 
| Douglas Gregor | 1d957a3 | 2009-10-27 18:42:08 +0000 | [diff] [blame] | 2694 | //   instantiation. | 
|  | 2695 | if (TSK == TSK_ExplicitInstantiationDeclaration) { | 
|  | 2696 | MSInfo->setTemplateSpecializationKind(TSK); | 
|  | 2697 | MSInfo->setPointOfInstantiation(PointOfInstantiation); | 
|  | 2698 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2699 |  | 
| Douglas Gregor | 1d957a3 | 2009-10-27 18:42:08 +0000 | [diff] [blame] | 2700 | continue; | 
|  | 2701 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2702 |  | 
| Douglas Gregor | 1d957a3 | 2009-10-27 18:42:08 +0000 | [diff] [blame] | 2703 | InstantiateClass(PointOfInstantiation, Record, Pattern, | 
| Douglas Gregor | 34ec2ef | 2009-09-04 22:48:11 +0000 | [diff] [blame] | 2704 | TemplateArgs, | 
|  | 2705 | TSK); | 
| Nico Weber | d75488d | 2010-09-27 21:02:09 +0000 | [diff] [blame] | 2706 | } else { | 
|  | 2707 | if (TSK == TSK_ExplicitInstantiationDefinition && | 
|  | 2708 | Record->getTemplateSpecializationKind() == | 
|  | 2709 | TSK_ExplicitInstantiationDeclaration) { | 
|  | 2710 | Record->setTemplateSpecializationKind(TSK); | 
|  | 2711 | MarkVTableUsed(PointOfInstantiation, Record, true); | 
|  | 2712 | } | 
| Douglas Gregor | 1d957a3 | 2009-10-27 18:42:08 +0000 | [diff] [blame] | 2713 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2714 |  | 
| Douglas Gregor | 0a5a221 | 2010-02-11 01:04:33 +0000 | [diff] [blame] | 2715 | Pattern = cast_or_null<CXXRecordDecl>(Record->getDefinition()); | 
| Douglas Gregor | 1d957a3 | 2009-10-27 18:42:08 +0000 | [diff] [blame] | 2716 | if (Pattern) | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2717 | InstantiateClassMembers(PointOfInstantiation, Pattern, TemplateArgs, | 
| Douglas Gregor | 1d957a3 | 2009-10-27 18:42:08 +0000 | [diff] [blame] | 2718 | TSK); | 
| Aaron Ballman | 629afae | 2014-03-07 19:56:05 +0000 | [diff] [blame] | 2719 | } else if (auto *Enum = dyn_cast<EnumDecl>(D)) { | 
| Richard Smith | 4b38ded | 2012-03-14 23:13:10 +0000 | [diff] [blame] | 2720 | MemberSpecializationInfo *MSInfo = Enum->getMemberSpecializationInfo(); | 
|  | 2721 | assert(MSInfo && "No member specialization information?"); | 
|  | 2722 |  | 
|  | 2723 | if (MSInfo->getTemplateSpecializationKind() | 
|  | 2724 | == TSK_ExplicitSpecialization) | 
|  | 2725 | continue; | 
|  | 2726 |  | 
|  | 2727 | if (CheckSpecializationInstantiationRedecl( | 
|  | 2728 | PointOfInstantiation, TSK, Enum, | 
|  | 2729 | MSInfo->getTemplateSpecializationKind(), | 
|  | 2730 | MSInfo->getPointOfInstantiation(), SuppressNew) || | 
|  | 2731 | SuppressNew) | 
|  | 2732 | continue; | 
|  | 2733 |  | 
|  | 2734 | if (Enum->getDefinition()) | 
|  | 2735 | continue; | 
|  | 2736 |  | 
| Richard Smith | 6739a10 | 2016-05-05 00:56:12 +0000 | [diff] [blame] | 2737 | EnumDecl *Pattern = Enum->getTemplateInstantiationPattern(); | 
| Richard Smith | 4b38ded | 2012-03-14 23:13:10 +0000 | [diff] [blame] | 2738 | assert(Pattern && "Missing instantiated-from-template information"); | 
|  | 2739 |  | 
|  | 2740 | if (TSK == TSK_ExplicitInstantiationDefinition) { | 
|  | 2741 | if (!Pattern->getDefinition()) | 
|  | 2742 | continue; | 
|  | 2743 |  | 
|  | 2744 | InstantiateEnum(PointOfInstantiation, Enum, Pattern, TemplateArgs, TSK); | 
|  | 2745 | } else { | 
|  | 2746 | MSInfo->setTemplateSpecializationKind(TSK); | 
|  | 2747 | MSInfo->setPointOfInstantiation(PointOfInstantiation); | 
|  | 2748 | } | 
| Reid Kleckner | d60b82f | 2014-11-17 23:36:45 +0000 | [diff] [blame] | 2749 | } else if (auto *Field = dyn_cast<FieldDecl>(D)) { | 
|  | 2750 | // No need to instantiate in-class initializers during explicit | 
|  | 2751 | // instantiation. | 
|  | 2752 | if (Field->hasInClassInitializer() && TSK == TSK_ImplicitInstantiation) { | 
|  | 2753 | CXXRecordDecl *ClassPattern = | 
|  | 2754 | Instantiation->getTemplateInstantiationPattern(); | 
|  | 2755 | DeclContext::lookup_result Lookup = | 
|  | 2756 | ClassPattern->lookup(Field->getDeclName()); | 
| David Majnemer | 76a2562 | 2016-06-09 05:26:56 +0000 | [diff] [blame] | 2757 | FieldDecl *Pattern = cast<FieldDecl>(Lookup.front()); | 
| Reid Kleckner | d60b82f | 2014-11-17 23:36:45 +0000 | [diff] [blame] | 2758 | InstantiateInClassInitializer(PointOfInstantiation, Field, Pattern, | 
|  | 2759 | TemplateArgs); | 
|  | 2760 | } | 
| Douglas Gregor | bbbb02d | 2009-05-13 20:28:22 +0000 | [diff] [blame] | 2761 | } | 
|  | 2762 | } | 
|  | 2763 | } | 
|  | 2764 |  | 
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2765 | /// Instantiate the definitions of all of the members of the | 
| Douglas Gregor | bbbb02d | 2009-05-13 20:28:22 +0000 | [diff] [blame] | 2766 | /// given class template specialization, which was named as part of an | 
|  | 2767 | /// explicit instantiation. | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2768 | void | 
| Douglas Gregor | 34ec2ef | 2009-09-04 22:48:11 +0000 | [diff] [blame] | 2769 | Sema::InstantiateClassTemplateSpecializationMembers( | 
| Douglas Gregor | bbbb02d | 2009-05-13 20:28:22 +0000 | [diff] [blame] | 2770 | SourceLocation PointOfInstantiation, | 
| Douglas Gregor | 34ec2ef | 2009-09-04 22:48:11 +0000 | [diff] [blame] | 2771 | ClassTemplateSpecializationDecl *ClassTemplateSpec, | 
|  | 2772 | TemplateSpecializationKind TSK) { | 
| Douglas Gregor | bbbb02d | 2009-05-13 20:28:22 +0000 | [diff] [blame] | 2773 | // C++0x [temp.explicit]p7: | 
|  | 2774 | //   An explicit instantiation that names a class template | 
|  | 2775 | //   specialization is an explicit instantion of the same kind | 
|  | 2776 | //   (declaration or definition) of each of its members (not | 
|  | 2777 | //   including members inherited from base classes) that has not | 
|  | 2778 | //   been previously explicitly specialized in the translation unit | 
|  | 2779 | //   containing the explicit instantiation, except as described | 
|  | 2780 | //   below. | 
|  | 2781 | InstantiateClassMembers(PointOfInstantiation, ClassTemplateSpec, | 
| Douglas Gregor | 34ec2ef | 2009-09-04 22:48:11 +0000 | [diff] [blame] | 2782 | getTemplateInstantiationArgs(ClassTemplateSpec), | 
|  | 2783 | TSK); | 
| Douglas Gregor | bbbb02d | 2009-05-13 20:28:22 +0000 | [diff] [blame] | 2784 | } | 
|  | 2785 |  | 
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2786 | StmtResult | 
| Douglas Gregor | 01afeef | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 2787 | Sema::SubstStmt(Stmt *S, const MultiLevelTemplateArgumentList &TemplateArgs) { | 
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2788 | if (!S) | 
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2789 | return S; | 
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2790 |  | 
|  | 2791 | TemplateInstantiator Instantiator(*this, TemplateArgs, | 
|  | 2792 | SourceLocation(), | 
|  | 2793 | DeclarationName()); | 
|  | 2794 | return Instantiator.TransformStmt(S); | 
|  | 2795 | } | 
|  | 2796 |  | 
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2797 | ExprResult | 
| Douglas Gregor | 01afeef | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 2798 | Sema::SubstExpr(Expr *E, const MultiLevelTemplateArgumentList &TemplateArgs) { | 
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2799 | if (!E) | 
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2800 | return E; | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2801 |  | 
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2802 | TemplateInstantiator Instantiator(*this, TemplateArgs, | 
|  | 2803 | SourceLocation(), | 
|  | 2804 | DeclarationName()); | 
|  | 2805 | return Instantiator.TransformExpr(E); | 
|  | 2806 | } | 
|  | 2807 |  | 
| Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2808 | ExprResult Sema::SubstInitializer(Expr *Init, | 
|  | 2809 | const MultiLevelTemplateArgumentList &TemplateArgs, | 
|  | 2810 | bool CXXDirectInit) { | 
|  | 2811 | TemplateInstantiator Instantiator(*this, TemplateArgs, | 
|  | 2812 | SourceLocation(), | 
|  | 2813 | DeclarationName()); | 
|  | 2814 | return Instantiator.TransformInitializer(Init, CXXDirectInit); | 
|  | 2815 | } | 
|  | 2816 |  | 
| Craig Topper | 99d2353 | 2015-12-24 23:58:29 +0000 | [diff] [blame] | 2817 | bool Sema::SubstExprs(ArrayRef<Expr *> Exprs, bool IsCall, | 
| Douglas Gregor | 2cd32a0 | 2011-01-07 19:35:17 +0000 | [diff] [blame] | 2818 | const MultiLevelTemplateArgumentList &TemplateArgs, | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2819 | SmallVectorImpl<Expr *> &Outputs) { | 
| Craig Topper | 99d2353 | 2015-12-24 23:58:29 +0000 | [diff] [blame] | 2820 | if (Exprs.empty()) | 
| Douglas Gregor | 2cd32a0 | 2011-01-07 19:35:17 +0000 | [diff] [blame] | 2821 | return false; | 
| Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2822 |  | 
| Douglas Gregor | 2cd32a0 | 2011-01-07 19:35:17 +0000 | [diff] [blame] | 2823 | TemplateInstantiator Instantiator(*this, TemplateArgs, | 
|  | 2824 | SourceLocation(), | 
|  | 2825 | DeclarationName()); | 
| Craig Topper | 99d2353 | 2015-12-24 23:58:29 +0000 | [diff] [blame] | 2826 | return Instantiator.TransformExprs(Exprs.data(), Exprs.size(), | 
|  | 2827 | IsCall, Outputs); | 
| Douglas Gregor | 2cd32a0 | 2011-01-07 19:35:17 +0000 | [diff] [blame] | 2828 | } | 
|  | 2829 |  | 
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2830 | NestedNameSpecifierLoc | 
|  | 2831 | Sema::SubstNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2832 | const MultiLevelTemplateArgumentList &TemplateArgs) { | 
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2833 | if (!NNS) | 
|  | 2834 | return NestedNameSpecifierLoc(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2835 |  | 
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2836 | TemplateInstantiator Instantiator(*this, TemplateArgs, NNS.getBeginLoc(), | 
|  | 2837 | DeclarationName()); | 
|  | 2838 | return Instantiator.TransformNestedNameSpecifierLoc(NNS); | 
|  | 2839 | } | 
|  | 2840 |  | 
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2841 | /// Do template substitution on declaration name info. | 
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2842 | DeclarationNameInfo | 
|  | 2843 | Sema::SubstDeclarationNameInfo(const DeclarationNameInfo &NameInfo, | 
|  | 2844 | const MultiLevelTemplateArgumentList &TemplateArgs) { | 
|  | 2845 | TemplateInstantiator Instantiator(*this, TemplateArgs, NameInfo.getLoc(), | 
|  | 2846 | NameInfo.getName()); | 
|  | 2847 | return Instantiator.TransformDeclarationNameInfo(NameInfo); | 
|  | 2848 | } | 
|  | 2849 |  | 
| Douglas Gregor | aa59489 | 2009-03-31 18:38:02 +0000 | [diff] [blame] | 2850 | TemplateName | 
| Douglas Gregor | df846d1 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 2851 | Sema::SubstTemplateName(NestedNameSpecifierLoc QualifierLoc, | 
|  | 2852 | TemplateName Name, SourceLocation Loc, | 
| Douglas Gregor | 01afeef | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 2853 | const MultiLevelTemplateArgumentList &TemplateArgs) { | 
| Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2854 | TemplateInstantiator Instantiator(*this, TemplateArgs, Loc, | 
|  | 2855 | DeclarationName()); | 
| Douglas Gregor | df846d1 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 2856 | CXXScopeSpec SS; | 
|  | 2857 | SS.Adopt(QualifierLoc); | 
|  | 2858 | return Instantiator.TransformTemplateName(SS, Name, Loc); | 
| Douglas Gregor | aa59489 | 2009-03-31 18:38:02 +0000 | [diff] [blame] | 2859 | } | 
| Douglas Gregor | c43620d | 2009-06-11 00:06:24 +0000 | [diff] [blame] | 2860 |  | 
| Douglas Gregor | 0f3feb4 | 2010-12-22 21:19:48 +0000 | [diff] [blame] | 2861 | bool Sema::Subst(const TemplateArgumentLoc *Args, unsigned NumArgs, | 
|  | 2862 | TemplateArgumentListInfo &Result, | 
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2863 | const MultiLevelTemplateArgumentList &TemplateArgs) { | 
| Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2864 | TemplateInstantiator Instantiator(*this, TemplateArgs, SourceLocation(), | 
|  | 2865 | DeclarationName()); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2866 |  | 
| Douglas Gregor | 0f3feb4 | 2010-12-22 21:19:48 +0000 | [diff] [blame] | 2867 | return Instantiator.TransformTemplateArguments(Args, NumArgs, Result); | 
| Douglas Gregor | c43620d | 2009-06-11 00:06:24 +0000 | [diff] [blame] | 2868 | } | 
| Douglas Gregor | 14cf752 | 2010-04-30 18:55:50 +0000 | [diff] [blame] | 2869 |  | 
| Richard Smith | 70b1304 | 2015-01-09 01:19:56 +0000 | [diff] [blame] | 2870 | static const Decl *getCanonicalParmVarDecl(const Decl *D) { | 
| DeLesley Hutchins | f39c0c2 | 2012-09-26 17:57:31 +0000 | [diff] [blame] | 2871 | // When storing ParmVarDecls in the local instantiation scope, we always | 
|  | 2872 | // want to use the ParmVarDecl from the canonical function declaration, | 
|  | 2873 | // since the map is then valid for any redeclaration or definition of that | 
|  | 2874 | // function. | 
|  | 2875 | if (const ParmVarDecl *PV = dyn_cast<ParmVarDecl>(D)) { | 
|  | 2876 | if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(PV->getDeclContext())) { | 
|  | 2877 | unsigned i = PV->getFunctionScopeIndex(); | 
| Richard Smith | 70b1304 | 2015-01-09 01:19:56 +0000 | [diff] [blame] | 2878 | // This parameter might be from a freestanding function type within the | 
|  | 2879 | // function and isn't necessarily referring to one of FD's parameters. | 
|  | 2880 | if (FD->getParamDecl(i) == PV) | 
|  | 2881 | return FD->getCanonicalDecl()->getParamDecl(i); | 
| DeLesley Hutchins | f39c0c2 | 2012-09-26 17:57:31 +0000 | [diff] [blame] | 2882 | } | 
|  | 2883 | } | 
|  | 2884 | return D; | 
|  | 2885 | } | 
|  | 2886 |  | 
|  | 2887 |  | 
| Douglas Gregor | f301011 | 2011-01-07 16:43:16 +0000 | [diff] [blame] | 2888 | llvm::PointerUnion<Decl *, LocalInstantiationScope::DeclArgumentPack *> * | 
|  | 2889 | LocalInstantiationScope::findInstantiationOf(const Decl *D) { | 
| DeLesley Hutchins | f39c0c2 | 2012-09-26 17:57:31 +0000 | [diff] [blame] | 2890 | D = getCanonicalParmVarDecl(D); | 
| Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 2891 | for (LocalInstantiationScope *Current = this; Current; | 
| Douglas Gregor | 14cf752 | 2010-04-30 18:55:50 +0000 | [diff] [blame] | 2892 | Current = Current->Outer) { | 
| Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 2893 |  | 
| Douglas Gregor | 14cf752 | 2010-04-30 18:55:50 +0000 | [diff] [blame] | 2894 | // Check if we found something within this scope. | 
| Douglas Gregor | e9fc8dc | 2010-12-21 21:22:51 +0000 | [diff] [blame] | 2895 | const Decl *CheckD = D; | 
|  | 2896 | do { | 
| Douglas Gregor | f301011 | 2011-01-07 16:43:16 +0000 | [diff] [blame] | 2897 | LocalDeclsMap::iterator Found = Current->LocalDecls.find(CheckD); | 
| Douglas Gregor | e9fc8dc | 2010-12-21 21:22:51 +0000 | [diff] [blame] | 2898 | if (Found != Current->LocalDecls.end()) | 
| Douglas Gregor | f301011 | 2011-01-07 16:43:16 +0000 | [diff] [blame] | 2899 | return &Found->second; | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2900 |  | 
| Douglas Gregor | e9fc8dc | 2010-12-21 21:22:51 +0000 | [diff] [blame] | 2901 | // If this is a tag declaration, it's possible that we need to look for | 
|  | 2902 | // a previous declaration. | 
|  | 2903 | if (const TagDecl *Tag = dyn_cast<TagDecl>(CheckD)) | 
| Douglas Gregor | ec9fd13 | 2012-01-14 16:38:05 +0000 | [diff] [blame] | 2904 | CheckD = Tag->getPreviousDecl(); | 
| Douglas Gregor | e9fc8dc | 2010-12-21 21:22:51 +0000 | [diff] [blame] | 2905 | else | 
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 2906 | CheckD = nullptr; | 
| Douglas Gregor | e9fc8dc | 2010-12-21 21:22:51 +0000 | [diff] [blame] | 2907 | } while (CheckD); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2908 |  | 
|  | 2909 | // If we aren't combined with our outer scope, we're done. | 
| Douglas Gregor | 14cf752 | 2010-04-30 18:55:50 +0000 | [diff] [blame] | 2910 | if (!Current->CombineWithOuterScope) | 
|  | 2911 | break; | 
|  | 2912 | } | 
| Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 2913 |  | 
| Serge Pavlov | 7cd8f60 | 2013-07-15 06:14:07 +0000 | [diff] [blame] | 2914 | // If we're performing a partial substitution during template argument | 
|  | 2915 | // deduction, we may not have values for template parameters yet. | 
|  | 2916 | if (isa<NonTypeTemplateParmDecl>(D) || isa<TemplateTypeParmDecl>(D) || | 
|  | 2917 | isa<TemplateTemplateParmDecl>(D)) | 
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 2918 | return nullptr; | 
| Serge Pavlov | 7cd8f60 | 2013-07-15 06:14:07 +0000 | [diff] [blame] | 2919 |  | 
| Serge Pavlov | e7ad831 | 2015-05-15 10:10:28 +0000 | [diff] [blame] | 2920 | // Local types referenced prior to definition may require instantiation. | 
|  | 2921 | if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(D)) | 
|  | 2922 | if (RD->isLocalClass()) | 
|  | 2923 | return nullptr; | 
|  | 2924 |  | 
|  | 2925 | // Enumeration types referenced prior to definition may appear as a result of | 
|  | 2926 | // error recovery. | 
|  | 2927 | if (isa<EnumDecl>(D)) | 
| Serge Pavlov | 4c51174 | 2015-05-04 16:44:39 +0000 | [diff] [blame] | 2928 | return nullptr; | 
|  | 2929 |  | 
| Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 2930 | // If we didn't find the decl, then we either have a sema bug, or we have a | 
|  | 2931 | // forward reference to a label declaration.  Return null to indicate that | 
|  | 2932 | // we have an uninstantiated label. | 
|  | 2933 | assert(isa<LabelDecl>(D) && "declaration not instantiated in this scope"); | 
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 2934 | return nullptr; | 
| Douglas Gregor | 14cf752 | 2010-04-30 18:55:50 +0000 | [diff] [blame] | 2935 | } | 
|  | 2936 |  | 
| John McCall | 19c1bfd | 2010-08-25 05:32:35 +0000 | [diff] [blame] | 2937 | void LocalInstantiationScope::InstantiatedLocal(const Decl *D, Decl *Inst) { | 
| DeLesley Hutchins | f39c0c2 | 2012-09-26 17:57:31 +0000 | [diff] [blame] | 2938 | D = getCanonicalParmVarDecl(D); | 
| Douglas Gregor | f301011 | 2011-01-07 16:43:16 +0000 | [diff] [blame] | 2939 | llvm::PointerUnion<Decl *, DeclArgumentPack *> &Stored = LocalDecls[D]; | 
| Richard Smith | 70b1304 | 2015-01-09 01:19:56 +0000 | [diff] [blame] | 2940 | if (Stored.isNull()) { | 
|  | 2941 | #ifndef NDEBUG | 
|  | 2942 | // It should not be present in any surrounding scope either. | 
|  | 2943 | LocalInstantiationScope *Current = this; | 
|  | 2944 | while (Current->CombineWithOuterScope && Current->Outer) { | 
|  | 2945 | Current = Current->Outer; | 
|  | 2946 | assert(Current->LocalDecls.find(D) == Current->LocalDecls.end() && | 
|  | 2947 | "Instantiated local in inner and outer scopes"); | 
|  | 2948 | } | 
|  | 2949 | #endif | 
| Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 2950 | Stored = Inst; | 
| Richard Smith | 70b1304 | 2015-01-09 01:19:56 +0000 | [diff] [blame] | 2951 | } else if (DeclArgumentPack *Pack = Stored.dyn_cast<DeclArgumentPack *>()) { | 
| James Y Knight | 48fefa3 | 2015-09-30 14:04:23 +0000 | [diff] [blame] | 2952 | Pack->push_back(cast<ParmVarDecl>(Inst)); | 
| Richard Smith | 70b1304 | 2015-01-09 01:19:56 +0000 | [diff] [blame] | 2953 | } else { | 
| Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 2954 | assert(Stored.get<Decl *>() == Inst && "Already instantiated this local"); | 
| Richard Smith | 70b1304 | 2015-01-09 01:19:56 +0000 | [diff] [blame] | 2955 | } | 
| Douglas Gregor | 14cf752 | 2010-04-30 18:55:50 +0000 | [diff] [blame] | 2956 | } | 
| Douglas Gregor | f301011 | 2011-01-07 16:43:16 +0000 | [diff] [blame] | 2957 |  | 
| James Y Knight | 48fefa3 | 2015-09-30 14:04:23 +0000 | [diff] [blame] | 2958 | void LocalInstantiationScope::InstantiatedLocalPackArg(const Decl *D, | 
|  | 2959 | ParmVarDecl *Inst) { | 
| DeLesley Hutchins | f39c0c2 | 2012-09-26 17:57:31 +0000 | [diff] [blame] | 2960 | D = getCanonicalParmVarDecl(D); | 
| Douglas Gregor | f301011 | 2011-01-07 16:43:16 +0000 | [diff] [blame] | 2961 | DeclArgumentPack *Pack = LocalDecls[D].get<DeclArgumentPack *>(); | 
|  | 2962 | Pack->push_back(Inst); | 
|  | 2963 | } | 
|  | 2964 |  | 
|  | 2965 | void LocalInstantiationScope::MakeInstantiatedLocalArgPack(const Decl *D) { | 
| Richard Smith | 70b1304 | 2015-01-09 01:19:56 +0000 | [diff] [blame] | 2966 | #ifndef NDEBUG | 
|  | 2967 | // This should be the first time we've been told about this decl. | 
|  | 2968 | for (LocalInstantiationScope *Current = this; | 
|  | 2969 | Current && Current->CombineWithOuterScope; Current = Current->Outer) | 
|  | 2970 | assert(Current->LocalDecls.find(D) == Current->LocalDecls.end() && | 
|  | 2971 | "Creating local pack after instantiation of local"); | 
|  | 2972 | #endif | 
|  | 2973 |  | 
| DeLesley Hutchins | f39c0c2 | 2012-09-26 17:57:31 +0000 | [diff] [blame] | 2974 | D = getCanonicalParmVarDecl(D); | 
| Douglas Gregor | f301011 | 2011-01-07 16:43:16 +0000 | [diff] [blame] | 2975 | llvm::PointerUnion<Decl *, DeclArgumentPack *> &Stored = LocalDecls[D]; | 
| Douglas Gregor | f301011 | 2011-01-07 16:43:16 +0000 | [diff] [blame] | 2976 | DeclArgumentPack *Pack = new DeclArgumentPack; | 
|  | 2977 | Stored = Pack; | 
|  | 2978 | ArgumentPacks.push_back(Pack); | 
|  | 2979 | } | 
|  | 2980 |  | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2981 | void LocalInstantiationScope::SetPartiallySubstitutedPack(NamedDecl *Pack, | 
| Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 2982 | const TemplateArgument *ExplicitArgs, | 
|  | 2983 | unsigned NumExplicitArgs) { | 
|  | 2984 | assert((!PartiallySubstitutedPack || PartiallySubstitutedPack == Pack) && | 
|  | 2985 | "Already have a partially-substituted pack"); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2986 | assert((!PartiallySubstitutedPack | 
| Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 2987 | || NumArgsInPartiallySubstitutedPack == NumExplicitArgs) && | 
|  | 2988 | "Wrong number of arguments in partially-substituted pack"); | 
|  | 2989 | PartiallySubstitutedPack = Pack; | 
|  | 2990 | ArgsInPartiallySubstitutedPack = ExplicitArgs; | 
|  | 2991 | NumArgsInPartiallySubstitutedPack = NumExplicitArgs; | 
|  | 2992 | } | 
|  | 2993 |  | 
|  | 2994 | NamedDecl *LocalInstantiationScope::getPartiallySubstitutedPack( | 
|  | 2995 | const TemplateArgument **ExplicitArgs, | 
|  | 2996 | unsigned *NumExplicitArgs) const { | 
|  | 2997 | if (ExplicitArgs) | 
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 2998 | *ExplicitArgs = nullptr; | 
| Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 2999 | if (NumExplicitArgs) | 
|  | 3000 | *NumExplicitArgs = 0; | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3001 |  | 
|  | 3002 | for (const LocalInstantiationScope *Current = this; Current; | 
| Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3003 | Current = Current->Outer) { | 
|  | 3004 | if (Current->PartiallySubstitutedPack) { | 
|  | 3005 | if (ExplicitArgs) | 
|  | 3006 | *ExplicitArgs = Current->ArgsInPartiallySubstitutedPack; | 
|  | 3007 | if (NumExplicitArgs) | 
|  | 3008 | *NumExplicitArgs = Current->NumArgsInPartiallySubstitutedPack; | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3009 |  | 
| Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3010 | return Current->PartiallySubstitutedPack; | 
|  | 3011 | } | 
|  | 3012 |  | 
|  | 3013 | if (!Current->CombineWithOuterScope) | 
|  | 3014 | break; | 
|  | 3015 | } | 
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 3016 |  | 
|  | 3017 | return nullptr; | 
| Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3018 | } |