[clang] 9b23407 - [Concepts] Fix MarkUsedTemplateParameters for exprs
Saar Raz via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 10 17:17:13 PST 2020
Author: Saar Raz
Date: 2020-01-11T03:16:57+02:00
New Revision: 9b23407063ca41901e9e272bacf8b33eee8251c4
URL: https://github.com/llvm/llvm-project/commit/9b23407063ca41901e9e272bacf8b33eee8251c4
DIFF: https://github.com/llvm/llvm-project/commit/9b23407063ca41901e9e272bacf8b33eee8251c4.diff
LOG: [Concepts] Fix MarkUsedTemplateParameters for exprs
D41910 introduced a recursive visitor to MarkUsedTemplateParameters, but
disregarded the 'Depth' parameter, and had incorrect assertions. This fixes
the visitor and removes the assertions.
Added:
Modified:
clang/lib/Sema/SemaTemplateDeduction.cpp
Removed:
################################################################################
diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp
index d267ae8572e4..e626948cb5d4 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -5384,46 +5384,40 @@ bool Sema::isTemplateTemplateParameterAtLeastAsSpecializedAs(
return isAtLeastAsSpecializedAs(*this, PType, AType, AArg, Info);
}
-struct OccurringTemplateParameterFinder :
- RecursiveASTVisitor<OccurringTemplateParameterFinder> {
- llvm::SmallBitVector &OccurringIndices;
+namespace {
+struct MarkUsedTemplateParameterVisitor :
+ RecursiveASTVisitor<MarkUsedTemplateParameterVisitor> {
+ llvm::SmallBitVector &Used;
+ unsigned Depth;
- OccurringTemplateParameterFinder(llvm::SmallBitVector &OccurringIndices)
- : OccurringIndices(OccurringIndices) { }
+ MarkUsedTemplateParameterVisitor(llvm::SmallBitVector &Used,
+ unsigned Depth)
+ : Used(Used), Depth(Depth) { }
bool VisitTemplateTypeParmType(TemplateTypeParmType *T) {
- assert(T->getDepth() == 0 && "This assumes that we allow concepts at "
- "namespace scope only");
- noteParameter(T->getIndex());
+ if (T->getDepth() == Depth)
+ Used[T->getIndex()] = true;
return true;
}
bool TraverseTemplateName(TemplateName Template) {
if (auto *TTP =
- dyn_cast<TemplateTemplateParmDecl>(Template.getAsTemplateDecl())) {
- assert(TTP->getDepth() == 0 && "This assumes that we allow concepts at "
- "namespace scope only");
- noteParameter(TTP->getIndex());
- }
- RecursiveASTVisitor<OccurringTemplateParameterFinder>::
+ dyn_cast<TemplateTemplateParmDecl>(Template.getAsTemplateDecl()))
+ if (TTP->getDepth() == Depth)
+ Used[TTP->getIndex()] = true;
+ RecursiveASTVisitor<MarkUsedTemplateParameterVisitor>::
TraverseTemplateName(Template);
return true;
}
bool VisitDeclRefExpr(DeclRefExpr *E) {
- if (auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(E->getDecl())) {
- assert(NTTP->getDepth() == 0 && "This assumes that we allow concepts at "
- "namespace scope only");
- noteParameter(NTTP->getIndex());
- }
+ if (auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(E->getDecl()))
+ if (NTTP->getDepth() == Depth)
+ Used[NTTP->getIndex()] = true;
return true;
}
-
-protected:
- void noteParameter(unsigned Index) {
- OccurringIndices.set(Index);
- }
};
+}
/// Mark the template parameters that are used by the given
/// expression.
@@ -5434,7 +5428,8 @@ MarkUsedTemplateParameters(ASTContext &Ctx,
unsigned Depth,
llvm::SmallBitVector &Used) {
if (!OnlyDeduced) {
- OccurringTemplateParameterFinder(Used).TraverseStmt(const_cast<Expr *>(E));
+ MarkUsedTemplateParameterVisitor(Used, Depth)
+ .TraverseStmt(const_cast<Expr *>(E));
return;
}
More information about the cfe-commits
mailing list