From 9b23407063ca41901e9e272bacf8b33eee8251c4 Mon Sep 17 00:00:00 2001 From: Saar Raz Date: Sat, 11 Jan 2020 03:12:04 +0200 Subject: [PATCH] [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. --- clang/lib/Sema/SemaTemplateDeduction.cpp | 45 ++++++++++++++------------------ 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp index d267ae8..e626948 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 { - llvm::SmallBitVector &OccurringIndices; +namespace { +struct MarkUsedTemplateParameterVisitor : + RecursiveASTVisitor { + 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(Template.getAsTemplateDecl())) { - assert(TTP->getDepth() == 0 && "This assumes that we allow concepts at " - "namespace scope only"); - noteParameter(TTP->getIndex()); - } - RecursiveASTVisitor:: + dyn_cast(Template.getAsTemplateDecl())) + if (TTP->getDepth() == Depth) + Used[TTP->getIndex()] = true; + RecursiveASTVisitor:: TraverseTemplateName(Template); return true; } bool VisitDeclRefExpr(DeclRefExpr *E) { - if (auto *NTTP = dyn_cast(E->getDecl())) { - assert(NTTP->getDepth() == 0 && "This assumes that we allow concepts at " - "namespace scope only"); - noteParameter(NTTP->getIndex()); - } + if (auto *NTTP = dyn_cast(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(E)); + MarkUsedTemplateParameterVisitor(Used, Depth) + .TraverseStmt(const_cast(E)); return; } -- 2.7.4