@@ -220,7 +220,7 @@ class ExtractTypeForDeductionGuide
220220// A deduction guide can be either a template or a non-template function
221221// declaration. If \p TemplateParams is null, a non-template function
222222// declaration will be created.
223- NamedDecl *
223+ CXXDeductionGuideDecl *
224224buildDeductionGuide (Sema &SemaRef, TemplateDecl *OriginalTemplate,
225225 TemplateParameterList *TemplateParams,
226226 CXXConstructorDecl *Ctor, ExplicitSpecifier ES ,
@@ -276,7 +276,7 @@ buildDeductionGuide(Sema &SemaRef, TemplateDecl *OriginalTemplate,
276276
277277 if (HaveSameAssociatedConstraints (SemaRef, ExistingCtor, ExistingACs,
278278 Ctor, NewACs))
279- return Existing ;
279+ return ExistingGuide ;
280280 }
281281 }
282282
@@ -307,7 +307,7 @@ buildDeductionGuide(Sema &SemaRef, TemplateDecl *OriginalTemplate,
307307 GuideTemplate->setAccess (AS_public);
308308
309309 DC ->addDecl (GuideTemplate);
310- return GuideTemplate ;
310+ return Guide ;
311311}
312312
313313// Transform a given template type parameter `TTP`.
@@ -570,7 +570,8 @@ struct ConvertConstructorToDeductionGuideTransform {
570570 }
571571
572572 // / Build a deduction guide with the specified parameter types.
573- NamedDecl *buildSimpleDeductionGuide (MutableArrayRef<QualType> ParamTypes) {
573+ CXXDeductionGuideDecl *
574+ buildSimpleDeductionGuide (MutableArrayRef<QualType> ParamTypes) {
574575 SourceLocation Loc = Template->getLocation ();
575576
576577 // Build the requested type.
@@ -1081,11 +1082,14 @@ bool IsNonDeducedArgument(const TemplateArgument &TA) {
10811082}
10821083
10831084// Build deduction guides for a type alias template from the given underlying
1084- // deduction guide F.
1085- FunctionTemplateDecl *
1086- BuildDeductionGuideForTypeAlias (Sema &SemaRef,
1087- TypeAliasTemplateDecl *AliasTemplate,
1088- FunctionTemplateDecl *F, SourceLocation Loc) {
1085+ // source deduction guide.
1086+ CXXDeductionGuideDecl *BuildDeductionGuideForTypeAlias (
1087+ Sema &SemaRef, TypeAliasTemplateDecl *AliasTemplate,
1088+ CXXDeductionGuideDecl *SourceDeductionGuide, SourceLocation Loc) {
1089+ FunctionTemplateDecl *F =
1090+ SourceDeductionGuide->getDescribedFunctionTemplate ();
1091+ assert (F && " deduction guide for alias template must be a function template" );
1092+
10891093 LocalInstantiationScope Scope (SemaRef);
10901094 Sema::NonSFINAEContext _1 (SemaRef);
10911095 Sema::InstantiatingTemplate BuildingDeductionGuides (
@@ -1116,7 +1120,7 @@ BuildDeductionGuideForTypeAlias(Sema &SemaRef,
11161120 //
11171121 // Instead, we need to canonicalize both against A, i.e. A<A<T>> and A<A<U>>,
11181122 // such that T can be deduced as U.
1119- auto RType = F-> getTemplatedDecl () ->getReturnType ();
1123+ auto RType = SourceDeductionGuide ->getReturnType ();
11201124 // The (trailing) return type of the deduction guide.
11211125 const auto *FReturnType = RType->getAs <TemplateSpecializationType>();
11221126 if (const auto *ICNT = RType->getAsCanonical <InjectedClassNameType>())
@@ -1316,25 +1320,26 @@ BuildDeductionGuideForTypeAlias(Sema &SemaRef,
13161320 buildAssociatedConstraints (SemaRef, F, AliasTemplate, DeduceResults,
13171321 FirstUndeducedParamIdx, IsDeducible);
13181322
1319- auto *FPrimeTemplateParamList = TemplateParameterList::Create (
1320- Context, AliasTemplate->getTemplateParameters ()->getTemplateLoc (),
1321- AliasTemplate->getTemplateParameters ()->getLAngleLoc (),
1322- FPrimeTemplateParams,
1323- AliasTemplate->getTemplateParameters ()->getRAngleLoc (),
1324- /* RequiresClause=*/ RequiresClause);
1325- auto *Result = cast<FunctionTemplateDecl>(buildDeductionGuide (
1323+ TemplateParameterList *FPrimeTemplateParamList = nullptr ;
1324+ if (!FPrimeTemplateParams.empty ())
1325+ FPrimeTemplateParamList = TemplateParameterList::Create (
1326+ Context, AliasTemplate->getTemplateParameters ()->getTemplateLoc (),
1327+ AliasTemplate->getTemplateParameters ()->getLAngleLoc (),
1328+ FPrimeTemplateParams,
1329+ AliasTemplate->getTemplateParameters ()->getRAngleLoc (),
1330+ /* RequiresClause=*/ RequiresClause);
1331+
1332+ auto *DGuide = buildDeductionGuide (
13261333 SemaRef, AliasTemplate, FPrimeTemplateParamList,
13271334 GG ->getCorrespondingConstructor (), GG ->getExplicitSpecifier (),
13281335 GG ->getTypeSourceInfo (), AliasTemplate->getBeginLoc (),
13291336 AliasTemplate->getLocation (), AliasTemplate->getEndLoc (),
1330- F->isImplicit ()));
1331- auto *DGuide = cast<CXXDeductionGuideDecl>(Result->getTemplatedDecl ());
1337+ F->isImplicit ());
13321338 DGuide->setDeductionCandidateKind (GG ->getDeductionCandidateKind ());
1333- DGuide->setSourceDeductionGuide (
1334- cast<CXXDeductionGuideDecl>(F->getTemplatedDecl ()));
1339+ DGuide->setSourceDeductionGuide (SourceDeductionGuide);
13351340 DGuide->setSourceDeductionGuideKind (
13361341 CXXDeductionGuideDecl::SourceDeductionGuideKind::Alias);
1337- return Result ;
1342+ return DGuide ;
13381343 }
13391344 return nullptr ;
13401345}
@@ -1412,16 +1417,16 @@ void DeclareImplicitDeductionGuidesForTypeAlias(
14121417 // The **aggregate** deduction guides are handled in a different code path
14131418 // (DeclareAggregateDeductionGuideFromInitList), which involves the tricky
14141419 // cache.
1415- if ( cast<CXXDeductionGuideDecl>(F->getTemplatedDecl ())
1416- ->getDeductionCandidateKind () == DeductionCandidate::Aggregate)
1420+ auto *DGuide = cast<CXXDeductionGuideDecl>(F->getTemplatedDecl ());
1421+ if (DGuide ->getDeductionCandidateKind () == DeductionCandidate::Aggregate)
14171422 continue ;
14181423
1419- BuildDeductionGuideForTypeAlias (SemaRef, AliasTemplate, F , Loc);
1424+ BuildDeductionGuideForTypeAlias (SemaRef, AliasTemplate, DGuide , Loc);
14201425 }
14211426}
14221427
14231428// Build an aggregate deduction guide for a type alias template.
1424- FunctionTemplateDecl *DeclareAggregateDeductionGuideForTypeAlias (
1429+ CXXDeductionGuideDecl *DeclareAggregateDeductionGuideForTypeAlias (
14251430 Sema &SemaRef, TypeAliasTemplateDecl *AliasTemplate,
14261431 MutableArrayRef<QualType> ParamTypes, SourceLocation Loc) {
14271432 TemplateDecl *RHSTemplate =
@@ -1445,15 +1450,15 @@ FunctionTemplateDecl *DeclareAggregateDeductionGuideForTypeAlias(
14451450 return nullptr ;
14461451
14471452 for (TypedefNameDecl *TD : TypedefDecls)
1448- TD ->setDeclContext (RHSDeductionGuide-> getTemplatedDecl () );
1453+ TD ->setDeclContext (RHSDeductionGuide);
14491454
14501455 return BuildDeductionGuideForTypeAlias (SemaRef, AliasTemplate,
14511456 RHSDeductionGuide, Loc);
14521457}
14531458
14541459} // namespace
14551460
1456- FunctionTemplateDecl *Sema::DeclareAggregateDeductionGuideFromInitList (
1461+ CXXDeductionGuideDecl *Sema::DeclareAggregateDeductionGuideFromInitList (
14571462 TemplateDecl *Template, MutableArrayRef<QualType> ParamTypes,
14581463 SourceLocation Loc) {
14591464 llvm::FoldingSetNodeID ID ;
@@ -1463,18 +1468,15 @@ FunctionTemplateDecl *Sema::DeclareAggregateDeductionGuideFromInitList(
14631468 unsigned Hash = ID .ComputeHash ();
14641469
14651470 auto Found = AggregateDeductionCandidates.find (Hash);
1466- if (Found != AggregateDeductionCandidates.end ()) {
1467- CXXDeductionGuideDecl *GD = Found->getSecond ();
1468- return GD ->getDescribedFunctionTemplate ();
1469- }
1471+ if (Found != AggregateDeductionCandidates.end ())
1472+ return Found->getSecond ();
14701473
14711474 if (auto *AliasTemplate = llvm::dyn_cast<TypeAliasTemplateDecl>(Template)) {
1472- if (auto *FTD = DeclareAggregateDeductionGuideForTypeAlias (
1475+ if (auto *GD = DeclareAggregateDeductionGuideForTypeAlias (
14731476 *this , AliasTemplate, ParamTypes, Loc)) {
1474- auto *GD = cast<CXXDeductionGuideDecl>(FTD ->getTemplatedDecl ());
14751477 GD ->setDeductionCandidateKind (DeductionCandidate::Aggregate);
14761478 AggregateDeductionCandidates[Hash] = GD ;
1477- return FTD ;
1479+ return GD ;
14781480 }
14791481 }
14801482
@@ -1509,13 +1511,11 @@ FunctionTemplateDecl *Sema::DeclareAggregateDeductionGuideFromInitList(
15091511 Transform.NestedPattern ? Transform.NestedPattern : Transform.Template ;
15101512 ContextRAII SavedContext (*this , Pattern->getTemplatedDecl ());
15111513
1512- auto *FTD = cast<FunctionTemplateDecl>(
1513- Transform.buildSimpleDeductionGuide (ParamTypes));
1514+ CXXDeductionGuideDecl *GD = Transform.buildSimpleDeductionGuide (ParamTypes);
15141515 SavedContext.pop ();
1515- auto *GD = cast<CXXDeductionGuideDecl>(FTD ->getTemplatedDecl ());
15161516 GD ->setDeductionCandidateKind (DeductionCandidate::Aggregate);
15171517 AggregateDeductionCandidates[Hash] = GD ;
1518- return FTD ;
1518+ return GD ;
15191519}
15201520
15211521void Sema::DeclareImplicitDeductionGuides (TemplateDecl *Template,
@@ -1607,10 +1607,7 @@ void Sema::DeclareImplicitDeductionGuides(TemplateDecl *Template,
16071607
16081608 // -- An additional function template derived as above from a hypothetical
16091609 // constructor C(C), called the copy deduction candidate.
1610- cast<CXXDeductionGuideDecl>(
1611- cast<FunctionTemplateDecl>(
1612- Transform.buildSimpleDeductionGuide (Transform.DeducedType ))
1613- ->getTemplatedDecl ())
1610+ Transform.buildSimpleDeductionGuide (Transform.DeducedType )
16141611 ->setDeductionCandidateKind (DeductionCandidate::Copy);
16151612
16161613 SavedContext.pop ();
0 commit comments