| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | #include "clang/Sema/SemaInternal.h" |
| 13 | #include "TreeTransform.h" |
| 14 | #include "clang/AST/ASTConsumer.h" |
| 15 | #include "clang/AST/ASTContext.h" |
| 16 | #include "clang/AST/ASTLambda.h" |
| 17 | #include "clang/AST/ASTMutationListener.h" |
| 18 | #include "clang/AST/DeclTemplate.h" |
| 19 | #include "clang/AST/Expr.h" |
| 20 | #include "clang/AST/PrettyDeclStackTrace.h" |
| 21 | #include "clang/Basic/LangOptions.h" |
| 22 | #include "clang/Sema/DeclSpec.h" |
| 23 | #include "clang/Sema/Initialization.h" |
| 24 | #include "clang/Sema/Lookup.h" |
| 25 | #include "clang/Sema/Template.h" |
| 26 | #include "clang/Sema/TemplateDeduction.h" |
| 27 | #include "clang/Sema/TemplateInstCallback.h" |
| 28 | |
| 29 | using namespace clang; |
| 30 | using namespace sema; |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | MultiLevelTemplateArgumentList |
| 54 | Sema::getTemplateInstantiationArgs(NamedDecl *D, |
| 55 | const TemplateArgumentList *Innermost, |
| 56 | bool RelativeToPrimary, |
| 57 | const FunctionDecl *Pattern) { |
| 58 | |
| 59 | MultiLevelTemplateArgumentList Result; |
| 60 | |
| 61 | if (Innermost) |
| 62 | Result.addOuterTemplateArguments(Innermost); |
| 63 | |
| 64 | DeclContext *Ctx = dyn_cast<DeclContext>(D); |
| 65 | if (!Ctx) { |
| 66 | Ctx = D->getDeclContext(); |
| 67 | |
| 68 | |
| 69 | if (VarTemplateSpecializationDecl *Spec = |
| 70 | dyn_cast<VarTemplateSpecializationDecl>(D)) { |
| 71 | |
| 72 | if (Spec->getSpecializationKind() == TSK_ExplicitSpecialization && |
| 73 | !isa<VarTemplatePartialSpecializationDecl>(Spec)) |
| 74 | return Result; |
| 75 | |
| 76 | Result.addOuterTemplateArguments(&Spec->getTemplateInstantiationArgs()); |
| 77 | |
| 78 | |
| 79 | |
| 80 | (0) . __assert_fail ("Spec->getSpecializedTemplate() && \"No variable template?\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 80, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Spec->getSpecializedTemplate() && "No variable template?"); |
| 81 | llvm::PointerUnion<VarTemplateDecl*, |
| 82 | VarTemplatePartialSpecializationDecl*> Specialized |
| 83 | = Spec->getSpecializedTemplateOrPartial(); |
| 84 | if (VarTemplatePartialSpecializationDecl *Partial = |
| 85 | Specialized.dyn_cast<VarTemplatePartialSpecializationDecl *>()) { |
| 86 | if (Partial->isMemberSpecialization()) |
| 87 | return Result; |
| 88 | } else { |
| 89 | VarTemplateDecl *Tmpl = Specialized.get<VarTemplateDecl *>(); |
| 90 | if (Tmpl->isMemberSpecialization()) |
| 91 | return Result; |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 | if (Ctx->isTranslationUnit()) { |
| 102 | if (TemplateTemplateParmDecl *TTP |
| 103 | = dyn_cast<TemplateTemplateParmDecl>(D)) { |
| 104 | for (unsigned I = 0, N = TTP->getDepth() + 1; I != N; ++I) |
| 105 | Result.addOuterTemplateArguments(None); |
| 106 | return Result; |
| 107 | } |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | while (!Ctx->isFileContext()) { |
| 112 | |
| 113 | if (ClassTemplateSpecializationDecl *Spec |
| 114 | = dyn_cast<ClassTemplateSpecializationDecl>(Ctx)) { |
| 115 | |
| 116 | if (Spec->getSpecializationKind() == TSK_ExplicitSpecialization && |
| 117 | !isa<ClassTemplatePartialSpecializationDecl>(Spec)) |
| 118 | break; |
| 119 | |
| 120 | Result.addOuterTemplateArguments(&Spec->getTemplateInstantiationArgs()); |
| 121 | |
| 122 | |
| 123 | |
| 124 | (0) . __assert_fail ("Spec->getSpecializedTemplate() && \"No class template?\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 124, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Spec->getSpecializedTemplate() && "No class template?"); |
| 125 | if (Spec->getSpecializedTemplate()->isMemberSpecialization()) |
| 126 | break; |
| 127 | } |
| 128 | |
| 129 | else if (FunctionDecl *Function = dyn_cast<FunctionDecl>(Ctx)) { |
| 130 | if (!RelativeToPrimary && |
| 131 | (Function->getTemplateSpecializationKind() == |
| 132 | TSK_ExplicitSpecialization && |
| 133 | !Function->getClassScopeSpecializationPattern())) |
| 134 | break; |
| 135 | |
| 136 | if (const TemplateArgumentList *TemplateArgs |
| 137 | = Function->getTemplateSpecializationArgs()) { |
| 138 | |
| 139 | Result.addOuterTemplateArguments(TemplateArgs); |
| 140 | |
| 141 | |
| 142 | |
| 143 | (0) . __assert_fail ("Function->getPrimaryTemplate() && \"No function template?\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 143, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Function->getPrimaryTemplate() && "No function template?"); |
| 144 | if (Function->getPrimaryTemplate()->isMemberSpecialization()) |
| 145 | break; |
| 146 | |
| 147 | |
| 148 | if (isGenericLambdaCallOperatorSpecialization(Function)) |
| 149 | break; |
| 150 | |
| 151 | } else if (FunctionTemplateDecl *FunTmpl |
| 152 | = Function->getDescribedFunctionTemplate()) { |
| 153 | |
| 154 | Result.addOuterTemplateArguments(FunTmpl->getInjectedTemplateArgs()); |
| 155 | } |
| 156 | |
| 157 | |
| 158 | |
| 159 | |
| 160 | |
| 161 | if (Function->getFriendObjectKind() && |
| 162 | Function->getDeclContext()->isFileContext() && |
| 163 | (!Pattern || !Pattern->getLexicalDeclContext()->isFileContext())) { |
| 164 | Ctx = Function->getLexicalDeclContext(); |
| 165 | RelativeToPrimary = false; |
| 166 | continue; |
| 167 | } |
| 168 | } else if (CXXRecordDecl *Rec = dyn_cast<CXXRecordDecl>(Ctx)) { |
| 169 | if (ClassTemplateDecl *ClassTemplate = Rec->getDescribedClassTemplate()) { |
| 170 | QualType T = ClassTemplate->getInjectedClassNameSpecialization(); |
| 171 | const TemplateSpecializationType *TST = |
| 172 | cast<TemplateSpecializationType>(Context.getCanonicalType(T)); |
| 173 | Result.addOuterTemplateArguments( |
| 174 | llvm::makeArrayRef(TST->getArgs(), TST->getNumArgs())); |
| 175 | if (ClassTemplate->isMemberSpecialization()) |
| 176 | break; |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | Ctx = Ctx->getParent(); |
| 181 | RelativeToPrimary = false; |
| 182 | } |
| 183 | |
| 184 | return Result; |
| 185 | } |
| 186 | |
| 187 | bool Sema::CodeSynthesisContext::isInstantiationRecord() const { |
| 188 | switch (Kind) { |
| 189 | case TemplateInstantiation: |
| 190 | case ExceptionSpecInstantiation: |
| 191 | case DefaultTemplateArgumentInstantiation: |
| 192 | case DefaultFunctionArgumentInstantiation: |
| 193 | case ExplicitTemplateArgumentSubstitution: |
| 194 | case DeducedTemplateArgumentSubstitution: |
| 195 | case PriorTemplateArgumentSubstitution: |
| 196 | return true; |
| 197 | |
| 198 | case DefaultTemplateArgumentChecking: |
| 199 | case DeclaringSpecialMember: |
| 200 | case DefiningSynthesizedFunction: |
| 201 | case ExceptionSpecEvaluation: |
| 202 | return false; |
| 203 | |
| 204 | |
| 205 | case Memoization: |
| 206 | break; |
| 207 | } |
| 208 | |
| 209 | llvm_unreachable("Invalid SynthesisKind!"); |
| 210 | } |
| 211 | |
| 212 | Sema::InstantiatingTemplate::InstantiatingTemplate( |
| 213 | Sema &SemaRef, CodeSynthesisContext::SynthesisKind Kind, |
| 214 | SourceLocation PointOfInstantiation, SourceRange InstantiationRange, |
| 215 | Decl *Entity, NamedDecl *Template, ArrayRef<TemplateArgument> TemplateArgs, |
| 216 | sema::TemplateDeductionInfo *DeductionInfo) |
| 217 | : SemaRef(SemaRef) { |
| 218 | |
| 219 | |
| 220 | |
| 221 | if (SemaRef.Diags.hasFatalErrorOccurred() && |
| 222 | SemaRef.Diags.hasUncompilableErrorOccurred()) { |
| 223 | Invalid = true; |
| 224 | return; |
| 225 | } |
| 226 | Invalid = CheckInstantiationDepth(PointOfInstantiation, InstantiationRange); |
| 227 | if (!Invalid) { |
| 228 | CodeSynthesisContext Inst; |
| 229 | Inst.Kind = Kind; |
| 230 | Inst.PointOfInstantiation = PointOfInstantiation; |
| 231 | Inst.Entity = Entity; |
| 232 | Inst.Template = Template; |
| 233 | Inst.TemplateArgs = TemplateArgs.data(); |
| 234 | Inst.NumTemplateArgs = TemplateArgs.size(); |
| 235 | Inst.DeductionInfo = DeductionInfo; |
| 236 | Inst.InstantiationRange = InstantiationRange; |
| 237 | SemaRef.pushCodeSynthesisContext(Inst); |
| 238 | |
| 239 | AlreadyInstantiating = |
| 240 | !SemaRef.InstantiatingSpecializations |
| 241 | .insert(std::make_pair(Inst.Entity->getCanonicalDecl(), Inst.Kind)) |
| 242 | .second; |
| 243 | atTemplateBegin(SemaRef.TemplateInstCallbacks, SemaRef, Inst); |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | Sema::InstantiatingTemplate::InstantiatingTemplate( |
| 248 | Sema &SemaRef, SourceLocation PointOfInstantiation, Decl *Entity, |
| 249 | SourceRange InstantiationRange) |
| 250 | : InstantiatingTemplate(SemaRef, |
| 251 | CodeSynthesisContext::TemplateInstantiation, |
| 252 | PointOfInstantiation, InstantiationRange, Entity) {} |
| 253 | |
| 254 | Sema::InstantiatingTemplate::InstantiatingTemplate( |
| 255 | Sema &SemaRef, SourceLocation PointOfInstantiation, FunctionDecl *Entity, |
| 256 | ExceptionSpecification, SourceRange InstantiationRange) |
| 257 | : InstantiatingTemplate( |
| 258 | SemaRef, CodeSynthesisContext::ExceptionSpecInstantiation, |
| 259 | PointOfInstantiation, InstantiationRange, Entity) {} |
| 260 | |
| 261 | Sema::InstantiatingTemplate::InstantiatingTemplate( |
| 262 | Sema &SemaRef, SourceLocation PointOfInstantiation, TemplateParameter Param, |
| 263 | TemplateDecl *Template, ArrayRef<TemplateArgument> TemplateArgs, |
| 264 | SourceRange InstantiationRange) |
| 265 | : InstantiatingTemplate( |
| 266 | SemaRef, |
| 267 | CodeSynthesisContext::DefaultTemplateArgumentInstantiation, |
| 268 | PointOfInstantiation, InstantiationRange, getAsNamedDecl(Param), |
| 269 | Template, TemplateArgs) {} |
| 270 | |
| 271 | Sema::InstantiatingTemplate::InstantiatingTemplate( |
| 272 | Sema &SemaRef, SourceLocation PointOfInstantiation, |
| 273 | FunctionTemplateDecl *FunctionTemplate, |
| 274 | ArrayRef<TemplateArgument> TemplateArgs, |
| 275 | CodeSynthesisContext::SynthesisKind Kind, |
| 276 | sema::TemplateDeductionInfo &DeductionInfo, SourceRange InstantiationRange) |
| 277 | : InstantiatingTemplate(SemaRef, Kind, PointOfInstantiation, |
| 278 | InstantiationRange, FunctionTemplate, nullptr, |
| 279 | TemplateArgs, &DeductionInfo) { |
| 280 | assert( |
| 281 | Kind == CodeSynthesisContext::ExplicitTemplateArgumentSubstitution || |
| 282 | Kind == CodeSynthesisContext::DeducedTemplateArgumentSubstitution); |
| 283 | } |
| 284 | |
| 285 | Sema::InstantiatingTemplate::InstantiatingTemplate( |
| 286 | Sema &SemaRef, SourceLocation PointOfInstantiation, |
| 287 | TemplateDecl *Template, |
| 288 | ArrayRef<TemplateArgument> TemplateArgs, |
| 289 | sema::TemplateDeductionInfo &DeductionInfo, SourceRange InstantiationRange) |
| 290 | : InstantiatingTemplate( |
| 291 | SemaRef, |
| 292 | CodeSynthesisContext::DeducedTemplateArgumentSubstitution, |
| 293 | PointOfInstantiation, InstantiationRange, Template, nullptr, |
| 294 | TemplateArgs, &DeductionInfo) {} |
| 295 | |
| 296 | Sema::InstantiatingTemplate::InstantiatingTemplate( |
| 297 | Sema &SemaRef, SourceLocation PointOfInstantiation, |
| 298 | ClassTemplatePartialSpecializationDecl *PartialSpec, |
| 299 | ArrayRef<TemplateArgument> TemplateArgs, |
| 300 | sema::TemplateDeductionInfo &DeductionInfo, SourceRange InstantiationRange) |
| 301 | : InstantiatingTemplate( |
| 302 | SemaRef, |
| 303 | CodeSynthesisContext::DeducedTemplateArgumentSubstitution, |
| 304 | PointOfInstantiation, InstantiationRange, PartialSpec, nullptr, |
| 305 | TemplateArgs, &DeductionInfo) {} |
| 306 | |
| 307 | Sema::InstantiatingTemplate::InstantiatingTemplate( |
| 308 | Sema &SemaRef, SourceLocation PointOfInstantiation, |
| 309 | VarTemplatePartialSpecializationDecl *PartialSpec, |
| 310 | ArrayRef<TemplateArgument> TemplateArgs, |
| 311 | sema::TemplateDeductionInfo &DeductionInfo, SourceRange InstantiationRange) |
| 312 | : InstantiatingTemplate( |
| 313 | SemaRef, |
| 314 | CodeSynthesisContext::DeducedTemplateArgumentSubstitution, |
| 315 | PointOfInstantiation, InstantiationRange, PartialSpec, nullptr, |
| 316 | TemplateArgs, &DeductionInfo) {} |
| 317 | |
| 318 | Sema::InstantiatingTemplate::InstantiatingTemplate( |
| 319 | Sema &SemaRef, SourceLocation PointOfInstantiation, ParmVarDecl *Param, |
| 320 | ArrayRef<TemplateArgument> TemplateArgs, SourceRange InstantiationRange) |
| 321 | : InstantiatingTemplate( |
| 322 | SemaRef, |
| 323 | CodeSynthesisContext::DefaultFunctionArgumentInstantiation, |
| 324 | PointOfInstantiation, InstantiationRange, Param, nullptr, |
| 325 | TemplateArgs) {} |
| 326 | |
| 327 | Sema::InstantiatingTemplate::InstantiatingTemplate( |
| 328 | Sema &SemaRef, SourceLocation PointOfInstantiation, NamedDecl *Template, |
| 329 | NonTypeTemplateParmDecl *Param, ArrayRef<TemplateArgument> TemplateArgs, |
| 330 | SourceRange InstantiationRange) |
| 331 | : InstantiatingTemplate( |
| 332 | SemaRef, |
| 333 | CodeSynthesisContext::PriorTemplateArgumentSubstitution, |
| 334 | PointOfInstantiation, InstantiationRange, Param, Template, |
| 335 | TemplateArgs) {} |
| 336 | |
| 337 | Sema::InstantiatingTemplate::InstantiatingTemplate( |
| 338 | Sema &SemaRef, SourceLocation PointOfInstantiation, NamedDecl *Template, |
| 339 | TemplateTemplateParmDecl *Param, ArrayRef<TemplateArgument> TemplateArgs, |
| 340 | SourceRange InstantiationRange) |
| 341 | : InstantiatingTemplate( |
| 342 | SemaRef, |
| 343 | CodeSynthesisContext::PriorTemplateArgumentSubstitution, |
| 344 | PointOfInstantiation, InstantiationRange, Param, Template, |
| 345 | TemplateArgs) {} |
| 346 | |
| 347 | Sema::InstantiatingTemplate::InstantiatingTemplate( |
| 348 | Sema &SemaRef, SourceLocation PointOfInstantiation, TemplateDecl *Template, |
| 349 | NamedDecl *Param, ArrayRef<TemplateArgument> TemplateArgs, |
| 350 | SourceRange InstantiationRange) |
| 351 | : InstantiatingTemplate( |
| 352 | SemaRef, CodeSynthesisContext::DefaultTemplateArgumentChecking, |
| 353 | PointOfInstantiation, InstantiationRange, Param, Template, |
| 354 | TemplateArgs) {} |
| 355 | |
| 356 | void Sema::pushCodeSynthesisContext(CodeSynthesisContext Ctx) { |
| 357 | Ctx.SavedInNonInstantiationSFINAEContext = InNonInstantiationSFINAEContext; |
| 358 | InNonInstantiationSFINAEContext = false; |
| 359 | |
| 360 | CodeSynthesisContexts.push_back(Ctx); |
| 361 | |
| 362 | if (!Ctx.isInstantiationRecord()) |
| 363 | ++NonInstantiationEntries; |
| 364 | } |
| 365 | |
| 366 | void Sema::popCodeSynthesisContext() { |
| 367 | auto &Active = CodeSynthesisContexts.back(); |
| 368 | if (!Active.isInstantiationRecord()) { |
| 369 | 0", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 369, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(NonInstantiationEntries > 0); |
| 370 | --NonInstantiationEntries; |
| 371 | } |
| 372 | |
| 373 | InNonInstantiationSFINAEContext = Active.SavedInNonInstantiationSFINAEContext; |
| 374 | |
| 375 | |
| 376 | (0) . __assert_fail ("CodeSynthesisContexts.size() >= CodeSynthesisContextLookupModules.size() && \"forgot to remove a lookup module for a template instantiation\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 378, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(CodeSynthesisContexts.size() >= |
| 377 | (0) . __assert_fail ("CodeSynthesisContexts.size() >= CodeSynthesisContextLookupModules.size() && \"forgot to remove a lookup module for a template instantiation\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 378, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> CodeSynthesisContextLookupModules.size() && |
| 378 | (0) . __assert_fail ("CodeSynthesisContexts.size() >= CodeSynthesisContextLookupModules.size() && \"forgot to remove a lookup module for a template instantiation\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 378, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "forgot to remove a lookup module for a template instantiation"); |
| 379 | if (CodeSynthesisContexts.size() == |
| 380 | CodeSynthesisContextLookupModules.size()) { |
| 381 | if (Module *M = CodeSynthesisContextLookupModules.back()) |
| 382 | LookupModulesCache.erase(M); |
| 383 | CodeSynthesisContextLookupModules.pop_back(); |
| 384 | } |
| 385 | |
| 386 | |
| 387 | |
| 388 | if (CodeSynthesisContexts.size() == |
| 389 | LastEmittedCodeSynthesisContextDepth) |
| 390 | LastEmittedCodeSynthesisContextDepth = 0; |
| 391 | |
| 392 | CodeSynthesisContexts.pop_back(); |
| 393 | } |
| 394 | |
| 395 | void Sema::InstantiatingTemplate::Clear() { |
| 396 | if (!Invalid) { |
| 397 | if (!AlreadyInstantiating) { |
| 398 | auto &Active = SemaRef.CodeSynthesisContexts.back(); |
| 399 | SemaRef.InstantiatingSpecializations.erase( |
| 400 | std::make_pair(Active.Entity, Active.Kind)); |
| 401 | } |
| 402 | |
| 403 | atTemplateEnd(SemaRef.TemplateInstCallbacks, SemaRef, |
| 404 | SemaRef.CodeSynthesisContexts.back()); |
| 405 | |
| 406 | SemaRef.popCodeSynthesisContext(); |
| 407 | Invalid = true; |
| 408 | } |
| 409 | } |
| 410 | |
| 411 | bool Sema::InstantiatingTemplate::CheckInstantiationDepth( |
| 412 | SourceLocation PointOfInstantiation, |
| 413 | SourceRange InstantiationRange) { |
| 414 | assert(SemaRef.NonInstantiationEntries <= |
| 415 | SemaRef.CodeSynthesisContexts.size()); |
| 416 | if ((SemaRef.CodeSynthesisContexts.size() - |
| 417 | SemaRef.NonInstantiationEntries) |
| 418 | <= SemaRef.getLangOpts().InstantiationDepth) |
| 419 | return false; |
| 420 | |
| 421 | SemaRef.Diag(PointOfInstantiation, |
| 422 | diag::err_template_recursion_depth_exceeded) |
| 423 | << SemaRef.getLangOpts().InstantiationDepth |
| 424 | << InstantiationRange; |
| 425 | SemaRef.Diag(PointOfInstantiation, diag::note_template_recursion_depth) |
| 426 | << SemaRef.getLangOpts().InstantiationDepth; |
| 427 | return true; |
| 428 | } |
| 429 | |
| 430 | |
| 431 | |
| 432 | void Sema::PrintInstantiationStack() { |
| 433 | |
| 434 | unsigned SkipStart = CodeSynthesisContexts.size(), SkipEnd = SkipStart; |
| 435 | unsigned Limit = Diags.getTemplateBacktraceLimit(); |
| 436 | if (Limit && Limit < CodeSynthesisContexts.size()) { |
| 437 | SkipStart = Limit / 2 + Limit % 2; |
| 438 | SkipEnd = CodeSynthesisContexts.size() - Limit / 2; |
| 439 | } |
| 440 | |
| 441 | |
| 442 | unsigned InstantiationIdx = 0; |
| 443 | for (SmallVectorImpl<CodeSynthesisContext>::reverse_iterator |
| 444 | Active = CodeSynthesisContexts.rbegin(), |
| 445 | ActiveEnd = CodeSynthesisContexts.rend(); |
| 446 | Active != ActiveEnd; |
| 447 | ++Active, ++InstantiationIdx) { |
| 448 | |
| 449 | if (InstantiationIdx >= SkipStart && InstantiationIdx < SkipEnd) { |
| 450 | if (InstantiationIdx == SkipStart) { |
| 451 | |
| 452 | Diags.Report(Active->PointOfInstantiation, |
| 453 | diag::note_instantiation_contexts_suppressed) |
| 454 | << unsigned(CodeSynthesisContexts.size() - Limit); |
| 455 | } |
| 456 | continue; |
| 457 | } |
| 458 | |
| 459 | switch (Active->Kind) { |
| 460 | case CodeSynthesisContext::TemplateInstantiation: { |
| 461 | Decl *D = Active->Entity; |
| 462 | if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(D)) { |
| 463 | unsigned DiagID = diag::note_template_member_class_here; |
| 464 | if (isa<ClassTemplateSpecializationDecl>(Record)) |
| 465 | DiagID = diag::note_template_class_instantiation_here; |
| 466 | Diags.Report(Active->PointOfInstantiation, DiagID) |
| 467 | << Record << Active->InstantiationRange; |
| 468 | } else if (FunctionDecl *Function = dyn_cast<FunctionDecl>(D)) { |
| 469 | unsigned DiagID; |
| 470 | if (Function->getPrimaryTemplate()) |
| 471 | DiagID = diag::note_function_template_spec_here; |
| 472 | else |
| 473 | DiagID = diag::note_template_member_function_here; |
| 474 | Diags.Report(Active->PointOfInstantiation, DiagID) |
| 475 | << Function |
| 476 | << Active->InstantiationRange; |
| 477 | } else if (VarDecl *VD = dyn_cast<VarDecl>(D)) { |
| 478 | Diags.Report(Active->PointOfInstantiation, |
| 479 | VD->isStaticDataMember()? |
| 480 | diag::note_template_static_data_member_def_here |
| 481 | : diag::note_template_variable_def_here) |
| 482 | << VD |
| 483 | << Active->InstantiationRange; |
| 484 | } else if (EnumDecl *ED = dyn_cast<EnumDecl>(D)) { |
| 485 | Diags.Report(Active->PointOfInstantiation, |
| 486 | diag::note_template_enum_def_here) |
| 487 | << ED |
| 488 | << Active->InstantiationRange; |
| 489 | } else if (FieldDecl *FD = dyn_cast<FieldDecl>(D)) { |
| 490 | Diags.Report(Active->PointOfInstantiation, |
| 491 | diag::note_template_nsdmi_here) |
| 492 | << FD << Active->InstantiationRange; |
| 493 | } else { |
| 494 | Diags.Report(Active->PointOfInstantiation, |
| 495 | diag::note_template_type_alias_instantiation_here) |
| 496 | << cast<TypeAliasTemplateDecl>(D) |
| 497 | << Active->InstantiationRange; |
| 498 | } |
| 499 | break; |
| 500 | } |
| 501 | |
| 502 | case CodeSynthesisContext::DefaultTemplateArgumentInstantiation: { |
| 503 | TemplateDecl *Template = cast<TemplateDecl>(Active->Template); |
| 504 | SmallVector<char, 128> TemplateArgsStr; |
| 505 | llvm::raw_svector_ostream OS(TemplateArgsStr); |
| 506 | Template->printName(OS); |
| 507 | printTemplateArgumentList(OS, Active->template_arguments(), |
| 508 | getPrintingPolicy()); |
| 509 | Diags.Report(Active->PointOfInstantiation, |
| 510 | diag::note_default_arg_instantiation_here) |
| 511 | << OS.str() |
| 512 | << Active->InstantiationRange; |
| 513 | break; |
| 514 | } |
| 515 | |
| 516 | case CodeSynthesisContext::ExplicitTemplateArgumentSubstitution: { |
| 517 | FunctionTemplateDecl *FnTmpl = cast<FunctionTemplateDecl>(Active->Entity); |
| 518 | Diags.Report(Active->PointOfInstantiation, |
| 519 | diag::note_explicit_template_arg_substitution_here) |
| 520 | << FnTmpl |
| 521 | << getTemplateArgumentBindingsText(FnTmpl->getTemplateParameters(), |
| 522 | Active->TemplateArgs, |
| 523 | Active->NumTemplateArgs) |
| 524 | << Active->InstantiationRange; |
| 525 | break; |
| 526 | } |
| 527 | |
| 528 | case CodeSynthesisContext::DeducedTemplateArgumentSubstitution: { |
| 529 | if (FunctionTemplateDecl *FnTmpl = |
| 530 | dyn_cast<FunctionTemplateDecl>(Active->Entity)) { |
| 531 | Diags.Report(Active->PointOfInstantiation, |
| 532 | diag::note_function_template_deduction_instantiation_here) |
| 533 | << FnTmpl |
| 534 | << getTemplateArgumentBindingsText(FnTmpl->getTemplateParameters(), |
| 535 | Active->TemplateArgs, |
| 536 | Active->NumTemplateArgs) |
| 537 | << Active->InstantiationRange; |
| 538 | } else { |
| 539 | bool IsVar = isa<VarTemplateDecl>(Active->Entity) || |
| 540 | isa<VarTemplateSpecializationDecl>(Active->Entity); |
| 541 | bool IsTemplate = false; |
| 542 | TemplateParameterList *Params; |
| 543 | if (auto *D = dyn_cast<TemplateDecl>(Active->Entity)) { |
| 544 | IsTemplate = true; |
| 545 | Params = D->getTemplateParameters(); |
| 546 | } else if (auto *D = dyn_cast<ClassTemplatePartialSpecializationDecl>( |
| 547 | Active->Entity)) { |
| 548 | Params = D->getTemplateParameters(); |
| 549 | } else if (auto *D = dyn_cast<VarTemplatePartialSpecializationDecl>( |
| 550 | Active->Entity)) { |
| 551 | Params = D->getTemplateParameters(); |
| 552 | } else { |
| 553 | llvm_unreachable("unexpected template kind"); |
| 554 | } |
| 555 | |
| 556 | Diags.Report(Active->PointOfInstantiation, |
| 557 | diag::note_deduced_template_arg_substitution_here) |
| 558 | << IsVar << IsTemplate << cast<NamedDecl>(Active->Entity) |
| 559 | << getTemplateArgumentBindingsText(Params, Active->TemplateArgs, |
| 560 | Active->NumTemplateArgs) |
| 561 | << Active->InstantiationRange; |
| 562 | } |
| 563 | break; |
| 564 | } |
| 565 | |
| 566 | case CodeSynthesisContext::DefaultFunctionArgumentInstantiation: { |
| 567 | ParmVarDecl *Param = cast<ParmVarDecl>(Active->Entity); |
| 568 | FunctionDecl *FD = cast<FunctionDecl>(Param->getDeclContext()); |
| 569 | |
| 570 | SmallVector<char, 128> TemplateArgsStr; |
| 571 | llvm::raw_svector_ostream OS(TemplateArgsStr); |
| 572 | FD->printName(OS); |
| 573 | printTemplateArgumentList(OS, Active->template_arguments(), |
| 574 | getPrintingPolicy()); |
| 575 | Diags.Report(Active->PointOfInstantiation, |
| 576 | diag::note_default_function_arg_instantiation_here) |
| 577 | << OS.str() |
| 578 | << Active->InstantiationRange; |
| 579 | break; |
| 580 | } |
| 581 | |
| 582 | case CodeSynthesisContext::PriorTemplateArgumentSubstitution: { |
| 583 | NamedDecl *Parm = cast<NamedDecl>(Active->Entity); |
| 584 | std::string Name; |
| 585 | if (!Parm->getName().empty()) |
| 586 | Name = std::string(" '") + Parm->getName().str() + "'"; |
| 587 | |
| 588 | TemplateParameterList *TemplateParams = nullptr; |
| 589 | if (TemplateDecl *Template = dyn_cast<TemplateDecl>(Active->Template)) |
| 590 | TemplateParams = Template->getTemplateParameters(); |
| 591 | else |
| 592 | TemplateParams = |
| 593 | cast<ClassTemplatePartialSpecializationDecl>(Active->Template) |
| 594 | ->getTemplateParameters(); |
| 595 | Diags.Report(Active->PointOfInstantiation, |
| 596 | diag::note_prior_template_arg_substitution) |
| 597 | << isa<TemplateTemplateParmDecl>(Parm) |
| 598 | << Name |
| 599 | << getTemplateArgumentBindingsText(TemplateParams, |
| 600 | Active->TemplateArgs, |
| 601 | Active->NumTemplateArgs) |
| 602 | << Active->InstantiationRange; |
| 603 | break; |
| 604 | } |
| 605 | |
| 606 | case CodeSynthesisContext::DefaultTemplateArgumentChecking: { |
| 607 | TemplateParameterList *TemplateParams = nullptr; |
| 608 | if (TemplateDecl *Template = dyn_cast<TemplateDecl>(Active->Template)) |
| 609 | TemplateParams = Template->getTemplateParameters(); |
| 610 | else |
| 611 | TemplateParams = |
| 612 | cast<ClassTemplatePartialSpecializationDecl>(Active->Template) |
| 613 | ->getTemplateParameters(); |
| 614 | |
| 615 | Diags.Report(Active->PointOfInstantiation, |
| 616 | diag::note_template_default_arg_checking) |
| 617 | << getTemplateArgumentBindingsText(TemplateParams, |
| 618 | Active->TemplateArgs, |
| 619 | Active->NumTemplateArgs) |
| 620 | << Active->InstantiationRange; |
| 621 | break; |
| 622 | } |
| 623 | |
| 624 | case CodeSynthesisContext::ExceptionSpecEvaluation: |
| 625 | Diags.Report(Active->PointOfInstantiation, |
| 626 | diag::note_evaluating_exception_spec_here) |
| 627 | << cast<FunctionDecl>(Active->Entity); |
| 628 | break; |
| 629 | |
| 630 | case CodeSynthesisContext::ExceptionSpecInstantiation: |
| 631 | Diags.Report(Active->PointOfInstantiation, |
| 632 | diag::note_template_exception_spec_instantiation_here) |
| 633 | << cast<FunctionDecl>(Active->Entity) |
| 634 | << Active->InstantiationRange; |
| 635 | break; |
| 636 | |
| 637 | case CodeSynthesisContext::DeclaringSpecialMember: |
| 638 | Diags.Report(Active->PointOfInstantiation, |
| 639 | diag::note_in_declaration_of_implicit_special_member) |
| 640 | << cast<CXXRecordDecl>(Active->Entity) << Active->SpecialMember; |
| 641 | break; |
| 642 | |
| 643 | case CodeSynthesisContext::DefiningSynthesizedFunction: { |
| 644 | |
| 645 | auto *MD = dyn_cast<CXXMethodDecl>(Active->Entity); |
| 646 | auto CSM = MD ? getSpecialMember(MD) : CXXInvalid; |
| 647 | if (CSM != CXXInvalid) { |
| 648 | Diags.Report(Active->PointOfInstantiation, |
| 649 | diag::note_member_synthesized_at) |
| 650 | << CSM << Context.getTagDeclType(MD->getParent()); |
| 651 | } |
| 652 | break; |
| 653 | } |
| 654 | |
| 655 | case CodeSynthesisContext::Memoization: |
| 656 | break; |
| 657 | } |
| 658 | } |
| 659 | } |
| 660 | |
| 661 | Optional<TemplateDeductionInfo *> Sema::isSFINAEContext() const { |
| 662 | if (InNonInstantiationSFINAEContext) |
| 663 | return Optional<TemplateDeductionInfo *>(nullptr); |
| 664 | |
| 665 | for (SmallVectorImpl<CodeSynthesisContext>::const_reverse_iterator |
| 666 | Active = CodeSynthesisContexts.rbegin(), |
| 667 | ActiveEnd = CodeSynthesisContexts.rend(); |
| 668 | Active != ActiveEnd; |
| 669 | ++Active) |
| 670 | { |
| 671 | switch (Active->Kind) { |
| 672 | case CodeSynthesisContext::TemplateInstantiation: |
| 673 | |
| 674 | |
| 675 | if (isa<TypeAliasTemplateDecl>(Active->Entity)) |
| 676 | break; |
| 677 | LLVM_FALLTHROUGH; |
| 678 | case CodeSynthesisContext::DefaultFunctionArgumentInstantiation: |
| 679 | case CodeSynthesisContext::ExceptionSpecInstantiation: |
| 680 | |
| 681 | return None; |
| 682 | |
| 683 | case CodeSynthesisContext::DefaultTemplateArgumentInstantiation: |
| 684 | case CodeSynthesisContext::PriorTemplateArgumentSubstitution: |
| 685 | case CodeSynthesisContext::DefaultTemplateArgumentChecking: |
| 686 | |
| 687 | |
| 688 | |
| 689 | break; |
| 690 | |
| 691 | case CodeSynthesisContext::ExplicitTemplateArgumentSubstitution: |
| 692 | case CodeSynthesisContext::DeducedTemplateArgumentSubstitution: |
| 693 | |
| 694 | |
| 695 | (0) . __assert_fail ("Active->DeductionInfo && \"Missing deduction info pointer\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 695, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Active->DeductionInfo && "Missing deduction info pointer"); |
| 696 | return Active->DeductionInfo; |
| 697 | |
| 698 | case CodeSynthesisContext::DeclaringSpecialMember: |
| 699 | case CodeSynthesisContext::DefiningSynthesizedFunction: |
| 700 | |
| 701 | |
| 702 | return None; |
| 703 | |
| 704 | case CodeSynthesisContext::ExceptionSpecEvaluation: |
| 705 | |
| 706 | |
| 707 | |
| 708 | break; |
| 709 | |
| 710 | case CodeSynthesisContext::Memoization: |
| 711 | break; |
| 712 | } |
| 713 | |
| 714 | |
| 715 | |
| 716 | if (Active->SavedInNonInstantiationSFINAEContext) |
| 717 | return Optional<TemplateDeductionInfo *>(nullptr); |
| 718 | } |
| 719 | |
| 720 | return None; |
| 721 | } |
| 722 | |
| 723 | |
| 724 | |
| 725 | |
| 726 | namespace { |
| 727 | class TemplateInstantiator : public TreeTransform<TemplateInstantiator> { |
| 728 | const MultiLevelTemplateArgumentList &TemplateArgs; |
| 729 | SourceLocation Loc; |
| 730 | DeclarationName Entity; |
| 731 | |
| 732 | public: |
| 733 | typedef TreeTransform<TemplateInstantiator> inherited; |
| 734 | |
| 735 | TemplateInstantiator(Sema &SemaRef, |
| 736 | const MultiLevelTemplateArgumentList &TemplateArgs, |
| 737 | SourceLocation Loc, |
| 738 | DeclarationName Entity) |
| 739 | : inherited(SemaRef), TemplateArgs(TemplateArgs), Loc(Loc), |
| 740 | Entity(Entity) { } |
| 741 | |
| 742 | |
| 743 | |
| 744 | |
| 745 | |
| 746 | |
| 747 | bool AlreadyTransformed(QualType T); |
| 748 | |
| 749 | |
| 750 | SourceLocation getBaseLocation() { return Loc; } |
| 751 | |
| 752 | |
| 753 | DeclarationName getBaseEntity() { return Entity; } |
| 754 | |
| 755 | |
| 756 | |
| 757 | void setBase(SourceLocation Loc, DeclarationName Entity) { |
| 758 | this->Loc = Loc; |
| 759 | this->Entity = Entity; |
| 760 | } |
| 761 | |
| 762 | bool TryExpandParameterPacks(SourceLocation EllipsisLoc, |
| 763 | SourceRange PatternRange, |
| 764 | ArrayRef<UnexpandedParameterPack> Unexpanded, |
| 765 | bool &ShouldExpand, bool &RetainExpansion, |
| 766 | Optional<unsigned> &NumExpansions) { |
| 767 | return getSema().CheckParameterPacksForExpansion(EllipsisLoc, |
| 768 | PatternRange, Unexpanded, |
| 769 | TemplateArgs, |
| 770 | ShouldExpand, |
| 771 | RetainExpansion, |
| 772 | NumExpansions); |
| 773 | } |
| 774 | |
| 775 | void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { |
| 776 | SemaRef.CurrentInstantiationScope->MakeInstantiatedLocalArgPack(Pack); |
| 777 | } |
| 778 | |
| 779 | TemplateArgument ForgetPartiallySubstitutedPack() { |
| 780 | TemplateArgument Result; |
| 781 | if (NamedDecl *PartialPack |
| 782 | = SemaRef.CurrentInstantiationScope->getPartiallySubstitutedPack()){ |
| 783 | MultiLevelTemplateArgumentList &TemplateArgs |
| 784 | = const_cast<MultiLevelTemplateArgumentList &>(this->TemplateArgs); |
| 785 | unsigned Depth, Index; |
| 786 | std::tie(Depth, Index) = getDepthAndIndex(PartialPack); |
| 787 | if (TemplateArgs.hasTemplateArgument(Depth, Index)) { |
| 788 | Result = TemplateArgs(Depth, Index); |
| 789 | TemplateArgs.setArgument(Depth, Index, TemplateArgument()); |
| 790 | } |
| 791 | } |
| 792 | |
| 793 | return Result; |
| 794 | } |
| 795 | |
| 796 | void RememberPartiallySubstitutedPack(TemplateArgument Arg) { |
| 797 | if (Arg.isNull()) |
| 798 | return; |
| 799 | |
| 800 | if (NamedDecl *PartialPack |
| 801 | = SemaRef.CurrentInstantiationScope->getPartiallySubstitutedPack()){ |
| 802 | MultiLevelTemplateArgumentList &TemplateArgs |
| 803 | = const_cast<MultiLevelTemplateArgumentList &>(this->TemplateArgs); |
| 804 | unsigned Depth, Index; |
| 805 | std::tie(Depth, Index) = getDepthAndIndex(PartialPack); |
| 806 | TemplateArgs.setArgument(Depth, Index, Arg); |
| 807 | } |
| 808 | } |
| 809 | |
| 810 | |
| 811 | |
| 812 | Decl *TransformDecl(SourceLocation Loc, Decl *D); |
| 813 | |
| 814 | void transformAttrs(Decl *Old, Decl *New) { |
| 815 | SemaRef.InstantiateAttrs(TemplateArgs, Old, New); |
| 816 | } |
| 817 | |
| 818 | void transformedLocalDecl(Decl *Old, Decl *New) { |
| 819 | |
| 820 | |
| 821 | |
| 822 | auto *NewMD = dyn_cast<CXXMethodDecl>(New); |
| 823 | if (NewMD && isLambdaCallOperator(NewMD)) { |
| 824 | auto *OldMD = dyn_cast<CXXMethodDecl>(Old); |
| 825 | if (auto *NewTD = NewMD->getDescribedFunctionTemplate()) |
| 826 | NewTD->setInstantiatedFromMemberTemplate( |
| 827 | OldMD->getDescribedFunctionTemplate()); |
| 828 | else |
| 829 | NewMD->setInstantiationOfMemberFunction(OldMD, |
| 830 | TSK_ImplicitInstantiation); |
| 831 | } |
| 832 | |
| 833 | SemaRef.CurrentInstantiationScope->InstantiatedLocal(Old, New); |
| 834 | |
| 835 | |
| 836 | |
| 837 | if (auto *DC = dyn_cast<DeclContext>(Old)) |
| 838 | SemaRef.PerformDependentDiagnostics(DC, TemplateArgs); |
| 839 | } |
| 840 | |
| 841 | |
| 842 | |
| 843 | Decl *TransformDefinition(SourceLocation Loc, Decl *D); |
| 844 | |
| 845 | |
| 846 | |
| 847 | NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc); |
| 848 | |
| 849 | |
| 850 | |
| 851 | VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, |
| 852 | TypeSourceInfo *Declarator, |
| 853 | SourceLocation StartLoc, |
| 854 | SourceLocation NameLoc, |
| 855 | IdentifierInfo *Name); |
| 856 | |
| 857 | |
| 858 | |
| 859 | VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl, |
| 860 | TypeSourceInfo *TSInfo, QualType T); |
| 861 | |
| 862 | |
| 863 | |
| 864 | QualType RebuildElaboratedType(SourceLocation KeywordLoc, |
| 865 | ElaboratedTypeKeyword Keyword, |
| 866 | NestedNameSpecifierLoc QualifierLoc, |
| 867 | QualType T); |
| 868 | |
| 869 | TemplateName |
| 870 | TransformTemplateName(CXXScopeSpec &SS, TemplateName Name, |
| 871 | SourceLocation NameLoc, |
| 872 | QualType ObjectType = QualType(), |
| 873 | NamedDecl *FirstQualifierInScope = nullptr, |
| 874 | bool AllowInjectedClassName = false); |
| 875 | |
| 876 | const LoopHintAttr *TransformLoopHintAttr(const LoopHintAttr *LH); |
| 877 | |
| 878 | ExprResult TransformPredefinedExpr(PredefinedExpr *E); |
| 879 | ExprResult TransformDeclRefExpr(DeclRefExpr *E); |
| 880 | ExprResult TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E); |
| 881 | |
| 882 | ExprResult TransformTemplateParmRefExpr(DeclRefExpr *E, |
| 883 | NonTypeTemplateParmDecl *D); |
| 884 | ExprResult TransformSubstNonTypeTemplateParmPackExpr( |
| 885 | SubstNonTypeTemplateParmPackExpr *E); |
| 886 | |
| 887 | |
| 888 | ExprResult RebuildParmVarDeclRefExpr(ParmVarDecl *PD, SourceLocation Loc); |
| 889 | |
| 890 | |
| 891 | ExprResult TransformFunctionParmPackRefExpr(DeclRefExpr *E, |
| 892 | ParmVarDecl *PD); |
| 893 | |
| 894 | |
| 895 | |
| 896 | |
| 897 | ExprResult TransformFunctionParmPackExpr(FunctionParmPackExpr *E); |
| 898 | |
| 899 | QualType TransformFunctionProtoType(TypeLocBuilder &TLB, |
| 900 | FunctionProtoTypeLoc TL) { |
| 901 | |
| 902 | return inherited::TransformFunctionProtoType(TLB, TL); |
| 903 | } |
| 904 | |
| 905 | template<typename Fn> |
| 906 | QualType TransformFunctionProtoType(TypeLocBuilder &TLB, |
| 907 | FunctionProtoTypeLoc TL, |
| 908 | CXXRecordDecl *ThisContext, |
| 909 | Qualifiers ThisTypeQuals, |
| 910 | Fn TransformExceptionSpec); |
| 911 | |
| 912 | ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm, |
| 913 | int indexAdjustment, |
| 914 | Optional<unsigned> NumExpansions, |
| 915 | bool ExpectParameterPack); |
| 916 | |
| 917 | |
| 918 | |
| 919 | QualType TransformTemplateTypeParmType(TypeLocBuilder &TLB, |
| 920 | TemplateTypeParmTypeLoc TL); |
| 921 | |
| 922 | |
| 923 | |
| 924 | |
| 925 | QualType TransformSubstTemplateTypeParmPackType(TypeLocBuilder &TLB, |
| 926 | SubstTemplateTypeParmPackTypeLoc TL); |
| 927 | |
| 928 | ExprResult TransformLambdaExpr(LambdaExpr *E) { |
| 929 | LocalInstantiationScope Scope(SemaRef, ); |
| 930 | return TreeTransform<TemplateInstantiator>::TransformLambdaExpr(E); |
| 931 | } |
| 932 | |
| 933 | TemplateParameterList *TransformTemplateParameterList( |
| 934 | TemplateParameterList *OrigTPL) { |
| 935 | if (!OrigTPL || !OrigTPL->size()) return OrigTPL; |
| 936 | |
| 937 | DeclContext *Owner = OrigTPL->getParam(0)->getDeclContext(); |
| 938 | TemplateDeclInstantiator DeclInstantiator(getSema(), |
| 939 | Owner, TemplateArgs); |
| 940 | return DeclInstantiator.SubstTemplateParams(OrigTPL); |
| 941 | } |
| 942 | private: |
| 943 | ExprResult transformNonTypeTemplateParmRef(NonTypeTemplateParmDecl *parm, |
| 944 | SourceLocation loc, |
| 945 | TemplateArgument arg); |
| 946 | }; |
| 947 | } |
| 948 | |
| 949 | bool TemplateInstantiator::AlreadyTransformed(QualType T) { |
| 950 | if (T.isNull()) |
| 951 | return true; |
| 952 | |
| 953 | if (T->isInstantiationDependentType() || T->isVariablyModifiedType()) |
| 954 | return false; |
| 955 | |
| 956 | getSema().MarkDeclarationsReferencedInType(Loc, T); |
| 957 | return true; |
| 958 | } |
| 959 | |
| 960 | static TemplateArgument |
| 961 | getPackSubstitutedTemplateArgument(Sema &S, TemplateArgument Arg) { |
| 962 | = 0", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 962, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(S.ArgumentPackSubstitutionIndex >= 0); |
| 963 | assert(S.ArgumentPackSubstitutionIndex < (int)Arg.pack_size()); |
| 964 | Arg = Arg.pack_begin()[S.ArgumentPackSubstitutionIndex]; |
| 965 | if (Arg.isPackExpansion()) |
| 966 | Arg = Arg.getPackExpansionPattern(); |
| 967 | return Arg; |
| 968 | } |
| 969 | |
| 970 | Decl *TemplateInstantiator::TransformDecl(SourceLocation Loc, Decl *D) { |
| 971 | if (!D) |
| 972 | return nullptr; |
| 973 | |
| 974 | if (TemplateTemplateParmDecl *TTP = dyn_cast<TemplateTemplateParmDecl>(D)) { |
| 975 | if (TTP->getDepth() < TemplateArgs.getNumLevels()) { |
| 976 | |
| 977 | |
| 978 | |
| 979 | |
| 980 | if (!TemplateArgs.hasTemplateArgument(TTP->getDepth(), |
| 981 | TTP->getPosition())) |
| 982 | return D; |
| 983 | |
| 984 | TemplateArgument Arg = TemplateArgs(TTP->getDepth(), TTP->getPosition()); |
| 985 | |
| 986 | if (TTP->isParameterPack()) { |
| 987 | (0) . __assert_fail ("Arg.getKind() == TemplateArgument..Pack && \"Missing argument pack\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 988, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Arg.getKind() == TemplateArgument::Pack && |
| 988 | (0) . __assert_fail ("Arg.getKind() == TemplateArgument..Pack && \"Missing argument pack\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 988, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Missing argument pack"); |
| 989 | Arg = getPackSubstitutedTemplateArgument(getSema(), Arg); |
| 990 | } |
| 991 | |
| 992 | TemplateName Template = Arg.getAsTemplate().getNameToSubstitute(); |
| 993 | (0) . __assert_fail ("!Template.isNull() && Template.getAsTemplateDecl() && \"Wrong kind of template template argument\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 994, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!Template.isNull() && Template.getAsTemplateDecl() && |
| 994 | (0) . __assert_fail ("!Template.isNull() && Template.getAsTemplateDecl() && \"Wrong kind of template template argument\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 994, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Wrong kind of template template argument"); |
| 995 | return Template.getAsTemplateDecl(); |
| 996 | } |
| 997 | |
| 998 | |
| 999 | |
| 1000 | } |
| 1001 | |
| 1002 | return SemaRef.FindInstantiatedDecl(Loc, cast<NamedDecl>(D), TemplateArgs); |
| 1003 | } |
| 1004 | |
| 1005 | Decl *TemplateInstantiator::TransformDefinition(SourceLocation Loc, Decl *D) { |
| 1006 | Decl *Inst = getSema().SubstDecl(D, getSema().CurContext, TemplateArgs); |
| 1007 | if (!Inst) |
| 1008 | return nullptr; |
| 1009 | |
| 1010 | getSema().CurrentInstantiationScope->InstantiatedLocal(D, Inst); |
| 1011 | return Inst; |
| 1012 | } |
| 1013 | |
| 1014 | NamedDecl * |
| 1015 | TemplateInstantiator::TransformFirstQualifierInScope(NamedDecl *D, |
| 1016 | SourceLocation Loc) { |
| 1017 | |
| 1018 | |
| 1019 | if (TemplateTypeParmDecl *TTPD = dyn_cast_or_null<TemplateTypeParmDecl>(D)) { |
| 1020 | const TemplateTypeParmType *TTP |
| 1021 | = cast<TemplateTypeParmType>(getSema().Context.getTypeDeclType(TTPD)); |
| 1022 | |
| 1023 | if (TTP->getDepth() < TemplateArgs.getNumLevels()) { |
| 1024 | |
| 1025 | TemplateArgument Arg = TemplateArgs(TTP->getDepth(), TTP->getIndex()); |
| 1026 | |
| 1027 | if (TTP->isParameterPack()) { |
| 1028 | (0) . __assert_fail ("Arg.getKind() == TemplateArgument..Pack && \"Missing argument pack\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 1029, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Arg.getKind() == TemplateArgument::Pack && |
| 1029 | (0) . __assert_fail ("Arg.getKind() == TemplateArgument..Pack && \"Missing argument pack\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 1029, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Missing argument pack"); |
| 1030 | |
| 1031 | if (getSema().ArgumentPackSubstitutionIndex == -1) |
| 1032 | return nullptr; |
| 1033 | |
| 1034 | Arg = getPackSubstitutedTemplateArgument(getSema(), Arg); |
| 1035 | } |
| 1036 | |
| 1037 | QualType T = Arg.getAsType(); |
| 1038 | if (T.isNull()) |
| 1039 | return cast_or_null<NamedDecl>(TransformDecl(Loc, D)); |
| 1040 | |
| 1041 | if (const TagType *Tag = T->getAs<TagType>()) |
| 1042 | return Tag->getDecl(); |
| 1043 | |
| 1044 | |
| 1045 | getSema().Diag(Loc, diag::err_nested_name_spec_non_tag) << T; |
| 1046 | return nullptr; |
| 1047 | } |
| 1048 | } |
| 1049 | |
| 1050 | return cast_or_null<NamedDecl>(TransformDecl(Loc, D)); |
| 1051 | } |
| 1052 | |
| 1053 | VarDecl * |
| 1054 | TemplateInstantiator::RebuildExceptionDecl(VarDecl *ExceptionDecl, |
| 1055 | TypeSourceInfo *Declarator, |
| 1056 | SourceLocation StartLoc, |
| 1057 | SourceLocation NameLoc, |
| 1058 | IdentifierInfo *Name) { |
| 1059 | VarDecl *Var = inherited::RebuildExceptionDecl(ExceptionDecl, Declarator, |
| 1060 | StartLoc, NameLoc, Name); |
| 1061 | if (Var) |
| 1062 | getSema().CurrentInstantiationScope->InstantiatedLocal(ExceptionDecl, Var); |
| 1063 | return Var; |
| 1064 | } |
| 1065 | |
| 1066 | VarDecl *TemplateInstantiator::RebuildObjCExceptionDecl(VarDecl *ExceptionDecl, |
| 1067 | TypeSourceInfo *TSInfo, |
| 1068 | QualType T) { |
| 1069 | VarDecl *Var = inherited::RebuildObjCExceptionDecl(ExceptionDecl, TSInfo, T); |
| 1070 | if (Var) |
| 1071 | getSema().CurrentInstantiationScope->InstantiatedLocal(ExceptionDecl, Var); |
| 1072 | return Var; |
| 1073 | } |
| 1074 | |
| 1075 | QualType |
| 1076 | TemplateInstantiator::RebuildElaboratedType(SourceLocation KeywordLoc, |
| 1077 | ElaboratedTypeKeyword Keyword, |
| 1078 | NestedNameSpecifierLoc QualifierLoc, |
| 1079 | QualType T) { |
| 1080 | if (const TagType *TT = T->getAs<TagType>()) { |
| 1081 | TagDecl* TD = TT->getDecl(); |
| 1082 | |
| 1083 | SourceLocation TagLocation = KeywordLoc; |
| 1084 | |
| 1085 | IdentifierInfo *Id = TD->getIdentifier(); |
| 1086 | |
| 1087 | |
| 1088 | |
| 1089 | if (Id && Keyword != ETK_None && Keyword != ETK_Typename) { |
| 1090 | TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword); |
| 1091 | if (!SemaRef.isAcceptableTagRedeclaration(TD, Kind, , |
| 1092 | TagLocation, Id)) { |
| 1093 | SemaRef.Diag(TagLocation, diag::err_use_with_wrong_tag) |
| 1094 | << Id |
| 1095 | << FixItHint::CreateReplacement(SourceRange(TagLocation), |
| 1096 | TD->getKindName()); |
| 1097 | SemaRef.Diag(TD->getLocation(), diag::note_previous_use); |
| 1098 | } |
| 1099 | } |
| 1100 | } |
| 1101 | |
| 1102 | return TreeTransform<TemplateInstantiator>::RebuildElaboratedType(KeywordLoc, |
| 1103 | Keyword, |
| 1104 | QualifierLoc, |
| 1105 | T); |
| 1106 | } |
| 1107 | |
| 1108 | TemplateName TemplateInstantiator::TransformTemplateName( |
| 1109 | CXXScopeSpec &SS, TemplateName Name, SourceLocation NameLoc, |
| 1110 | QualType ObjectType, NamedDecl *FirstQualifierInScope, |
| 1111 | bool AllowInjectedClassName) { |
| 1112 | if (TemplateTemplateParmDecl *TTP |
| 1113 | = dyn_cast_or_null<TemplateTemplateParmDecl>(Name.getAsTemplateDecl())) { |
| 1114 | if (TTP->getDepth() < TemplateArgs.getNumLevels()) { |
| 1115 | |
| 1116 | |
| 1117 | |
| 1118 | |
| 1119 | if (!TemplateArgs.hasTemplateArgument(TTP->getDepth(), |
| 1120 | TTP->getPosition())) |
| 1121 | return Name; |
| 1122 | |
| 1123 | TemplateArgument Arg = TemplateArgs(TTP->getDepth(), TTP->getPosition()); |
| 1124 | |
| 1125 | if (TTP->isParameterPack()) { |
| 1126 | (0) . __assert_fail ("Arg.getKind() == TemplateArgument..Pack && \"Missing argument pack\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 1127, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Arg.getKind() == TemplateArgument::Pack && |
| 1127 | (0) . __assert_fail ("Arg.getKind() == TemplateArgument..Pack && \"Missing argument pack\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 1127, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Missing argument pack"); |
| 1128 | |
| 1129 | if (getSema().ArgumentPackSubstitutionIndex == -1) { |
| 1130 | |
| 1131 | |
| 1132 | |
| 1133 | return getSema().Context.getSubstTemplateTemplateParmPack(TTP, Arg); |
| 1134 | } |
| 1135 | |
| 1136 | Arg = getPackSubstitutedTemplateArgument(getSema(), Arg); |
| 1137 | } |
| 1138 | |
| 1139 | TemplateName Template = Arg.getAsTemplate().getNameToSubstitute(); |
| 1140 | (0) . __assert_fail ("!Template.isNull() && \"Null template template argument\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 1140, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!Template.isNull() && "Null template template argument"); |
| 1141 | (0) . __assert_fail ("!Template.getAsQualifiedTemplateName() && \"template decl to substitute is qualified?\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 1142, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!Template.getAsQualifiedTemplateName() && |
| 1142 | (0) . __assert_fail ("!Template.getAsQualifiedTemplateName() && \"template decl to substitute is qualified?\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 1142, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "template decl to substitute is qualified?"); |
| 1143 | |
| 1144 | Template = getSema().Context.getSubstTemplateTemplateParm(TTP, Template); |
| 1145 | return Template; |
| 1146 | } |
| 1147 | } |
| 1148 | |
| 1149 | if (SubstTemplateTemplateParmPackStorage *SubstPack |
| 1150 | = Name.getAsSubstTemplateTemplateParmPack()) { |
| 1151 | if (getSema().ArgumentPackSubstitutionIndex == -1) |
| 1152 | return Name; |
| 1153 | |
| 1154 | TemplateArgument Arg = SubstPack->getArgumentPack(); |
| 1155 | Arg = getPackSubstitutedTemplateArgument(getSema(), Arg); |
| 1156 | return Arg.getAsTemplate().getNameToSubstitute(); |
| 1157 | } |
| 1158 | |
| 1159 | return inherited::TransformTemplateName(SS, Name, NameLoc, ObjectType, |
| 1160 | FirstQualifierInScope, |
| 1161 | AllowInjectedClassName); |
| 1162 | } |
| 1163 | |
| 1164 | ExprResult |
| 1165 | TemplateInstantiator::TransformPredefinedExpr(PredefinedExpr *E) { |
| 1166 | if (!E->isTypeDependent()) |
| 1167 | return E; |
| 1168 | |
| 1169 | return getSema().BuildPredefinedExpr(E->getLocation(), E->getIdentKind()); |
| 1170 | } |
| 1171 | |
| 1172 | ExprResult |
| 1173 | TemplateInstantiator::TransformTemplateParmRefExpr(DeclRefExpr *E, |
| 1174 | NonTypeTemplateParmDecl *NTTP) { |
| 1175 | |
| 1176 | |
| 1177 | |
| 1178 | |
| 1179 | if (!TemplateArgs.hasTemplateArgument(NTTP->getDepth(), |
| 1180 | NTTP->getPosition())) |
| 1181 | return E; |
| 1182 | |
| 1183 | TemplateArgument Arg = TemplateArgs(NTTP->getDepth(), NTTP->getPosition()); |
| 1184 | |
| 1185 | if (TemplateArgs.getNumLevels() != TemplateArgs.getNumSubstitutedLevels()) { |
| 1186 | |
| 1187 | |
| 1188 | |
| 1189 | |
| 1190 | if (Arg.getKind() == TemplateArgument::Pack) { |
| 1191 | |
| 1192 | (0) . __assert_fail ("Arg.pack_size() == 1 && Arg.pack_begin()->isPackExpansion() && \"unexpected pack arguments in partial substitution\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 1193, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Arg.pack_size() == 1 && Arg.pack_begin()->isPackExpansion() && |
| 1193 | (0) . __assert_fail ("Arg.pack_size() == 1 && Arg.pack_begin()->isPackExpansion() && \"unexpected pack arguments in partial substitution\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 1193, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "unexpected pack arguments in partial substitution"); |
| 1194 | Arg = Arg.pack_begin()->getPackExpansionPattern(); |
| 1195 | } |
| 1196 | (0) . __assert_fail ("Arg.getKind() == TemplateArgument..Expression && \"unexpected nontype template argument kind in partial substitution\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 1197, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Arg.getKind() == TemplateArgument::Expression && |
| 1197 | (0) . __assert_fail ("Arg.getKind() == TemplateArgument..Expression && \"unexpected nontype template argument kind in partial substitution\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 1197, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "unexpected nontype template argument kind in partial substitution"); |
| 1198 | return Arg.getAsExpr(); |
| 1199 | } |
| 1200 | |
| 1201 | if (NTTP->isParameterPack()) { |
| 1202 | (0) . __assert_fail ("Arg.getKind() == TemplateArgument..Pack && \"Missing argument pack\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 1203, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Arg.getKind() == TemplateArgument::Pack && |
| 1203 | (0) . __assert_fail ("Arg.getKind() == TemplateArgument..Pack && \"Missing argument pack\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 1203, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Missing argument pack"); |
| 1204 | |
| 1205 | if (getSema().ArgumentPackSubstitutionIndex == -1) { |
| 1206 | |
| 1207 | |
| 1208 | |
| 1209 | QualType TargetType = SemaRef.SubstType(NTTP->getType(), TemplateArgs, |
| 1210 | E->getLocation(), |
| 1211 | NTTP->getDeclName()); |
| 1212 | if (TargetType.isNull()) |
| 1213 | return ExprError(); |
| 1214 | |
| 1215 | return new (SemaRef.Context) SubstNonTypeTemplateParmPackExpr( |
| 1216 | TargetType.getNonLValueExprType(SemaRef.Context), |
| 1217 | TargetType->isReferenceType() ? VK_LValue : VK_RValue, NTTP, |
| 1218 | E->getLocation(), Arg); |
| 1219 | } |
| 1220 | |
| 1221 | Arg = getPackSubstitutedTemplateArgument(getSema(), Arg); |
| 1222 | } |
| 1223 | |
| 1224 | return transformNonTypeTemplateParmRef(NTTP, E->getLocation(), Arg); |
| 1225 | } |
| 1226 | |
| 1227 | const LoopHintAttr * |
| 1228 | TemplateInstantiator::TransformLoopHintAttr(const LoopHintAttr *LH) { |
| 1229 | Expr *TransformedExpr = getDerived().TransformExpr(LH->getValue()).get(); |
| 1230 | |
| 1231 | if (TransformedExpr == LH->getValue()) |
| 1232 | return LH; |
| 1233 | |
| 1234 | |
| 1235 | if (getSema().CheckLoopHintExpr(TransformedExpr, LH->getLocation())) |
| 1236 | return LH; |
| 1237 | |
| 1238 | |
| 1239 | |
| 1240 | return LoopHintAttr::CreateImplicit( |
| 1241 | getSema().Context, LH->getSemanticSpelling(), LH->getOption(), |
| 1242 | LH->getState(), TransformedExpr, LH->getRange()); |
| 1243 | } |
| 1244 | |
| 1245 | ExprResult TemplateInstantiator::transformNonTypeTemplateParmRef( |
| 1246 | NonTypeTemplateParmDecl *parm, |
| 1247 | SourceLocation loc, |
| 1248 | TemplateArgument arg) { |
| 1249 | ExprResult result; |
| 1250 | QualType type; |
| 1251 | |
| 1252 | |
| 1253 | |
| 1254 | if (arg.getKind() == TemplateArgument::Expression) { |
| 1255 | Expr *argExpr = arg.getAsExpr(); |
| 1256 | result = argExpr; |
| 1257 | type = argExpr->getType(); |
| 1258 | |
| 1259 | } else if (arg.getKind() == TemplateArgument::Declaration || |
| 1260 | arg.getKind() == TemplateArgument::NullPtr) { |
| 1261 | ValueDecl *VD; |
| 1262 | if (arg.getKind() == TemplateArgument::Declaration) { |
| 1263 | VD = arg.getAsDecl(); |
| 1264 | |
| 1265 | |
| 1266 | |
| 1267 | VD = cast_or_null<ValueDecl>( |
| 1268 | getSema().FindInstantiatedDecl(loc, VD, TemplateArgs)); |
| 1269 | if (!VD) |
| 1270 | return ExprError(); |
| 1271 | } else { |
| 1272 | |
| 1273 | VD = nullptr; |
| 1274 | } |
| 1275 | |
| 1276 | |
| 1277 | |
| 1278 | if (parm->isExpandedParameterPack()) { |
| 1279 | type = parm->getExpansionType(SemaRef.ArgumentPackSubstitutionIndex); |
| 1280 | } else if (parm->isParameterPack() && |
| 1281 | isa<PackExpansionType>(parm->getType())) { |
| 1282 | type = SemaRef.SubstType( |
| 1283 | cast<PackExpansionType>(parm->getType())->getPattern(), |
| 1284 | TemplateArgs, loc, parm->getDeclName()); |
| 1285 | } else { |
| 1286 | type = SemaRef.SubstType(VD ? arg.getParamTypeForDecl() : arg.getNullPtrType(), |
| 1287 | TemplateArgs, loc, parm->getDeclName()); |
| 1288 | } |
| 1289 | (0) . __assert_fail ("!type.isNull() && \"type substitution failed for param type\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 1289, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!type.isNull() && "type substitution failed for param type"); |
| 1290 | (0) . __assert_fail ("!type->isDependentType() && \"param type still dependent\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 1290, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!type->isDependentType() && "param type still dependent"); |
| 1291 | result = SemaRef.BuildExpressionFromDeclTemplateArgument(arg, type, loc); |
| 1292 | |
| 1293 | if (!result.isInvalid()) type = result.get()->getType(); |
| 1294 | } else { |
| 1295 | result = SemaRef.BuildExpressionFromIntegralTemplateArgument(arg, loc); |
| 1296 | |
| 1297 | |
| 1298 | |
| 1299 | type = arg.getIntegralType(); |
| 1300 | } |
| 1301 | if (result.isInvalid()) return ExprError(); |
| 1302 | |
| 1303 | Expr *resultExpr = result.get(); |
| 1304 | return new (SemaRef.Context) SubstNonTypeTemplateParmExpr( |
| 1305 | type, resultExpr->getValueKind(), loc, parm, resultExpr); |
| 1306 | } |
| 1307 | |
| 1308 | ExprResult |
| 1309 | TemplateInstantiator::TransformSubstNonTypeTemplateParmPackExpr( |
| 1310 | SubstNonTypeTemplateParmPackExpr *E) { |
| 1311 | if (getSema().ArgumentPackSubstitutionIndex == -1) { |
| 1312 | |
| 1313 | return E; |
| 1314 | } |
| 1315 | |
| 1316 | TemplateArgument Arg = E->getArgumentPack(); |
| 1317 | Arg = getPackSubstitutedTemplateArgument(getSema(), Arg); |
| 1318 | return transformNonTypeTemplateParmRef(E->getParameterPack(), |
| 1319 | E->getParameterPackLocation(), |
| 1320 | Arg); |
| 1321 | } |
| 1322 | |
| 1323 | ExprResult |
| 1324 | TemplateInstantiator::RebuildParmVarDeclRefExpr(ParmVarDecl *PD, |
| 1325 | SourceLocation Loc) { |
| 1326 | DeclarationNameInfo NameInfo(PD->getDeclName(), Loc); |
| 1327 | return getSema().BuildDeclarationNameExpr(CXXScopeSpec(), NameInfo, PD); |
| 1328 | } |
| 1329 | |
| 1330 | ExprResult |
| 1331 | TemplateInstantiator::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) { |
| 1332 | if (getSema().ArgumentPackSubstitutionIndex != -1) { |
| 1333 | |
| 1334 | ParmVarDecl *D = E->getExpansion(getSema().ArgumentPackSubstitutionIndex); |
| 1335 | ValueDecl *VD = cast_or_null<ValueDecl>(TransformDecl(E->getExprLoc(), D)); |
| 1336 | if (!VD) |
| 1337 | return ExprError(); |
| 1338 | return RebuildParmVarDeclRefExpr(cast<ParmVarDecl>(VD), E->getExprLoc()); |
| 1339 | } |
| 1340 | |
| 1341 | QualType T = TransformType(E->getType()); |
| 1342 | if (T.isNull()) |
| 1343 | return ExprError(); |
| 1344 | |
| 1345 | |
| 1346 | |
| 1347 | SmallVector<ParmVarDecl *, 8> Parms; |
| 1348 | Parms.reserve(E->getNumExpansions()); |
| 1349 | for (FunctionParmPackExpr::iterator I = E->begin(), End = E->end(); |
| 1350 | I != End; ++I) { |
| 1351 | ParmVarDecl *D = |
| 1352 | cast_or_null<ParmVarDecl>(TransformDecl(E->getExprLoc(), *I)); |
| 1353 | if (!D) |
| 1354 | return ExprError(); |
| 1355 | Parms.push_back(D); |
| 1356 | } |
| 1357 | |
| 1358 | return FunctionParmPackExpr::Create(getSema().Context, T, |
| 1359 | E->getParameterPack(), |
| 1360 | E->getParameterPackLocation(), Parms); |
| 1361 | } |
| 1362 | |
| 1363 | ExprResult |
| 1364 | TemplateInstantiator::TransformFunctionParmPackRefExpr(DeclRefExpr *E, |
| 1365 | ParmVarDecl *PD) { |
| 1366 | typedef LocalInstantiationScope::DeclArgumentPack DeclArgumentPack; |
| 1367 | llvm::PointerUnion<Decl *, DeclArgumentPack *> *Found |
| 1368 | = getSema().CurrentInstantiationScope->findInstantiationOf(PD); |
| 1369 | (0) . __assert_fail ("Found && \"no instantiation for parameter pack\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 1369, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Found && "no instantiation for parameter pack"); |
| 1370 | |
| 1371 | Decl *TransformedDecl; |
| 1372 | if (DeclArgumentPack *Pack = Found->dyn_cast<DeclArgumentPack *>()) { |
| 1373 | |
| 1374 | |
| 1375 | if (getSema().ArgumentPackSubstitutionIndex == -1) { |
| 1376 | QualType T = TransformType(E->getType()); |
| 1377 | if (T.isNull()) |
| 1378 | return ExprError(); |
| 1379 | return FunctionParmPackExpr::Create(getSema().Context, T, PD, |
| 1380 | E->getExprLoc(), *Pack); |
| 1381 | } |
| 1382 | |
| 1383 | TransformedDecl = (*Pack)[getSema().ArgumentPackSubstitutionIndex]; |
| 1384 | } else { |
| 1385 | TransformedDecl = Found->get<Decl*>(); |
| 1386 | } |
| 1387 | |
| 1388 | |
| 1389 | return RebuildParmVarDeclRefExpr(cast<ParmVarDecl>(TransformedDecl), |
| 1390 | E->getExprLoc()); |
| 1391 | } |
| 1392 | |
| 1393 | ExprResult |
| 1394 | TemplateInstantiator::TransformDeclRefExpr(DeclRefExpr *E) { |
| 1395 | NamedDecl *D = E->getDecl(); |
| 1396 | |
| 1397 | |
| 1398 | |
| 1399 | if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(D)) { |
| 1400 | if (NTTP->getDepth() < TemplateArgs.getNumLevels()) |
| 1401 | return TransformTemplateParmRefExpr(E, NTTP); |
| 1402 | |
| 1403 | |
| 1404 | |
| 1405 | } |
| 1406 | |
| 1407 | |
| 1408 | if (ParmVarDecl *PD = dyn_cast<ParmVarDecl>(D)) |
| 1409 | if (PD->isParameterPack()) |
| 1410 | return TransformFunctionParmPackRefExpr(E, PD); |
| 1411 | |
| 1412 | return TreeTransform<TemplateInstantiator>::TransformDeclRefExpr(E); |
| 1413 | } |
| 1414 | |
| 1415 | ExprResult TemplateInstantiator::TransformCXXDefaultArgExpr( |
| 1416 | CXXDefaultArgExpr *E) { |
| 1417 | (0) . __assert_fail ("!cast(E->getParam()->getDeclContext())-> getDescribedFunctionTemplate() && \"Default arg expressions are never formed in dependent cases.\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 1419, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!cast<FunctionDecl>(E->getParam()->getDeclContext())-> |
| 1418 | (0) . __assert_fail ("!cast(E->getParam()->getDeclContext())-> getDescribedFunctionTemplate() && \"Default arg expressions are never formed in dependent cases.\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 1419, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> getDescribedFunctionTemplate() && |
| 1419 | (0) . __assert_fail ("!cast(E->getParam()->getDeclContext())-> getDescribedFunctionTemplate() && \"Default arg expressions are never formed in dependent cases.\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 1419, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Default arg expressions are never formed in dependent cases."); |
| 1420 | return SemaRef.BuildCXXDefaultArgExpr(E->getUsedLocation(), |
| 1421 | cast<FunctionDecl>(E->getParam()->getDeclContext()), |
| 1422 | E->getParam()); |
| 1423 | } |
| 1424 | |
| 1425 | template<typename Fn> |
| 1426 | QualType TemplateInstantiator::TransformFunctionProtoType(TypeLocBuilder &TLB, |
| 1427 | FunctionProtoTypeLoc TL, |
| 1428 | CXXRecordDecl *ThisContext, |
| 1429 | Qualifiers ThisTypeQuals, |
| 1430 | Fn TransformExceptionSpec) { |
| 1431 | |
| 1432 | LocalInstantiationScope Scope(SemaRef, ); |
| 1433 | return inherited::TransformFunctionProtoType( |
| 1434 | TLB, TL, ThisContext, ThisTypeQuals, TransformExceptionSpec); |
| 1435 | } |
| 1436 | |
| 1437 | ParmVarDecl * |
| 1438 | TemplateInstantiator::TransformFunctionTypeParam(ParmVarDecl *OldParm, |
| 1439 | int indexAdjustment, |
| 1440 | Optional<unsigned> NumExpansions, |
| 1441 | bool ExpectParameterPack) { |
| 1442 | return SemaRef.SubstParmVarDecl(OldParm, TemplateArgs, indexAdjustment, |
| 1443 | NumExpansions, ExpectParameterPack); |
| 1444 | } |
| 1445 | |
| 1446 | QualType |
| 1447 | TemplateInstantiator::TransformTemplateTypeParmType(TypeLocBuilder &TLB, |
| 1448 | TemplateTypeParmTypeLoc TL) { |
| 1449 | const TemplateTypeParmType *T = TL.getTypePtr(); |
| 1450 | if (T->getDepth() < TemplateArgs.getNumLevels()) { |
| 1451 | |
| 1452 | |
| 1453 | |
| 1454 | |
| 1455 | |
| 1456 | |
| 1457 | |
| 1458 | if (!TemplateArgs.hasTemplateArgument(T->getDepth(), T->getIndex())) { |
| 1459 | TemplateTypeParmTypeLoc NewTL |
| 1460 | = TLB.push<TemplateTypeParmTypeLoc>(TL.getType()); |
| 1461 | NewTL.setNameLoc(TL.getNameLoc()); |
| 1462 | return TL.getType(); |
| 1463 | } |
| 1464 | |
| 1465 | TemplateArgument Arg = TemplateArgs(T->getDepth(), T->getIndex()); |
| 1466 | |
| 1467 | if (T->isParameterPack()) { |
| 1468 | (0) . __assert_fail ("Arg.getKind() == TemplateArgument..Pack && \"Missing argument pack\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 1469, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Arg.getKind() == TemplateArgument::Pack && |
| 1469 | (0) . __assert_fail ("Arg.getKind() == TemplateArgument..Pack && \"Missing argument pack\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 1469, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Missing argument pack"); |
| 1470 | |
| 1471 | if (getSema().ArgumentPackSubstitutionIndex == -1) { |
| 1472 | |
| 1473 | |
| 1474 | |
| 1475 | QualType Result |
| 1476 | = getSema().Context.getSubstTemplateTypeParmPackType(T, Arg); |
| 1477 | SubstTemplateTypeParmPackTypeLoc NewTL |
| 1478 | = TLB.push<SubstTemplateTypeParmPackTypeLoc>(Result); |
| 1479 | NewTL.setNameLoc(TL.getNameLoc()); |
| 1480 | return Result; |
| 1481 | } |
| 1482 | |
| 1483 | Arg = getPackSubstitutedTemplateArgument(getSema(), Arg); |
| 1484 | } |
| 1485 | |
| 1486 | (0) . __assert_fail ("Arg.getKind() == TemplateArgument..Type && \"Template argument kind mismatch\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 1487, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Arg.getKind() == TemplateArgument::Type && |
| 1487 | (0) . __assert_fail ("Arg.getKind() == TemplateArgument..Type && \"Template argument kind mismatch\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 1487, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Template argument kind mismatch"); |
| 1488 | |
| 1489 | QualType Replacement = Arg.getAsType(); |
| 1490 | |
| 1491 | |
| 1492 | QualType Result |
| 1493 | = getSema().Context.getSubstTemplateTypeParmType(T, Replacement); |
| 1494 | SubstTemplateTypeParmTypeLoc NewTL |
| 1495 | = TLB.push<SubstTemplateTypeParmTypeLoc>(Result); |
| 1496 | NewTL.setNameLoc(TL.getNameLoc()); |
| 1497 | return Result; |
| 1498 | } |
| 1499 | |
| 1500 | |
| 1501 | |
| 1502 | |
| 1503 | |
| 1504 | TemplateTypeParmDecl *NewTTPDecl = nullptr; |
| 1505 | if (TemplateTypeParmDecl *OldTTPDecl = T->getDecl()) |
| 1506 | NewTTPDecl = cast_or_null<TemplateTypeParmDecl>( |
| 1507 | TransformDecl(TL.getNameLoc(), OldTTPDecl)); |
| 1508 | |
| 1509 | QualType Result = getSema().Context.getTemplateTypeParmType( |
| 1510 | T->getDepth() - TemplateArgs.getNumSubstitutedLevels(), T->getIndex(), |
| 1511 | T->isParameterPack(), NewTTPDecl); |
| 1512 | TemplateTypeParmTypeLoc NewTL = TLB.push<TemplateTypeParmTypeLoc>(Result); |
| 1513 | NewTL.setNameLoc(TL.getNameLoc()); |
| 1514 | return Result; |
| 1515 | } |
| 1516 | |
| 1517 | QualType |
| 1518 | TemplateInstantiator::TransformSubstTemplateTypeParmPackType( |
| 1519 | TypeLocBuilder &TLB, |
| 1520 | SubstTemplateTypeParmPackTypeLoc TL) { |
| 1521 | if (getSema().ArgumentPackSubstitutionIndex == -1) { |
| 1522 | |
| 1523 | SubstTemplateTypeParmPackTypeLoc NewTL |
| 1524 | = TLB.push<SubstTemplateTypeParmPackTypeLoc>(TL.getType()); |
| 1525 | NewTL.setNameLoc(TL.getNameLoc()); |
| 1526 | return TL.getType(); |
| 1527 | } |
| 1528 | |
| 1529 | TemplateArgument Arg = TL.getTypePtr()->getArgumentPack(); |
| 1530 | Arg = getPackSubstitutedTemplateArgument(getSema(), Arg); |
| 1531 | QualType Result = Arg.getAsType(); |
| 1532 | |
| 1533 | Result = getSema().Context.getSubstTemplateTypeParmType( |
| 1534 | TL.getTypePtr()->getReplacedParameter(), |
| 1535 | Result); |
| 1536 | SubstTemplateTypeParmTypeLoc NewTL |
| 1537 | = TLB.push<SubstTemplateTypeParmTypeLoc>(Result); |
| 1538 | NewTL.setNameLoc(TL.getNameLoc()); |
| 1539 | return Result; |
| 1540 | } |
| 1541 | |
| 1542 | |
| 1543 | |
| 1544 | |
| 1545 | |
| 1546 | |
| 1547 | |
| 1548 | |
| 1549 | |
| 1550 | |
| 1551 | |
| 1552 | |
| 1553 | |
| 1554 | |
| 1555 | |
| 1556 | |
| 1557 | |
| 1558 | |
| 1559 | |
| 1560 | |
| 1561 | |
| 1562 | |
| 1563 | |
| 1564 | |
| 1565 | |
| 1566 | |
| 1567 | |
| 1568 | |
| 1569 | |
| 1570 | |
| 1571 | |
| 1572 | TypeSourceInfo *Sema::SubstType(TypeSourceInfo *T, |
| 1573 | const MultiLevelTemplateArgumentList &Args, |
| 1574 | SourceLocation Loc, |
| 1575 | DeclarationName Entity, |
| 1576 | bool AllowDeducedTST) { |
| 1577 | (0) . __assert_fail ("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 1579, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!CodeSynthesisContexts.empty() && |
| 1578 | (0) . __assert_fail ("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 1579, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Cannot perform an instantiation without some context on the " |
| 1579 | (0) . __assert_fail ("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 1579, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "instantiation stack"); |
| 1580 | |
| 1581 | if (!T->getType()->isInstantiationDependentType() && |
| 1582 | !T->getType()->isVariablyModifiedType()) |
| 1583 | return T; |
| 1584 | |
| 1585 | TemplateInstantiator Instantiator(*this, Args, Loc, Entity); |
| 1586 | return AllowDeducedTST ? Instantiator.TransformTypeWithDeducedTST(T) |
| 1587 | : Instantiator.TransformType(T); |
| 1588 | } |
| 1589 | |
| 1590 | TypeSourceInfo *Sema::SubstType(TypeLoc TL, |
| 1591 | const MultiLevelTemplateArgumentList &Args, |
| 1592 | SourceLocation Loc, |
| 1593 | DeclarationName Entity) { |
| 1594 | (0) . __assert_fail ("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 1596, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!CodeSynthesisContexts.empty() && |
| 1595 | (0) . __assert_fail ("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 1596, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Cannot perform an instantiation without some context on the " |
| 1596 | (0) . __assert_fail ("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 1596, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "instantiation stack"); |
| 1597 | |
| 1598 | if (TL.getType().isNull()) |
| 1599 | return nullptr; |
| 1600 | |
| 1601 | if (!TL.getType()->isInstantiationDependentType() && |
| 1602 | !TL.getType()->isVariablyModifiedType()) { |
| 1603 | |
| 1604 | |
| 1605 | TypeLocBuilder TLB; |
| 1606 | TLB.pushFullCopy(TL); |
| 1607 | return TLB.getTypeSourceInfo(Context, TL.getType()); |
| 1608 | } |
| 1609 | |
| 1610 | TemplateInstantiator Instantiator(*this, Args, Loc, Entity); |
| 1611 | TypeLocBuilder TLB; |
| 1612 | TLB.reserve(TL.getFullDataSize()); |
| 1613 | QualType Result = Instantiator.TransformType(TLB, TL); |
| 1614 | if (Result.isNull()) |
| 1615 | return nullptr; |
| 1616 | |
| 1617 | return TLB.getTypeSourceInfo(Context, Result); |
| 1618 | } |
| 1619 | |
| 1620 | |
| 1621 | QualType Sema::SubstType(QualType T, |
| 1622 | const MultiLevelTemplateArgumentList &TemplateArgs, |
| 1623 | SourceLocation Loc, DeclarationName Entity) { |
| 1624 | (0) . __assert_fail ("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 1626, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!CodeSynthesisContexts.empty() && |
| 1625 | (0) . __assert_fail ("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 1626, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Cannot perform an instantiation without some context on the " |
| 1626 | (0) . __assert_fail ("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 1626, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "instantiation stack"); |
| 1627 | |
| 1628 | |
| 1629 | |
| 1630 | if (!T->isInstantiationDependentType() && !T->isVariablyModifiedType()) |
| 1631 | return T; |
| 1632 | |
| 1633 | TemplateInstantiator Instantiator(*this, TemplateArgs, Loc, Entity); |
| 1634 | return Instantiator.TransformType(T); |
| 1635 | } |
| 1636 | |
| 1637 | static bool NeedsInstantiationAsFunctionType(TypeSourceInfo *T) { |
| 1638 | if (T->getType()->isInstantiationDependentType() || |
| 1639 | T->getType()->isVariablyModifiedType()) |
| 1640 | return true; |
| 1641 | |
| 1642 | TypeLoc TL = T->getTypeLoc().IgnoreParens(); |
| 1643 | if (!TL.getAs<FunctionProtoTypeLoc>()) |
| 1644 | return false; |
| 1645 | |
| 1646 | FunctionProtoTypeLoc FP = TL.castAs<FunctionProtoTypeLoc>(); |
| 1647 | for (ParmVarDecl *P : FP.getParams()) { |
| 1648 | |
| 1649 | if (!P) continue; |
| 1650 | |
| 1651 | |
| 1652 | |
| 1653 | return true; |
| 1654 | } |
| 1655 | |
| 1656 | return false; |
| 1657 | } |
| 1658 | |
| 1659 | |
| 1660 | |
| 1661 | |
| 1662 | |
| 1663 | TypeSourceInfo *Sema::SubstFunctionDeclType(TypeSourceInfo *T, |
| 1664 | const MultiLevelTemplateArgumentList &Args, |
| 1665 | SourceLocation Loc, |
| 1666 | DeclarationName Entity, |
| 1667 | CXXRecordDecl *ThisContext, |
| 1668 | Qualifiers ThisTypeQuals) { |
| 1669 | (0) . __assert_fail ("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 1671, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!CodeSynthesisContexts.empty() && |
| 1670 | (0) . __assert_fail ("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 1671, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Cannot perform an instantiation without some context on the " |
| 1671 | (0) . __assert_fail ("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 1671, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "instantiation stack"); |
| 1672 | |
| 1673 | if (!NeedsInstantiationAsFunctionType(T)) |
| 1674 | return T; |
| 1675 | |
| 1676 | TemplateInstantiator Instantiator(*this, Args, Loc, Entity); |
| 1677 | |
| 1678 | TypeLocBuilder TLB; |
| 1679 | |
| 1680 | TypeLoc TL = T->getTypeLoc(); |
| 1681 | TLB.reserve(TL.getFullDataSize()); |
| 1682 | |
| 1683 | QualType Result; |
| 1684 | |
| 1685 | if (FunctionProtoTypeLoc Proto = |
| 1686 | TL.IgnoreParens().getAs<FunctionProtoTypeLoc>()) { |
| 1687 | |
| 1688 | |
| 1689 | |
| 1690 | |
| 1691 | |
| 1692 | Result = Instantiator.TransformFunctionProtoType( |
| 1693 | TLB, Proto, ThisContext, ThisTypeQuals, |
| 1694 | [](FunctionProtoType::ExceptionSpecInfo &ESI, |
| 1695 | bool &Changed) { return false; }); |
| 1696 | } else { |
| 1697 | Result = Instantiator.TransformType(TLB, TL); |
| 1698 | } |
| 1699 | if (Result.isNull()) |
| 1700 | return nullptr; |
| 1701 | |
| 1702 | return TLB.getTypeSourceInfo(Context, Result); |
| 1703 | } |
| 1704 | |
| 1705 | bool Sema::SubstExceptionSpec(SourceLocation Loc, |
| 1706 | FunctionProtoType::ExceptionSpecInfo &ESI, |
| 1707 | SmallVectorImpl<QualType> &ExceptionStorage, |
| 1708 | const MultiLevelTemplateArgumentList &Args) { |
| 1709 | assert(ESI.Type != EST_Uninstantiated); |
| 1710 | |
| 1711 | bool Changed = false; |
| 1712 | TemplateInstantiator Instantiator(*this, Args, Loc, DeclarationName()); |
| 1713 | return Instantiator.TransformExceptionSpec(Loc, ESI, ExceptionStorage, |
| 1714 | Changed); |
| 1715 | } |
| 1716 | |
| 1717 | void Sema::SubstExceptionSpec(FunctionDecl *New, const FunctionProtoType *Proto, |
| 1718 | const MultiLevelTemplateArgumentList &Args) { |
| 1719 | FunctionProtoType::ExceptionSpecInfo ESI = |
| 1720 | Proto->getExtProtoInfo().ExceptionSpec; |
| 1721 | |
| 1722 | SmallVector<QualType, 4> ExceptionStorage; |
| 1723 | if (SubstExceptionSpec(New->getTypeSourceInfo()->getTypeLoc().getEndLoc(), |
| 1724 | ESI, ExceptionStorage, Args)) |
| 1725 | |
| 1726 | ESI.Type = EST_None; |
| 1727 | |
| 1728 | UpdateExceptionSpec(New, ESI); |
| 1729 | } |
| 1730 | |
| 1731 | ParmVarDecl *Sema::SubstParmVarDecl(ParmVarDecl *OldParm, |
| 1732 | const MultiLevelTemplateArgumentList &TemplateArgs, |
| 1733 | int indexAdjustment, |
| 1734 | Optional<unsigned> NumExpansions, |
| 1735 | bool ExpectParameterPack) { |
| 1736 | TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); |
| 1737 | TypeSourceInfo *NewDI = nullptr; |
| 1738 | |
| 1739 | TypeLoc OldTL = OldDI->getTypeLoc(); |
| 1740 | if (PackExpansionTypeLoc ExpansionTL = OldTL.getAs<PackExpansionTypeLoc>()) { |
| 1741 | |
| 1742 | |
| 1743 | |
| 1744 | NewDI = SubstType(ExpansionTL.getPatternLoc(), TemplateArgs, |
| 1745 | OldParm->getLocation(), OldParm->getDeclName()); |
| 1746 | if (!NewDI) |
| 1747 | return nullptr; |
| 1748 | |
| 1749 | if (NewDI->getType()->containsUnexpandedParameterPack()) { |
| 1750 | |
| 1751 | |
| 1752 | |
| 1753 | NewDI = CheckPackExpansion(NewDI, ExpansionTL.getEllipsisLoc(), |
| 1754 | NumExpansions); |
| 1755 | } else if (ExpectParameterPack) { |
| 1756 | |
| 1757 | |
| 1758 | |
| 1759 | |
| 1760 | Diag(OldParm->getLocation(), |
| 1761 | diag::err_function_parameter_pack_without_parameter_packs) |
| 1762 | << NewDI->getType(); |
| 1763 | return nullptr; |
| 1764 | } |
| 1765 | } else { |
| 1766 | NewDI = SubstType(OldDI, TemplateArgs, OldParm->getLocation(), |
| 1767 | OldParm->getDeclName()); |
| 1768 | } |
| 1769 | |
| 1770 | if (!NewDI) |
| 1771 | return nullptr; |
| 1772 | |
| 1773 | if (NewDI->getType()->isVoidType()) { |
| 1774 | Diag(OldParm->getLocation(), diag::err_param_with_void_type); |
| 1775 | return nullptr; |
| 1776 | } |
| 1777 | |
| 1778 | ParmVarDecl *NewParm = CheckParameter(Context.getTranslationUnitDecl(), |
| 1779 | OldParm->getInnerLocStart(), |
| 1780 | OldParm->getLocation(), |
| 1781 | OldParm->getIdentifier(), |
| 1782 | NewDI->getType(), NewDI, |
| 1783 | OldParm->getStorageClass()); |
| 1784 | if (!NewParm) |
| 1785 | return nullptr; |
| 1786 | |
| 1787 | |
| 1788 | if (OldParm->hasUninstantiatedDefaultArg()) { |
| 1789 | Expr *Arg = OldParm->getUninstantiatedDefaultArg(); |
| 1790 | NewParm->setUninstantiatedDefaultArg(Arg); |
| 1791 | } else if (OldParm->hasUnparsedDefaultArg()) { |
| 1792 | NewParm->setUnparsedDefaultArg(); |
| 1793 | UnparsedDefaultArgInstantiations[OldParm].push_back(NewParm); |
| 1794 | } else if (Expr *Arg = OldParm->getDefaultArg()) { |
| 1795 | FunctionDecl *OwningFunc = cast<FunctionDecl>(OldParm->getDeclContext()); |
| 1796 | if (OwningFunc->isLexicallyWithinFunctionOrMethod()) { |
| 1797 | |
| 1798 | |
| 1799 | Sema::ContextRAII SavedContext(*this, OwningFunc); |
| 1800 | LocalInstantiationScope Local(*this, true); |
| 1801 | ExprResult NewArg = SubstExpr(Arg, TemplateArgs); |
| 1802 | if (NewArg.isUsable()) { |
| 1803 | |
| 1804 | SourceLocation EqualLoc = NewArg.get()->getBeginLoc(); |
| 1805 | SetParamDefaultArgument(NewParm, NewArg.get(), EqualLoc); |
| 1806 | } |
| 1807 | } else { |
| 1808 | |
| 1809 | |
| 1810 | |
| 1811 | NewParm->setUninstantiatedDefaultArg(Arg); |
| 1812 | } |
| 1813 | } |
| 1814 | |
| 1815 | NewParm->setHasInheritedDefaultArg(OldParm->hasInheritedDefaultArg()); |
| 1816 | |
| 1817 | if (OldParm->isParameterPack() && !NewParm->isParameterPack()) { |
| 1818 | |
| 1819 | CurrentInstantiationScope->InstantiatedLocalPackArg(OldParm, NewParm); |
| 1820 | } else { |
| 1821 | |
| 1822 | CurrentInstantiationScope->InstantiatedLocal(OldParm, NewParm); |
| 1823 | } |
| 1824 | |
| 1825 | |
| 1826 | |
| 1827 | NewParm->setDeclContext(CurContext); |
| 1828 | |
| 1829 | NewParm->setScopeInfo(OldParm->getFunctionScopeDepth(), |
| 1830 | OldParm->getFunctionScopeIndex() + indexAdjustment); |
| 1831 | |
| 1832 | InstantiateAttrs(TemplateArgs, OldParm, NewParm); |
| 1833 | |
| 1834 | return NewParm; |
| 1835 | } |
| 1836 | |
| 1837 | |
| 1838 | |
| 1839 | |
| 1840 | bool Sema::SubstParmTypes( |
| 1841 | SourceLocation Loc, ArrayRef<ParmVarDecl *> Params, |
| 1842 | const FunctionProtoType::ExtParameterInfo *ExtParamInfos, |
| 1843 | const MultiLevelTemplateArgumentList &TemplateArgs, |
| 1844 | SmallVectorImpl<QualType> &ParamTypes, |
| 1845 | SmallVectorImpl<ParmVarDecl *> *OutParams, |
| 1846 | ExtParameterInfoBuilder &ParamInfos) { |
| 1847 | (0) . __assert_fail ("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 1849, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!CodeSynthesisContexts.empty() && |
| 1848 | (0) . __assert_fail ("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 1849, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Cannot perform an instantiation without some context on the " |
| 1849 | (0) . __assert_fail ("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 1849, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "instantiation stack"); |
| 1850 | |
| 1851 | TemplateInstantiator Instantiator(*this, TemplateArgs, Loc, |
| 1852 | DeclarationName()); |
| 1853 | return Instantiator.TransformFunctionTypeParams( |
| 1854 | Loc, Params, nullptr, ExtParamInfos, ParamTypes, OutParams, ParamInfos); |
| 1855 | } |
| 1856 | |
| 1857 | |
| 1858 | |
| 1859 | |
| 1860 | |
| 1861 | |
| 1862 | |
| 1863 | bool |
| 1864 | Sema::SubstBaseSpecifiers(CXXRecordDecl *Instantiation, |
| 1865 | CXXRecordDecl *Pattern, |
| 1866 | const MultiLevelTemplateArgumentList &TemplateArgs) { |
| 1867 | bool Invalid = false; |
| 1868 | SmallVector<CXXBaseSpecifier*, 4> InstantiatedBases; |
| 1869 | for (const auto &Base : Pattern->bases()) { |
| 1870 | if (!Base.getType()->isDependentType()) { |
| 1871 | if (const CXXRecordDecl *RD = Base.getType()->getAsCXXRecordDecl()) { |
| 1872 | if (RD->isInvalidDecl()) |
| 1873 | Instantiation->setInvalidDecl(); |
| 1874 | } |
| 1875 | InstantiatedBases.push_back(new (Context) CXXBaseSpecifier(Base)); |
| 1876 | continue; |
| 1877 | } |
| 1878 | |
| 1879 | SourceLocation EllipsisLoc; |
| 1880 | TypeSourceInfo *BaseTypeLoc; |
| 1881 | if (Base.isPackExpansion()) { |
| 1882 | |
| 1883 | |
| 1884 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 1885 | collectUnexpandedParameterPacks(Base.getTypeSourceInfo()->getTypeLoc(), |
| 1886 | Unexpanded); |
| 1887 | bool ShouldExpand = false; |
| 1888 | bool RetainExpansion = false; |
| 1889 | Optional<unsigned> NumExpansions; |
| 1890 | if (CheckParameterPacksForExpansion(Base.getEllipsisLoc(), |
| 1891 | Base.getSourceRange(), |
| 1892 | Unexpanded, |
| 1893 | TemplateArgs, ShouldExpand, |
| 1894 | RetainExpansion, |
| 1895 | NumExpansions)) { |
| 1896 | Invalid = true; |
| 1897 | continue; |
| 1898 | } |
| 1899 | |
| 1900 | |
| 1901 | if (ShouldExpand) { |
| 1902 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 1903 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(*this, I); |
| 1904 | |
| 1905 | TypeSourceInfo *BaseTypeLoc = SubstType(Base.getTypeSourceInfo(), |
| 1906 | TemplateArgs, |
| 1907 | Base.getSourceRange().getBegin(), |
| 1908 | DeclarationName()); |
| 1909 | if (!BaseTypeLoc) { |
| 1910 | Invalid = true; |
| 1911 | continue; |
| 1912 | } |
| 1913 | |
| 1914 | if (CXXBaseSpecifier *InstantiatedBase |
| 1915 | = CheckBaseSpecifier(Instantiation, |
| 1916 | Base.getSourceRange(), |
| 1917 | Base.isVirtual(), |
| 1918 | Base.getAccessSpecifierAsWritten(), |
| 1919 | BaseTypeLoc, |
| 1920 | SourceLocation())) |
| 1921 | InstantiatedBases.push_back(InstantiatedBase); |
| 1922 | else |
| 1923 | Invalid = true; |
| 1924 | } |
| 1925 | |
| 1926 | continue; |
| 1927 | } |
| 1928 | |
| 1929 | |
| 1930 | EllipsisLoc = Base.getEllipsisLoc(); |
| 1931 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(*this, -1); |
| 1932 | BaseTypeLoc = SubstType(Base.getTypeSourceInfo(), |
| 1933 | TemplateArgs, |
| 1934 | Base.getSourceRange().getBegin(), |
| 1935 | DeclarationName()); |
| 1936 | } else { |
| 1937 | BaseTypeLoc = SubstType(Base.getTypeSourceInfo(), |
| 1938 | TemplateArgs, |
| 1939 | Base.getSourceRange().getBegin(), |
| 1940 | DeclarationName()); |
| 1941 | } |
| 1942 | |
| 1943 | if (!BaseTypeLoc) { |
| 1944 | Invalid = true; |
| 1945 | continue; |
| 1946 | } |
| 1947 | |
| 1948 | if (CXXBaseSpecifier *InstantiatedBase |
| 1949 | = CheckBaseSpecifier(Instantiation, |
| 1950 | Base.getSourceRange(), |
| 1951 | Base.isVirtual(), |
| 1952 | Base.getAccessSpecifierAsWritten(), |
| 1953 | BaseTypeLoc, |
| 1954 | EllipsisLoc)) |
| 1955 | InstantiatedBases.push_back(InstantiatedBase); |
| 1956 | else |
| 1957 | Invalid = true; |
| 1958 | } |
| 1959 | |
| 1960 | if (!Invalid && AttachBaseSpecifiers(Instantiation, InstantiatedBases)) |
| 1961 | Invalid = true; |
| 1962 | |
| 1963 | return Invalid; |
| 1964 | } |
| 1965 | |
| 1966 | |
| 1967 | namespace clang { |
| 1968 | namespace sema { |
| 1969 | Attr *instantiateTemplateAttribute(const Attr *At, ASTContext &C, Sema &S, |
| 1970 | const MultiLevelTemplateArgumentList &TemplateArgs); |
| 1971 | Attr *instantiateTemplateAttributeForDecl( |
| 1972 | const Attr *At, ASTContext &C, Sema &S, |
| 1973 | const MultiLevelTemplateArgumentList &TemplateArgs); |
| 1974 | } |
| 1975 | } |
| 1976 | |
| 1977 | |
| 1978 | |
| 1979 | |
| 1980 | |
| 1981 | |
| 1982 | |
| 1983 | |
| 1984 | |
| 1985 | |
| 1986 | |
| 1987 | |
| 1988 | |
| 1989 | |
| 1990 | |
| 1991 | |
| 1992 | |
| 1993 | |
| 1994 | |
| 1995 | |
| 1996 | |
| 1997 | |
| 1998 | |
| 1999 | bool |
| 2000 | Sema::InstantiateClass(SourceLocation PointOfInstantiation, |
| 2001 | CXXRecordDecl *Instantiation, CXXRecordDecl *Pattern, |
| 2002 | const MultiLevelTemplateArgumentList &TemplateArgs, |
| 2003 | TemplateSpecializationKind TSK, |
| 2004 | bool Complain) { |
| 2005 | CXXRecordDecl *PatternDef |
| 2006 | = cast_or_null<CXXRecordDecl>(Pattern->getDefinition()); |
| 2007 | if (DiagnoseUninstantiableTemplate(PointOfInstantiation, Instantiation, |
| 2008 | Instantiation->getInstantiatedFromMemberClass(), |
| 2009 | Pattern, PatternDef, TSK, Complain)) |
| 2010 | return true; |
| 2011 | Pattern = PatternDef; |
| 2012 | |
| 2013 | |
| 2014 | if (MemberSpecializationInfo *MSInfo |
| 2015 | = Instantiation->getMemberSpecializationInfo()) { |
| 2016 | MSInfo->setTemplateSpecializationKind(TSK); |
| 2017 | MSInfo->setPointOfInstantiation(PointOfInstantiation); |
| 2018 | } else if (ClassTemplateSpecializationDecl *Spec |
| 2019 | = dyn_cast<ClassTemplateSpecializationDecl>(Instantiation)) { |
| 2020 | Spec->setTemplateSpecializationKind(TSK); |
| 2021 | Spec->setPointOfInstantiation(PointOfInstantiation); |
| 2022 | } |
| 2023 | |
| 2024 | InstantiatingTemplate Inst(*this, PointOfInstantiation, Instantiation); |
| 2025 | if (Inst.isInvalid()) |
| 2026 | return true; |
| 2027 | (0) . __assert_fail ("!Inst.isAlreadyInstantiating() && \"should have been caught by caller\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 2027, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!Inst.isAlreadyInstantiating() && "should have been caught by caller"); |
| 2028 | PrettyDeclStackTraceEntry CrashInfo(Context, Instantiation, SourceLocation(), |
| 2029 | "instantiating class definition"); |
| 2030 | |
| 2031 | |
| 2032 | |
| 2033 | ContextRAII SavedContext(*this, Instantiation); |
| 2034 | EnterExpressionEvaluationContext EvalContext( |
| 2035 | *this, Sema::ExpressionEvaluationContext::PotentiallyEvaluated); |
| 2036 | |
| 2037 | |
| 2038 | |
| 2039 | |
| 2040 | bool MergeWithParentScope = !Instantiation->isDefinedOutsideFunctionOrMethod(); |
| 2041 | LocalInstantiationScope Scope(*this, MergeWithParentScope); |
| 2042 | |
| 2043 | |
| 2044 | |
| 2045 | |
| 2046 | |
| 2047 | SavePendingParsedClassStateRAII SavedPendingParsedClassState(*this); |
| 2048 | |
| 2049 | |
| 2050 | InstantiateAttrs(TemplateArgs, Pattern, Instantiation); |
| 2051 | |
| 2052 | |
| 2053 | Instantiation->startDefinition(); |
| 2054 | |
| 2055 | |
| 2056 | |
| 2057 | Instantiation->setVisibleDespiteOwningModule(); |
| 2058 | |
| 2059 | |
| 2060 | Instantiation->setTagKind(Pattern->getTagKind()); |
| 2061 | |
| 2062 | |
| 2063 | if (SubstBaseSpecifiers(Instantiation, Pattern, TemplateArgs)) |
| 2064 | Instantiation->setInvalidDecl(); |
| 2065 | |
| 2066 | TemplateDeclInstantiator Instantiator(*this, Instantiation, TemplateArgs); |
| 2067 | SmallVector<Decl*, 4> Fields; |
| 2068 | |
| 2069 | LateInstantiatedAttrVec LateAttrs; |
| 2070 | Instantiator.enableLateAttributeInstantiation(&LateAttrs); |
| 2071 | |
| 2072 | for (auto *Member : Pattern->decls()) { |
| 2073 | |
| 2074 | |
| 2075 | |
| 2076 | |
| 2077 | |
| 2078 | |
| 2079 | |
| 2080 | |
| 2081 | |
| 2082 | if (Member->getDeclContext() != Pattern) |
| 2083 | continue; |
| 2084 | |
| 2085 | |
| 2086 | |
| 2087 | if (isa<BlockDecl>(Member)) |
| 2088 | continue; |
| 2089 | |
| 2090 | if (Member->isInvalidDecl()) { |
| 2091 | Instantiation->setInvalidDecl(); |
| 2092 | continue; |
| 2093 | } |
| 2094 | |
| 2095 | Decl *NewMember = Instantiator.Visit(Member); |
| 2096 | if (NewMember) { |
| 2097 | if (FieldDecl *Field = dyn_cast<FieldDecl>(NewMember)) { |
| 2098 | Fields.push_back(Field); |
| 2099 | } else if (EnumDecl *Enum = dyn_cast<EnumDecl>(NewMember)) { |
| 2100 | |
| 2101 | |
| 2102 | |
| 2103 | |
| 2104 | if (TSK == TSK_ImplicitInstantiation && !Enum->isScoped() && |
| 2105 | Enum->isCompleteDefinition()) { |
| 2106 | MemberSpecializationInfo *MSInfo =Enum->getMemberSpecializationInfo(); |
| 2107 | (0) . __assert_fail ("MSInfo && \"no spec info for member enum specialization\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 2107, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(MSInfo && "no spec info for member enum specialization"); |
| 2108 | MSInfo->setTemplateSpecializationKind(TSK_ImplicitInstantiation); |
| 2109 | MSInfo->setPointOfInstantiation(PointOfInstantiation); |
| 2110 | } |
| 2111 | } else if (StaticAssertDecl *SA = dyn_cast<StaticAssertDecl>(NewMember)) { |
| 2112 | if (SA->isFailed()) { |
| 2113 | |
| 2114 | |
| 2115 | Instantiation->setInvalidDecl(); |
| 2116 | break; |
| 2117 | } |
| 2118 | } |
| 2119 | |
| 2120 | if (NewMember->isInvalidDecl()) |
| 2121 | Instantiation->setInvalidDecl(); |
| 2122 | } else { |
| 2123 | |
| 2124 | |
| 2125 | |
| 2126 | |
| 2127 | } |
| 2128 | } |
| 2129 | |
| 2130 | |
| 2131 | ActOnFields(nullptr, Instantiation->getLocation(), Instantiation, Fields, |
| 2132 | SourceLocation(), SourceLocation(), ParsedAttributesView()); |
| 2133 | CheckCompletedCXXClass(Instantiation); |
| 2134 | |
| 2135 | |
| 2136 | |
| 2137 | ActOnFinishCXXNonNestedClass(Instantiation); |
| 2138 | |
| 2139 | |
| 2140 | |
| 2141 | for (LateInstantiatedAttrVec::iterator I = LateAttrs.begin(), |
| 2142 | E = LateAttrs.end(); I != E; ++I) { |
| 2143 | assert(CurrentInstantiationScope == Instantiator.getStartingScope()); |
| 2144 | CurrentInstantiationScope = I->Scope; |
| 2145 | |
| 2146 | |
| 2147 | NamedDecl *ND = dyn_cast<NamedDecl>(I->NewDecl); |
| 2148 | CXXRecordDecl *ThisContext = |
| 2149 | dyn_cast_or_null<CXXRecordDecl>(ND->getDeclContext()); |
| 2150 | CXXThisScopeRAII ThisScope(*this, ThisContext, Qualifiers(), |
| 2151 | ND && ND->isCXXInstanceMember()); |
| 2152 | |
| 2153 | Attr *NewAttr = |
| 2154 | instantiateTemplateAttribute(I->TmplAttr, Context, *this, TemplateArgs); |
| 2155 | I->NewDecl->addAttr(NewAttr); |
| 2156 | LocalInstantiationScope::deleteScopes(I->Scope, |
| 2157 | Instantiator.getStartingScope()); |
| 2158 | } |
| 2159 | Instantiator.disableLateAttributeInstantiation(); |
| 2160 | LateAttrs.clear(); |
| 2161 | |
| 2162 | ActOnFinishDelayedMemberInitializers(Instantiation); |
| 2163 | |
| 2164 | |
| 2165 | |
| 2166 | if (TSK == TSK_ImplicitInstantiation) { |
| 2167 | Instantiation->setLocation(Pattern->getLocation()); |
| 2168 | Instantiation->setLocStart(Pattern->getInnerLocStart()); |
| 2169 | Instantiation->setBraceRange(Pattern->getBraceRange()); |
| 2170 | } |
| 2171 | |
| 2172 | if (!Instantiation->isInvalidDecl()) { |
| 2173 | |
| 2174 | PerformDependentDiagnostics(Pattern, TemplateArgs); |
| 2175 | |
| 2176 | |
| 2177 | |
| 2178 | for (TemplateDeclInstantiator::delayed_partial_spec_iterator |
| 2179 | P = Instantiator.delayed_partial_spec_begin(), |
| 2180 | PEnd = Instantiator.delayed_partial_spec_end(); |
| 2181 | P != PEnd; ++P) { |
| 2182 | if (!Instantiator.InstantiateClassTemplatePartialSpecialization( |
| 2183 | P->first, P->second)) { |
| 2184 | Instantiation->setInvalidDecl(); |
| 2185 | break; |
| 2186 | } |
| 2187 | } |
| 2188 | |
| 2189 | |
| 2190 | |
| 2191 | for (TemplateDeclInstantiator::delayed_var_partial_spec_iterator |
| 2192 | P = Instantiator.delayed_var_partial_spec_begin(), |
| 2193 | PEnd = Instantiator.delayed_var_partial_spec_end(); |
| 2194 | P != PEnd; ++P) { |
| 2195 | if (!Instantiator.InstantiateVarTemplatePartialSpecialization( |
| 2196 | P->first, P->second)) { |
| 2197 | Instantiation->setInvalidDecl(); |
| 2198 | break; |
| 2199 | } |
| 2200 | } |
| 2201 | } |
| 2202 | |
| 2203 | |
| 2204 | SavedContext.pop(); |
| 2205 | |
| 2206 | if (!Instantiation->isInvalidDecl()) { |
| 2207 | Consumer.HandleTagDeclDefinition(Instantiation); |
| 2208 | |
| 2209 | |
| 2210 | |
| 2211 | if (TSK == TSK_ExplicitInstantiationDefinition) |
| 2212 | MarkVTableUsed(PointOfInstantiation, Instantiation, true); |
| 2213 | } |
| 2214 | |
| 2215 | return Instantiation->isInvalidDecl(); |
| 2216 | } |
| 2217 | |
| 2218 | |
| 2219 | |
| 2220 | |
| 2221 | |
| 2222 | |
| 2223 | |
| 2224 | |
| 2225 | |
| 2226 | |
| 2227 | |
| 2228 | |
| 2229 | |
| 2230 | |
| 2231 | |
| 2232 | |
| 2233 | bool Sema::InstantiateEnum(SourceLocation PointOfInstantiation, |
| 2234 | EnumDecl *Instantiation, EnumDecl *Pattern, |
| 2235 | const MultiLevelTemplateArgumentList &TemplateArgs, |
| 2236 | TemplateSpecializationKind TSK) { |
| 2237 | EnumDecl *PatternDef = Pattern->getDefinition(); |
| 2238 | if (DiagnoseUninstantiableTemplate(PointOfInstantiation, Instantiation, |
| 2239 | Instantiation->getInstantiatedFromMemberEnum(), |
| 2240 | Pattern, PatternDef, TSK,)) |
| 2241 | return true; |
| 2242 | Pattern = PatternDef; |
| 2243 | |
| 2244 | |
| 2245 | if (MemberSpecializationInfo *MSInfo |
| 2246 | = Instantiation->getMemberSpecializationInfo()) { |
| 2247 | MSInfo->setTemplateSpecializationKind(TSK); |
| 2248 | MSInfo->setPointOfInstantiation(PointOfInstantiation); |
| 2249 | } |
| 2250 | |
| 2251 | InstantiatingTemplate Inst(*this, PointOfInstantiation, Instantiation); |
| 2252 | if (Inst.isInvalid()) |
| 2253 | return true; |
| 2254 | if (Inst.isAlreadyInstantiating()) |
| 2255 | return false; |
| 2256 | PrettyDeclStackTraceEntry CrashInfo(Context, Instantiation, SourceLocation(), |
| 2257 | "instantiating enum definition"); |
| 2258 | |
| 2259 | |
| 2260 | |
| 2261 | Instantiation->setVisibleDespiteOwningModule(); |
| 2262 | |
| 2263 | |
| 2264 | |
| 2265 | ContextRAII SavedContext(*this, Instantiation); |
| 2266 | EnterExpressionEvaluationContext EvalContext( |
| 2267 | *this, Sema::ExpressionEvaluationContext::PotentiallyEvaluated); |
| 2268 | |
| 2269 | LocalInstantiationScope Scope(*this, ); |
| 2270 | |
| 2271 | |
| 2272 | InstantiateAttrs(TemplateArgs, Pattern, Instantiation); |
| 2273 | |
| 2274 | TemplateDeclInstantiator Instantiator(*this, Instantiation, TemplateArgs); |
| 2275 | Instantiator.InstantiateEnumDefinition(Instantiation, Pattern); |
| 2276 | |
| 2277 | |
| 2278 | SavedContext.pop(); |
| 2279 | |
| 2280 | return Instantiation->isInvalidDecl(); |
| 2281 | } |
| 2282 | |
| 2283 | |
| 2284 | |
| 2285 | |
| 2286 | |
| 2287 | |
| 2288 | |
| 2289 | |
| 2290 | |
| 2291 | |
| 2292 | |
| 2293 | |
| 2294 | |
| 2295 | |
| 2296 | |
| 2297 | |
| 2298 | bool Sema::InstantiateInClassInitializer( |
| 2299 | SourceLocation PointOfInstantiation, FieldDecl *Instantiation, |
| 2300 | FieldDecl *Pattern, const MultiLevelTemplateArgumentList &TemplateArgs) { |
| 2301 | |
| 2302 | if (!Pattern->hasInClassInitializer()) |
| 2303 | return false; |
| 2304 | |
| 2305 | (0) . __assert_fail ("Instantiation->getInClassInitStyle() == Pattern->getInClassInitStyle() && \"pattern and instantiation disagree about init style\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 2307, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Instantiation->getInClassInitStyle() == |
| 2306 | (0) . __assert_fail ("Instantiation->getInClassInitStyle() == Pattern->getInClassInitStyle() && \"pattern and instantiation disagree about init style\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 2307, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> Pattern->getInClassInitStyle() && |
| 2307 | (0) . __assert_fail ("Instantiation->getInClassInitStyle() == Pattern->getInClassInitStyle() && \"pattern and instantiation disagree about init style\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 2307, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "pattern and instantiation disagree about init style"); |
| 2308 | |
| 2309 | |
| 2310 | |
| 2311 | Expr *OldInit = Pattern->getInClassInitializer(); |
| 2312 | if (!OldInit) { |
| 2313 | RecordDecl *PatternRD = Pattern->getParent(); |
| 2314 | RecordDecl *OutermostClass = PatternRD->getOuterLexicalRecordContext(); |
| 2315 | Diag(PointOfInstantiation, |
| 2316 | diag::err_in_class_initializer_not_yet_parsed) |
| 2317 | << OutermostClass << Pattern; |
| 2318 | Diag(Pattern->getEndLoc(), diag::note_in_class_initializer_not_yet_parsed); |
| 2319 | Instantiation->setInvalidDecl(); |
| 2320 | return true; |
| 2321 | } |
| 2322 | |
| 2323 | InstantiatingTemplate Inst(*this, PointOfInstantiation, Instantiation); |
| 2324 | if (Inst.isInvalid()) |
| 2325 | return true; |
| 2326 | if (Inst.isAlreadyInstantiating()) { |
| 2327 | |
| 2328 | Diag(PointOfInstantiation, diag::err_in_class_initializer_cycle) |
| 2329 | << Instantiation; |
| 2330 | return true; |
| 2331 | } |
| 2332 | PrettyDeclStackTraceEntry CrashInfo(Context, Instantiation, SourceLocation(), |
| 2333 | "instantiating default member init"); |
| 2334 | |
| 2335 | |
| 2336 | |
| 2337 | ContextRAII SavedContext(*this, Instantiation->getParent()); |
| 2338 | EnterExpressionEvaluationContext EvalContext( |
| 2339 | *this, Sema::ExpressionEvaluationContext::PotentiallyEvaluated); |
| 2340 | |
| 2341 | LocalInstantiationScope Scope(*this, true); |
| 2342 | |
| 2343 | |
| 2344 | ActOnStartCXXInClassMemberInitializer(); |
| 2345 | CXXThisScopeRAII ThisScope(*this, Instantiation->getParent(), Qualifiers()); |
| 2346 | |
| 2347 | ExprResult NewInit = SubstInitializer(OldInit, TemplateArgs, |
| 2348 | ); |
| 2349 | Expr *Init = NewInit.get(); |
| 2350 | (0) . __assert_fail ("(!Init || !isa(Init)) && \"call-style init in class\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 2350, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert((!Init || !isa<ParenListExpr>(Init)) && "call-style init in class"); |
| 2351 | ActOnFinishCXXInClassMemberInitializer( |
| 2352 | Instantiation, Init ? Init->getBeginLoc() : SourceLocation(), Init); |
| 2353 | |
| 2354 | if (auto *L = getASTMutationListener()) |
| 2355 | L->DefaultMemberInitializerInstantiated(Instantiation); |
| 2356 | |
| 2357 | |
| 2358 | return !Instantiation->getInClassInitializer(); |
| 2359 | } |
| 2360 | |
| 2361 | namespace { |
| 2362 | |
| 2363 | |
| 2364 | struct PartialSpecMatchResult { |
| 2365 | ClassTemplatePartialSpecializationDecl *Partial; |
| 2366 | TemplateArgumentList *Args; |
| 2367 | }; |
| 2368 | } |
| 2369 | |
| 2370 | bool Sema::usesPartialOrExplicitSpecialization( |
| 2371 | SourceLocation Loc, ClassTemplateSpecializationDecl *ClassTemplateSpec) { |
| 2372 | if (ClassTemplateSpec->getTemplateSpecializationKind() == |
| 2373 | TSK_ExplicitSpecialization) |
| 2374 | return true; |
| 2375 | |
| 2376 | SmallVector<ClassTemplatePartialSpecializationDecl *, 4> PartialSpecs; |
| 2377 | ClassTemplateSpec->getSpecializedTemplate() |
| 2378 | ->getPartialSpecializations(PartialSpecs); |
| 2379 | for (unsigned I = 0, N = PartialSpecs.size(); I != N; ++I) { |
| 2380 | TemplateDeductionInfo Info(Loc); |
| 2381 | if (!DeduceTemplateArguments(PartialSpecs[I], |
| 2382 | ClassTemplateSpec->getTemplateArgs(), Info)) |
| 2383 | return true; |
| 2384 | } |
| 2385 | |
| 2386 | return false; |
| 2387 | } |
| 2388 | |
| 2389 | |
| 2390 | |
| 2391 | |
| 2392 | static CXXRecordDecl * |
| 2393 | getPatternForClassTemplateSpecialization( |
| 2394 | Sema &S, SourceLocation PointOfInstantiation, |
| 2395 | ClassTemplateSpecializationDecl *ClassTemplateSpec, |
| 2396 | TemplateSpecializationKind TSK, bool Complain) { |
| 2397 | Sema::InstantiatingTemplate Inst(S, PointOfInstantiation, ClassTemplateSpec); |
| 2398 | if (Inst.isInvalid() || Inst.isAlreadyInstantiating()) |
| 2399 | return nullptr; |
| 2400 | |
| 2401 | llvm::PointerUnion<ClassTemplateDecl *, |
| 2402 | ClassTemplatePartialSpecializationDecl *> |
| 2403 | Specialized = ClassTemplateSpec->getSpecializedTemplateOrPartial(); |
| 2404 | if (!Specialized.is<ClassTemplatePartialSpecializationDecl *>()) { |
| 2405 | |
| 2406 | ClassTemplateDecl *Template = ClassTemplateSpec->getSpecializedTemplate(); |
| 2407 | |
| 2408 | |
| 2409 | |
| 2410 | |
| 2411 | |
| 2412 | |
| 2413 | |
| 2414 | |
| 2415 | |
| 2416 | typedef PartialSpecMatchResult MatchResult; |
| 2417 | SmallVector<MatchResult, 4> Matched; |
| 2418 | SmallVector<ClassTemplatePartialSpecializationDecl *, 4> PartialSpecs; |
| 2419 | Template->getPartialSpecializations(PartialSpecs); |
| 2420 | TemplateSpecCandidateSet FailedCandidates(PointOfInstantiation); |
| 2421 | for (unsigned I = 0, N = PartialSpecs.size(); I != N; ++I) { |
| 2422 | ClassTemplatePartialSpecializationDecl *Partial = PartialSpecs[I]; |
| 2423 | TemplateDeductionInfo Info(FailedCandidates.getLocation()); |
| 2424 | if (Sema::TemplateDeductionResult Result = S.DeduceTemplateArguments( |
| 2425 | Partial, ClassTemplateSpec->getTemplateArgs(), Info)) { |
| 2426 | |
| 2427 | |
| 2428 | FailedCandidates.addCandidate().set( |
| 2429 | DeclAccessPair::make(Template, AS_public), Partial, |
| 2430 | MakeDeductionFailureInfo(S.Context, Result, Info)); |
| 2431 | (void)Result; |
| 2432 | } else { |
| 2433 | Matched.push_back(PartialSpecMatchResult()); |
| 2434 | Matched.back().Partial = Partial; |
| 2435 | Matched.back().Args = Info.take(); |
| 2436 | } |
| 2437 | } |
| 2438 | |
| 2439 | |
| 2440 | |
| 2441 | |
| 2442 | |
| 2443 | if (Matched.size() >= 1) { |
| 2444 | SmallVectorImpl<MatchResult>::iterator Best = Matched.begin(); |
| 2445 | if (Matched.size() == 1) { |
| 2446 | |
| 2447 | |
| 2448 | |
| 2449 | } else { |
| 2450 | |
| 2451 | |
| 2452 | |
| 2453 | |
| 2454 | |
| 2455 | |
| 2456 | |
| 2457 | for (SmallVectorImpl<MatchResult>::iterator P = Best + 1, |
| 2458 | PEnd = Matched.end(); |
| 2459 | P != PEnd; ++P) { |
| 2460 | if (S.getMoreSpecializedPartialSpecialization( |
| 2461 | P->Partial, Best->Partial, PointOfInstantiation) == |
| 2462 | P->Partial) |
| 2463 | Best = P; |
| 2464 | } |
| 2465 | |
| 2466 | |
| 2467 | |
| 2468 | bool Ambiguous = false; |
| 2469 | for (SmallVectorImpl<MatchResult>::iterator P = Matched.begin(), |
| 2470 | PEnd = Matched.end(); |
| 2471 | P != PEnd; ++P) { |
| 2472 | if (P != Best && S.getMoreSpecializedPartialSpecialization( |
| 2473 | P->Partial, Best->Partial, |
| 2474 | PointOfInstantiation) != Best->Partial) { |
| 2475 | Ambiguous = true; |
| 2476 | break; |
| 2477 | } |
| 2478 | } |
| 2479 | |
| 2480 | if (Ambiguous) { |
| 2481 | |
| 2482 | Inst.Clear(); |
| 2483 | ClassTemplateSpec->setInvalidDecl(); |
| 2484 | S.Diag(PointOfInstantiation, |
| 2485 | diag::err_partial_spec_ordering_ambiguous) |
| 2486 | << ClassTemplateSpec; |
| 2487 | |
| 2488 | |
| 2489 | for (SmallVectorImpl<MatchResult>::iterator P = Matched.begin(), |
| 2490 | PEnd = Matched.end(); |
| 2491 | P != PEnd; ++P) |
| 2492 | S.Diag(P->Partial->getLocation(), diag::note_partial_spec_match) |
| 2493 | << S.getTemplateArgumentBindingsText( |
| 2494 | P->Partial->getTemplateParameters(), *P->Args); |
| 2495 | |
| 2496 | return nullptr; |
| 2497 | } |
| 2498 | } |
| 2499 | |
| 2500 | ClassTemplateSpec->setInstantiationOf(Best->Partial, Best->Args); |
| 2501 | } else { |
| 2502 | |
| 2503 | |
| 2504 | } |
| 2505 | } |
| 2506 | |
| 2507 | CXXRecordDecl *Pattern = nullptr; |
| 2508 | Specialized = ClassTemplateSpec->getSpecializedTemplateOrPartial(); |
| 2509 | if (auto *PartialSpec = |
| 2510 | Specialized.dyn_cast<ClassTemplatePartialSpecializationDecl *>()) { |
| 2511 | |
| 2512 | while (PartialSpec->getInstantiatedFromMember()) { |
| 2513 | |
| 2514 | |
| 2515 | if (PartialSpec->isMemberSpecialization()) |
| 2516 | break; |
| 2517 | |
| 2518 | PartialSpec = PartialSpec->getInstantiatedFromMember(); |
| 2519 | } |
| 2520 | Pattern = PartialSpec; |
| 2521 | } else { |
| 2522 | ClassTemplateDecl *Template = ClassTemplateSpec->getSpecializedTemplate(); |
| 2523 | while (Template->getInstantiatedFromMemberTemplate()) { |
| 2524 | |
| 2525 | |
| 2526 | if (Template->isMemberSpecialization()) |
| 2527 | break; |
| 2528 | |
| 2529 | Template = Template->getInstantiatedFromMemberTemplate(); |
| 2530 | } |
| 2531 | Pattern = Template->getTemplatedDecl(); |
| 2532 | } |
| 2533 | |
| 2534 | return Pattern; |
| 2535 | } |
| 2536 | |
| 2537 | bool Sema::InstantiateClassTemplateSpecialization( |
| 2538 | SourceLocation PointOfInstantiation, |
| 2539 | ClassTemplateSpecializationDecl *ClassTemplateSpec, |
| 2540 | TemplateSpecializationKind TSK, bool Complain) { |
| 2541 | |
| 2542 | ClassTemplateSpec = cast<ClassTemplateSpecializationDecl>( |
| 2543 | ClassTemplateSpec->getCanonicalDecl()); |
| 2544 | if (ClassTemplateSpec->isInvalidDecl()) |
| 2545 | return true; |
| 2546 | |
| 2547 | CXXRecordDecl *Pattern = getPatternForClassTemplateSpecialization( |
| 2548 | *this, PointOfInstantiation, ClassTemplateSpec, TSK, Complain); |
| 2549 | if (!Pattern) |
| 2550 | return true; |
| 2551 | |
| 2552 | return InstantiateClass(PointOfInstantiation, ClassTemplateSpec, Pattern, |
| 2553 | getTemplateInstantiationArgs(ClassTemplateSpec), TSK, |
| 2554 | Complain); |
| 2555 | } |
| 2556 | |
| 2557 | |
| 2558 | |
| 2559 | |
| 2560 | void |
| 2561 | Sema::InstantiateClassMembers(SourceLocation PointOfInstantiation, |
| 2562 | CXXRecordDecl *Instantiation, |
| 2563 | const MultiLevelTemplateArgumentList &TemplateArgs, |
| 2564 | TemplateSpecializationKind TSK) { |
| 2565 | |
| 2566 | |
| 2567 | |
| 2568 | (0) . __assert_fail ("(TSK == TSK_ExplicitInstantiationDefinition || TSK == TSK_ExplicitInstantiationDeclaration || (TSK == TSK_ImplicitInstantiation && Instantiation->isLocalClass())) && \"Unexpected template specialization kind!\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 2572, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert( |
| 2569 | (0) . __assert_fail ("(TSK == TSK_ExplicitInstantiationDefinition || TSK == TSK_ExplicitInstantiationDeclaration || (TSK == TSK_ImplicitInstantiation && Instantiation->isLocalClass())) && \"Unexpected template specialization kind!\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 2572, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> (TSK == TSK_ExplicitInstantiationDefinition || |
| 2570 | (0) . __assert_fail ("(TSK == TSK_ExplicitInstantiationDefinition || TSK == TSK_ExplicitInstantiationDeclaration || (TSK == TSK_ImplicitInstantiation && Instantiation->isLocalClass())) && \"Unexpected template specialization kind!\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 2572, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> TSK == TSK_ExplicitInstantiationDeclaration || |
| 2571 | (0) . __assert_fail ("(TSK == TSK_ExplicitInstantiationDefinition || TSK == TSK_ExplicitInstantiationDeclaration || (TSK == TSK_ImplicitInstantiation && Instantiation->isLocalClass())) && \"Unexpected template specialization kind!\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 2572, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> (TSK == TSK_ImplicitInstantiation && Instantiation->isLocalClass())) && |
| 2572 | (0) . __assert_fail ("(TSK == TSK_ExplicitInstantiationDefinition || TSK == TSK_ExplicitInstantiationDeclaration || (TSK == TSK_ImplicitInstantiation && Instantiation->isLocalClass())) && \"Unexpected template specialization kind!\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 2572, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Unexpected template specialization kind!"); |
| 2573 | for (auto *D : Instantiation->decls()) { |
| 2574 | bool SuppressNew = false; |
| 2575 | if (auto *Function = dyn_cast<FunctionDecl>(D)) { |
| 2576 | if (FunctionDecl *Pattern = |
| 2577 | Function->getInstantiatedFromMemberFunction()) { |
| 2578 | |
| 2579 | if (Function->hasAttr<ExcludeFromExplicitInstantiationAttr>()) |
| 2580 | continue; |
| 2581 | |
| 2582 | MemberSpecializationInfo *MSInfo = |
| 2583 | Function->getMemberSpecializationInfo(); |
| 2584 | (0) . __assert_fail ("MSInfo && \"No member specialization information?\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 2584, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(MSInfo && "No member specialization information?"); |
| 2585 | if (MSInfo->getTemplateSpecializationKind() |
| 2586 | == TSK_ExplicitSpecialization) |
| 2587 | continue; |
| 2588 | |
| 2589 | if (CheckSpecializationInstantiationRedecl(PointOfInstantiation, TSK, |
| 2590 | Function, |
| 2591 | MSInfo->getTemplateSpecializationKind(), |
| 2592 | MSInfo->getPointOfInstantiation(), |
| 2593 | SuppressNew) || |
| 2594 | SuppressNew) |
| 2595 | continue; |
| 2596 | |
| 2597 | |
| 2598 | |
| 2599 | |
| 2600 | |
| 2601 | |
| 2602 | |
| 2603 | if (TSK == TSK_ExplicitInstantiationDefinition && !Pattern->isDefined()) |
| 2604 | continue; |
| 2605 | |
| 2606 | Function->setTemplateSpecializationKind(TSK, PointOfInstantiation); |
| 2607 | |
| 2608 | if (Function->isDefined()) { |
| 2609 | |
| 2610 | |
| 2611 | Consumer.HandleTopLevelDecl(DeclGroupRef(Function)); |
| 2612 | } else if (TSK == TSK_ExplicitInstantiationDefinition) { |
| 2613 | InstantiateFunctionDefinition(PointOfInstantiation, Function); |
| 2614 | } else if (TSK == TSK_ImplicitInstantiation) { |
| 2615 | PendingLocalImplicitInstantiations.push_back( |
| 2616 | std::make_pair(Function, PointOfInstantiation)); |
| 2617 | } |
| 2618 | } |
| 2619 | } else if (auto *Var = dyn_cast<VarDecl>(D)) { |
| 2620 | if (isa<VarTemplateSpecializationDecl>(Var)) |
| 2621 | continue; |
| 2622 | |
| 2623 | if (Var->isStaticDataMember()) { |
| 2624 | if (Var->hasAttr<ExcludeFromExplicitInstantiationAttr>()) |
| 2625 | continue; |
| 2626 | |
| 2627 | MemberSpecializationInfo *MSInfo = Var->getMemberSpecializationInfo(); |
| 2628 | (0) . __assert_fail ("MSInfo && \"No member specialization information?\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 2628, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(MSInfo && "No member specialization information?"); |
| 2629 | if (MSInfo->getTemplateSpecializationKind() |
| 2630 | == TSK_ExplicitSpecialization) |
| 2631 | continue; |
| 2632 | |
| 2633 | if (CheckSpecializationInstantiationRedecl(PointOfInstantiation, TSK, |
| 2634 | Var, |
| 2635 | MSInfo->getTemplateSpecializationKind(), |
| 2636 | MSInfo->getPointOfInstantiation(), |
| 2637 | SuppressNew) || |
| 2638 | SuppressNew) |
| 2639 | continue; |
| 2640 | |
| 2641 | if (TSK == TSK_ExplicitInstantiationDefinition) { |
| 2642 | |
| 2643 | |
| 2644 | |
| 2645 | |
| 2646 | |
| 2647 | |
| 2648 | if (!Var->getInstantiatedFromStaticDataMember()->getDefinition()) |
| 2649 | continue; |
| 2650 | |
| 2651 | Var->setTemplateSpecializationKind(TSK, PointOfInstantiation); |
| 2652 | InstantiateVariableDefinition(PointOfInstantiation, Var); |
| 2653 | } else { |
| 2654 | Var->setTemplateSpecializationKind(TSK, PointOfInstantiation); |
| 2655 | } |
| 2656 | } |
| 2657 | } else if (auto *Record = dyn_cast<CXXRecordDecl>(D)) { |
| 2658 | if (Record->hasAttr<ExcludeFromExplicitInstantiationAttr>()) |
| 2659 | continue; |
| 2660 | |
| 2661 | |
| 2662 | |
| 2663 | |
| 2664 | |
| 2665 | |
| 2666 | if (Record->isInjectedClassName() || Record->getPreviousDecl() || |
| 2667 | Record->isLambda()) |
| 2668 | continue; |
| 2669 | |
| 2670 | MemberSpecializationInfo *MSInfo = Record->getMemberSpecializationInfo(); |
| 2671 | (0) . __assert_fail ("MSInfo && \"No member specialization information?\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 2671, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(MSInfo && "No member specialization information?"); |
| 2672 | |
| 2673 | if (MSInfo->getTemplateSpecializationKind() |
| 2674 | == TSK_ExplicitSpecialization) |
| 2675 | continue; |
| 2676 | |
| 2677 | if ((Context.getTargetInfo().getCXXABI().isMicrosoft() || |
| 2678 | Context.getTargetInfo().getTriple().isWindowsItaniumEnvironment()) && |
| 2679 | TSK == TSK_ExplicitInstantiationDeclaration) { |
| 2680 | |
| 2681 | |
| 2682 | continue; |
| 2683 | } |
| 2684 | |
| 2685 | if (CheckSpecializationInstantiationRedecl(PointOfInstantiation, TSK, |
| 2686 | Record, |
| 2687 | MSInfo->getTemplateSpecializationKind(), |
| 2688 | MSInfo->getPointOfInstantiation(), |
| 2689 | SuppressNew) || |
| 2690 | SuppressNew) |
| 2691 | continue; |
| 2692 | |
| 2693 | CXXRecordDecl *Pattern = Record->getInstantiatedFromMemberClass(); |
| 2694 | (0) . __assert_fail ("Pattern && \"Missing instantiated-from-template information\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 2694, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Pattern && "Missing instantiated-from-template information"); |
| 2695 | |
| 2696 | if (!Record->getDefinition()) { |
| 2697 | if (!Pattern->getDefinition()) { |
| 2698 | |
| 2699 | |
| 2700 | |
| 2701 | |
| 2702 | |
| 2703 | |
| 2704 | if (TSK == TSK_ExplicitInstantiationDeclaration) { |
| 2705 | MSInfo->setTemplateSpecializationKind(TSK); |
| 2706 | MSInfo->setPointOfInstantiation(PointOfInstantiation); |
| 2707 | } |
| 2708 | |
| 2709 | continue; |
| 2710 | } |
| 2711 | |
| 2712 | InstantiateClass(PointOfInstantiation, Record, Pattern, |
| 2713 | TemplateArgs, |
| 2714 | TSK); |
| 2715 | } else { |
| 2716 | if (TSK == TSK_ExplicitInstantiationDefinition && |
| 2717 | Record->getTemplateSpecializationKind() == |
| 2718 | TSK_ExplicitInstantiationDeclaration) { |
| 2719 | Record->setTemplateSpecializationKind(TSK); |
| 2720 | MarkVTableUsed(PointOfInstantiation, Record, true); |
| 2721 | } |
| 2722 | } |
| 2723 | |
| 2724 | Pattern = cast_or_null<CXXRecordDecl>(Record->getDefinition()); |
| 2725 | if (Pattern) |
| 2726 | InstantiateClassMembers(PointOfInstantiation, Pattern, TemplateArgs, |
| 2727 | TSK); |
| 2728 | } else if (auto *Enum = dyn_cast<EnumDecl>(D)) { |
| 2729 | MemberSpecializationInfo *MSInfo = Enum->getMemberSpecializationInfo(); |
| 2730 | (0) . __assert_fail ("MSInfo && \"No member specialization information?\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 2730, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(MSInfo && "No member specialization information?"); |
| 2731 | |
| 2732 | if (MSInfo->getTemplateSpecializationKind() |
| 2733 | == TSK_ExplicitSpecialization) |
| 2734 | continue; |
| 2735 | |
| 2736 | if (CheckSpecializationInstantiationRedecl( |
| 2737 | PointOfInstantiation, TSK, Enum, |
| 2738 | MSInfo->getTemplateSpecializationKind(), |
| 2739 | MSInfo->getPointOfInstantiation(), SuppressNew) || |
| 2740 | SuppressNew) |
| 2741 | continue; |
| 2742 | |
| 2743 | if (Enum->getDefinition()) |
| 2744 | continue; |
| 2745 | |
| 2746 | EnumDecl *Pattern = Enum->getTemplateInstantiationPattern(); |
| 2747 | (0) . __assert_fail ("Pattern && \"Missing instantiated-from-template information\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 2747, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Pattern && "Missing instantiated-from-template information"); |
| 2748 | |
| 2749 | if (TSK == TSK_ExplicitInstantiationDefinition) { |
| 2750 | if (!Pattern->getDefinition()) |
| 2751 | continue; |
| 2752 | |
| 2753 | InstantiateEnum(PointOfInstantiation, Enum, Pattern, TemplateArgs, TSK); |
| 2754 | } else { |
| 2755 | MSInfo->setTemplateSpecializationKind(TSK); |
| 2756 | MSInfo->setPointOfInstantiation(PointOfInstantiation); |
| 2757 | } |
| 2758 | } else if (auto *Field = dyn_cast<FieldDecl>(D)) { |
| 2759 | |
| 2760 | |
| 2761 | if (Field->hasInClassInitializer() && TSK == TSK_ImplicitInstantiation) { |
| 2762 | CXXRecordDecl *ClassPattern = |
| 2763 | Instantiation->getTemplateInstantiationPattern(); |
| 2764 | DeclContext::lookup_result Lookup = |
| 2765 | ClassPattern->lookup(Field->getDeclName()); |
| 2766 | FieldDecl *Pattern = cast<FieldDecl>(Lookup.front()); |
| 2767 | InstantiateInClassInitializer(PointOfInstantiation, Field, Pattern, |
| 2768 | TemplateArgs); |
| 2769 | } |
| 2770 | } |
| 2771 | } |
| 2772 | } |
| 2773 | |
| 2774 | |
| 2775 | |
| 2776 | |
| 2777 | void |
| 2778 | Sema::InstantiateClassTemplateSpecializationMembers( |
| 2779 | SourceLocation PointOfInstantiation, |
| 2780 | ClassTemplateSpecializationDecl *ClassTemplateSpec, |
| 2781 | TemplateSpecializationKind TSK) { |
| 2782 | |
| 2783 | |
| 2784 | |
| 2785 | |
| 2786 | |
| 2787 | |
| 2788 | |
| 2789 | |
| 2790 | InstantiateClassMembers(PointOfInstantiation, ClassTemplateSpec, |
| 2791 | getTemplateInstantiationArgs(ClassTemplateSpec), |
| 2792 | TSK); |
| 2793 | } |
| 2794 | |
| 2795 | StmtResult |
| 2796 | Sema::SubstStmt(Stmt *S, const MultiLevelTemplateArgumentList &TemplateArgs) { |
| 2797 | if (!S) |
| 2798 | return S; |
| 2799 | |
| 2800 | TemplateInstantiator Instantiator(*this, TemplateArgs, |
| 2801 | SourceLocation(), |
| 2802 | DeclarationName()); |
| 2803 | return Instantiator.TransformStmt(S); |
| 2804 | } |
| 2805 | |
| 2806 | ExprResult |
| 2807 | Sema::SubstExpr(Expr *E, const MultiLevelTemplateArgumentList &TemplateArgs) { |
| 2808 | if (!E) |
| 2809 | return E; |
| 2810 | |
| 2811 | TemplateInstantiator Instantiator(*this, TemplateArgs, |
| 2812 | SourceLocation(), |
| 2813 | DeclarationName()); |
| 2814 | return Instantiator.TransformExpr(E); |
| 2815 | } |
| 2816 | |
| 2817 | ExprResult Sema::SubstInitializer(Expr *Init, |
| 2818 | const MultiLevelTemplateArgumentList &TemplateArgs, |
| 2819 | bool CXXDirectInit) { |
| 2820 | TemplateInstantiator Instantiator(*this, TemplateArgs, |
| 2821 | SourceLocation(), |
| 2822 | DeclarationName()); |
| 2823 | return Instantiator.TransformInitializer(Init, CXXDirectInit); |
| 2824 | } |
| 2825 | |
| 2826 | bool Sema::SubstExprs(ArrayRef<Expr *> Exprs, bool IsCall, |
| 2827 | const MultiLevelTemplateArgumentList &TemplateArgs, |
| 2828 | SmallVectorImpl<Expr *> &Outputs) { |
| 2829 | if (Exprs.empty()) |
| 2830 | return false; |
| 2831 | |
| 2832 | TemplateInstantiator Instantiator(*this, TemplateArgs, |
| 2833 | SourceLocation(), |
| 2834 | DeclarationName()); |
| 2835 | return Instantiator.TransformExprs(Exprs.data(), Exprs.size(), |
| 2836 | IsCall, Outputs); |
| 2837 | } |
| 2838 | |
| 2839 | NestedNameSpecifierLoc |
| 2840 | Sema::SubstNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, |
| 2841 | const MultiLevelTemplateArgumentList &TemplateArgs) { |
| 2842 | if (!NNS) |
| 2843 | return NestedNameSpecifierLoc(); |
| 2844 | |
| 2845 | TemplateInstantiator Instantiator(*this, TemplateArgs, NNS.getBeginLoc(), |
| 2846 | DeclarationName()); |
| 2847 | return Instantiator.TransformNestedNameSpecifierLoc(NNS); |
| 2848 | } |
| 2849 | |
| 2850 | |
| 2851 | DeclarationNameInfo |
| 2852 | Sema::SubstDeclarationNameInfo(const DeclarationNameInfo &NameInfo, |
| 2853 | const MultiLevelTemplateArgumentList &TemplateArgs) { |
| 2854 | TemplateInstantiator Instantiator(*this, TemplateArgs, NameInfo.getLoc(), |
| 2855 | NameInfo.getName()); |
| 2856 | return Instantiator.TransformDeclarationNameInfo(NameInfo); |
| 2857 | } |
| 2858 | |
| 2859 | TemplateName |
| 2860 | Sema::SubstTemplateName(NestedNameSpecifierLoc QualifierLoc, |
| 2861 | TemplateName Name, SourceLocation Loc, |
| 2862 | const MultiLevelTemplateArgumentList &TemplateArgs) { |
| 2863 | TemplateInstantiator Instantiator(*this, TemplateArgs, Loc, |
| 2864 | DeclarationName()); |
| 2865 | CXXScopeSpec SS; |
| 2866 | SS.Adopt(QualifierLoc); |
| 2867 | return Instantiator.TransformTemplateName(SS, Name, Loc); |
| 2868 | } |
| 2869 | |
| 2870 | bool Sema::Subst(const TemplateArgumentLoc *Args, unsigned NumArgs, |
| 2871 | TemplateArgumentListInfo &Result, |
| 2872 | const MultiLevelTemplateArgumentList &TemplateArgs) { |
| 2873 | TemplateInstantiator Instantiator(*this, TemplateArgs, SourceLocation(), |
| 2874 | DeclarationName()); |
| 2875 | |
| 2876 | return Instantiator.TransformTemplateArguments(Args, NumArgs, Result); |
| 2877 | } |
| 2878 | |
| 2879 | static const Decl *getCanonicalParmVarDecl(const Decl *D) { |
| 2880 | |
| 2881 | |
| 2882 | |
| 2883 | |
| 2884 | if (const ParmVarDecl *PV = dyn_cast<ParmVarDecl>(D)) { |
| 2885 | if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(PV->getDeclContext())) { |
| 2886 | unsigned i = PV->getFunctionScopeIndex(); |
| 2887 | |
| 2888 | |
| 2889 | if (FD->getParamDecl(i) == PV) |
| 2890 | return FD->getCanonicalDecl()->getParamDecl(i); |
| 2891 | } |
| 2892 | } |
| 2893 | return D; |
| 2894 | } |
| 2895 | |
| 2896 | |
| 2897 | llvm::PointerUnion<Decl *, LocalInstantiationScope::DeclArgumentPack *> * |
| 2898 | LocalInstantiationScope::findInstantiationOf(const Decl *D) { |
| 2899 | D = getCanonicalParmVarDecl(D); |
| 2900 | for (LocalInstantiationScope *Current = this; Current; |
| 2901 | Current = Current->Outer) { |
| 2902 | |
| 2903 | |
| 2904 | const Decl *CheckD = D; |
| 2905 | do { |
| 2906 | LocalDeclsMap::iterator Found = Current->LocalDecls.find(CheckD); |
| 2907 | if (Found != Current->LocalDecls.end()) |
| 2908 | return &Found->second; |
| 2909 | |
| 2910 | |
| 2911 | |
| 2912 | if (const TagDecl *Tag = dyn_cast<TagDecl>(CheckD)) |
| 2913 | CheckD = Tag->getPreviousDecl(); |
| 2914 | else |
| 2915 | CheckD = nullptr; |
| 2916 | } while (CheckD); |
| 2917 | |
| 2918 | |
| 2919 | if (!Current->CombineWithOuterScope) |
| 2920 | break; |
| 2921 | } |
| 2922 | |
| 2923 | |
| 2924 | |
| 2925 | if (isa<NonTypeTemplateParmDecl>(D) || isa<TemplateTypeParmDecl>(D) || |
| 2926 | isa<TemplateTemplateParmDecl>(D)) |
| 2927 | return nullptr; |
| 2928 | |
| 2929 | |
| 2930 | if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(D)) |
| 2931 | if (RD->isLocalClass()) |
| 2932 | return nullptr; |
| 2933 | |
| 2934 | |
| 2935 | |
| 2936 | if (isa<EnumDecl>(D)) |
| 2937 | return nullptr; |
| 2938 | |
| 2939 | |
| 2940 | |
| 2941 | |
| 2942 | (0) . __assert_fail ("isa(D) && \"declaration not instantiated in this scope\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 2942, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(isa<LabelDecl>(D) && "declaration not instantiated in this scope"); |
| 2943 | return nullptr; |
| 2944 | } |
| 2945 | |
| 2946 | void LocalInstantiationScope::InstantiatedLocal(const Decl *D, Decl *Inst) { |
| 2947 | D = getCanonicalParmVarDecl(D); |
| 2948 | llvm::PointerUnion<Decl *, DeclArgumentPack *> &Stored = LocalDecls[D]; |
| 2949 | if (Stored.isNull()) { |
| 2950 | #ifndef NDEBUG |
| 2951 | |
| 2952 | LocalInstantiationScope *Current = this; |
| 2953 | while (Current->CombineWithOuterScope && Current->Outer) { |
| 2954 | Current = Current->Outer; |
| 2955 | (0) . __assert_fail ("Current->LocalDecls.find(D) == Current->LocalDecls.end() && \"Instantiated local in inner and outer scopes\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 2956, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Current->LocalDecls.find(D) == Current->LocalDecls.end() && |
| 2956 | (0) . __assert_fail ("Current->LocalDecls.find(D) == Current->LocalDecls.end() && \"Instantiated local in inner and outer scopes\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 2956, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Instantiated local in inner and outer scopes"); |
| 2957 | } |
| 2958 | #endif |
| 2959 | Stored = Inst; |
| 2960 | } else if (DeclArgumentPack *Pack = Stored.dyn_cast<DeclArgumentPack *>()) { |
| 2961 | Pack->push_back(cast<ParmVarDecl>(Inst)); |
| 2962 | } else { |
| 2963 | (0) . __assert_fail ("Stored.get() == Inst && \"Already instantiated this local\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 2963, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Stored.get<Decl *>() == Inst && "Already instantiated this local"); |
| 2964 | } |
| 2965 | } |
| 2966 | |
| 2967 | void LocalInstantiationScope::InstantiatedLocalPackArg(const Decl *D, |
| 2968 | ParmVarDecl *Inst) { |
| 2969 | D = getCanonicalParmVarDecl(D); |
| 2970 | DeclArgumentPack *Pack = LocalDecls[D].get<DeclArgumentPack *>(); |
| 2971 | Pack->push_back(Inst); |
| 2972 | } |
| 2973 | |
| 2974 | void LocalInstantiationScope::MakeInstantiatedLocalArgPack(const Decl *D) { |
| 2975 | #ifndef NDEBUG |
| 2976 | |
| 2977 | for (LocalInstantiationScope *Current = this; |
| 2978 | Current && Current->CombineWithOuterScope; Current = Current->Outer) |
| 2979 | (0) . __assert_fail ("Current->LocalDecls.find(D) == Current->LocalDecls.end() && \"Creating local pack after instantiation of local\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 2980, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Current->LocalDecls.find(D) == Current->LocalDecls.end() && |
| 2980 | (0) . __assert_fail ("Current->LocalDecls.find(D) == Current->LocalDecls.end() && \"Creating local pack after instantiation of local\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 2980, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Creating local pack after instantiation of local"); |
| 2981 | #endif |
| 2982 | |
| 2983 | D = getCanonicalParmVarDecl(D); |
| 2984 | llvm::PointerUnion<Decl *, DeclArgumentPack *> &Stored = LocalDecls[D]; |
| 2985 | DeclArgumentPack *Pack = new DeclArgumentPack; |
| 2986 | Stored = Pack; |
| 2987 | ArgumentPacks.push_back(Pack); |
| 2988 | } |
| 2989 | |
| 2990 | void LocalInstantiationScope::SetPartiallySubstitutedPack(NamedDecl *Pack, |
| 2991 | const TemplateArgument *ExplicitArgs, |
| 2992 | unsigned NumExplicitArgs) { |
| 2993 | (0) . __assert_fail ("(!PartiallySubstitutedPack || PartiallySubstitutedPack == Pack) && \"Already have a partially-substituted pack\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 2994, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert((!PartiallySubstitutedPack || PartiallySubstitutedPack == Pack) && |
| 2994 | (0) . __assert_fail ("(!PartiallySubstitutedPack || PartiallySubstitutedPack == Pack) && \"Already have a partially-substituted pack\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 2994, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Already have a partially-substituted pack"); |
| 2995 | (0) . __assert_fail ("(!PartiallySubstitutedPack || NumArgsInPartiallySubstitutedPack == NumExplicitArgs) && \"Wrong number of arguments in partially-substituted pack\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 2997, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert((!PartiallySubstitutedPack |
| 2996 | (0) . __assert_fail ("(!PartiallySubstitutedPack || NumArgsInPartiallySubstitutedPack == NumExplicitArgs) && \"Wrong number of arguments in partially-substituted pack\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 2997, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> || NumArgsInPartiallySubstitutedPack == NumExplicitArgs) && |
| 2997 | (0) . __assert_fail ("(!PartiallySubstitutedPack || NumArgsInPartiallySubstitutedPack == NumExplicitArgs) && \"Wrong number of arguments in partially-substituted pack\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiate.cpp", 2997, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Wrong number of arguments in partially-substituted pack"); |
| 2998 | PartiallySubstitutedPack = Pack; |
| 2999 | ArgsInPartiallySubstitutedPack = ExplicitArgs; |
| 3000 | NumArgsInPartiallySubstitutedPack = NumExplicitArgs; |
| 3001 | } |
| 3002 | |
| 3003 | NamedDecl *LocalInstantiationScope::getPartiallySubstitutedPack( |
| 3004 | const TemplateArgument **ExplicitArgs, |
| 3005 | unsigned *NumExplicitArgs) const { |
| 3006 | if (ExplicitArgs) |
| 3007 | *ExplicitArgs = nullptr; |
| 3008 | if (NumExplicitArgs) |
| 3009 | *NumExplicitArgs = 0; |
| 3010 | |
| 3011 | for (const LocalInstantiationScope *Current = this; Current; |
| 3012 | Current = Current->Outer) { |
| 3013 | if (Current->PartiallySubstitutedPack) { |
| 3014 | if (ExplicitArgs) |
| 3015 | *ExplicitArgs = Current->ArgsInPartiallySubstitutedPack; |
| 3016 | if (NumExplicitArgs) |
| 3017 | *NumExplicitArgs = Current->NumArgsInPartiallySubstitutedPack; |
| 3018 | |
| 3019 | return Current->PartiallySubstitutedPack; |
| 3020 | } |
| 3021 | |
| 3022 | if (!Current->CombineWithOuterScope) |
| 3023 | break; |
| 3024 | } |
| 3025 | |
| 3026 | return nullptr; |
| 3027 | } |
| 3028 | |