diff options
author | Saar Raz <saar@raz.email> | 2020-01-11 03:12:04 +0200 |
---|---|---|
committer | Saar Raz <saar@raz.email> | 2020-01-11 03:16:57 +0200 |
commit | 9b23407063ca41901e9e272bacf8b33eee8251c4 (patch) | |
tree | de6820986937cbdc935eef86cfb2fb5b3f4599fa /clang | |
parent | 1d2cd2c0b7d978e22a50e918af708ba67e87c2c1 (diff) | |
download | bcm5719-llvm-9b23407063ca41901e9e272bacf8b33eee8251c4.tar.gz bcm5719-llvm-9b23407063ca41901e9e272bacf8b33eee8251c4.zip |
[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.
Diffstat (limited to 'clang')
-rw-r--r-- | clang/lib/Sema/SemaTemplateDeduction.cpp | 45 |
1 files changed, 20 insertions, 25 deletions
diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp index d267ae8572e..e626948cb5d 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; } |