|
21 | 21 | #include "clang/AST/DeclFriend.h"
|
22 | 22 | #include "clang/AST/DeclTemplate.h"
|
23 | 23 | #include "clang/AST/DeclarationName.h"
|
24 |
| -#include "clang/AST/DynamicRecursiveASTVisitor.h" |
25 | 24 | #include "clang/AST/Expr.h"
|
26 | 25 | #include "clang/AST/ExprCXX.h"
|
27 | 26 | #include "clang/AST/OperationKinds.h"
|
@@ -681,54 +680,16 @@ struct ConvertConstructorToDeductionGuideTransform {
|
681 | 680 | // Find all template parameters that appear in the given DeducedArgs.
|
682 | 681 | // Return the indices of the template parameters in the TemplateParams.
|
683 | 682 | SmallVector<unsigned> TemplateParamsReferencedInTemplateArgumentList(
|
684 |
| - const TemplateParameterList *TemplateParamsList, |
| 683 | + Sema &SemaRef, const TemplateParameterList *TemplateParamsList, |
685 | 684 | ArrayRef<TemplateArgument> DeducedArgs) {
|
686 |
| - struct TemplateParamsReferencedFinder : DynamicRecursiveASTVisitor { |
687 |
| - const TemplateParameterList *TemplateParamList; |
688 |
| - llvm::BitVector ReferencedTemplateParams; |
689 |
| - |
690 |
| - TemplateParamsReferencedFinder( |
691 |
| - const TemplateParameterList *TemplateParamList) |
692 |
| - : TemplateParamList(TemplateParamList), |
693 |
| - ReferencedTemplateParams(TemplateParamList->size()) {} |
694 |
| - |
695 |
| - bool VisitTemplateTypeParmType(TemplateTypeParmType *TTP) override { |
696 |
| - // We use the index and depth to retrieve the corresponding template |
697 |
| - // parameter from the parameter list, which is more robost. |
698 |
| - Mark(TTP->getDepth(), TTP->getIndex()); |
699 |
| - return true; |
700 |
| - } |
701 |
| - |
702 |
| - bool VisitDeclRefExpr(DeclRefExpr *DRE) override { |
703 |
| - MarkAppeared(DRE->getFoundDecl()); |
704 |
| - return true; |
705 |
| - } |
706 | 685 |
|
707 |
| - bool TraverseTemplateName(TemplateName Template) override { |
708 |
| - if (auto *TD = Template.getAsTemplateDecl()) |
709 |
| - MarkAppeared(TD); |
710 |
| - return DynamicRecursiveASTVisitor::TraverseTemplateName(Template); |
711 |
| - } |
712 |
| - |
713 |
| - void MarkAppeared(NamedDecl *ND) { |
714 |
| - if (llvm::isa<NonTypeTemplateParmDecl, TemplateTypeParmDecl, |
715 |
| - TemplateTemplateParmDecl>(ND)) { |
716 |
| - auto [Depth, Index] = getDepthAndIndex(ND); |
717 |
| - Mark(Depth, Index); |
718 |
| - } |
719 |
| - } |
720 |
| - void Mark(unsigned Depth, unsigned Index) { |
721 |
| - if (Index < TemplateParamList->size() && |
722 |
| - TemplateParamList->getParam(Index)->getTemplateDepth() == Depth) |
723 |
| - ReferencedTemplateParams.set(Index); |
724 |
| - } |
725 |
| - }; |
726 |
| - TemplateParamsReferencedFinder Finder(TemplateParamsList); |
727 |
| - Finder.TraverseTemplateArguments(DeducedArgs); |
| 686 | + llvm::SmallBitVector ReferencedTemplateParams(TemplateParamsList->size()); |
| 687 | + SemaRef.MarkUsedTemplateParameters( |
| 688 | + DeducedArgs, TemplateParamsList->getDepth(), ReferencedTemplateParams); |
728 | 689 |
|
729 | 690 | SmallVector<unsigned> Results;
|
730 | 691 | for (unsigned Index = 0; Index < TemplateParamsList->size(); ++Index) {
|
731 |
| - if (Finder.ReferencedTemplateParams[Index]) |
| 692 | + if (ReferencedTemplateParams[Index]) |
732 | 693 | Results.push_back(Index);
|
733 | 694 | }
|
734 | 695 | return Results;
|
@@ -1099,7 +1060,7 @@ BuildDeductionGuideForTypeAlias(Sema &SemaRef,
|
1099 | 1060 | }
|
1100 | 1061 | auto DeducedAliasTemplateParams =
|
1101 | 1062 | TemplateParamsReferencedInTemplateArgumentList(
|
1102 |
| - AliasTemplate->getTemplateParameters(), DeducedArgs); |
| 1063 | + SemaRef, AliasTemplate->getTemplateParameters(), DeducedArgs); |
1103 | 1064 | // All template arguments null by default.
|
1104 | 1065 | SmallVector<TemplateArgument> TemplateArgsForBuildingFPrime(
|
1105 | 1066 | F->getTemplateParameters()->size());
|
|
0 commit comments