[clang] [clang] CTAD: use index and depth to retrieve template parameter for TemplateParamsReferencedInTemplateArgumentList (PR #98013)
Matheus Izvekov via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 8 11:32:21 PDT 2024
================
@@ -2653,20 +2653,34 @@ struct ConvertConstructorToDeductionGuideTransform {
// Find all template parameters that appear in the given DeducedArgs.
// Return the indices of the template parameters in the TemplateParams.
SmallVector<unsigned> TemplateParamsReferencedInTemplateArgumentList(
- ArrayRef<NamedDecl *> TemplateParams,
+ const TemplateParameterList* TemplateParamsList,
ArrayRef<TemplateArgument> DeducedArgs) {
struct TemplateParamsReferencedFinder
: public RecursiveASTVisitor<TemplateParamsReferencedFinder> {
+ const TemplateParameterList* TemplateParamList;
llvm::DenseSet<NamedDecl *> TemplateParams;
llvm::DenseSet<const NamedDecl *> ReferencedTemplateParams;
- TemplateParamsReferencedFinder(ArrayRef<NamedDecl *> TemplateParams)
- : TemplateParams(TemplateParams.begin(), TemplateParams.end()) {}
+ TemplateParamsReferencedFinder(
+ const TemplateParameterList *TemplateParamList)
+ : TemplateParamList(TemplateParamList),
+ TemplateParams(TemplateParamList->begin(), TemplateParamList->end()) {
+ }
bool VisitTemplateTypeParmType(TemplateTypeParmType *TTP) {
- MarkAppeared(TTP->getDecl());
+ // We use the index and depth to retrieve the corresponding template
+ // parameter from the parameter list.
+ // Note that Clang may not preserve type sugar during template argument
+ // deduction. In such cases, the TTP is a canonical TemplateTypeParamType,
+ // which only retains its index and depth information.
+ if (TTP->getDepth() == TemplateParamList->getDepth() &&
----------------
mizvekov wrote:
Shouldn't this issue come up for the other kind of template parameters as well, besides type parameters?
https://github.com/llvm/llvm-project/pull/98013
More information about the cfe-commits
mailing list