diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2021-06-13 19:31:46 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2021-06-13 19:37:19 +0000 |
commit | e8d8bef961a50d4dc22501cde4fb9fb0be1b2532 (patch) | |
tree | 94f04805f47bb7c59ae29690d8952b6074fff602 /contrib/llvm-project/clang/lib/Sema/SemaTemplateVariadic.cpp | |
parent | bb130ff39747b94592cb26d71b7cb097b9a4ea6b (diff) | |
parent | b60736ec1405bb0a8dd40989f67ef4c93da068ab (diff) |
Diffstat (limited to 'contrib/llvm-project/clang/lib/Sema/SemaTemplateVariadic.cpp')
-rw-r--r-- | contrib/llvm-project/clang/lib/Sema/SemaTemplateVariadic.cpp | 60 |
1 files changed, 51 insertions, 9 deletions
diff --git a/contrib/llvm-project/clang/lib/Sema/SemaTemplateVariadic.cpp b/contrib/llvm-project/clang/lib/Sema/SemaTemplateVariadic.cpp index 259cc5165776..1951aec3d17d 100644 --- a/contrib/llvm-project/clang/lib/Sema/SemaTemplateVariadic.cpp +++ b/contrib/llvm-project/clang/lib/Sema/SemaTemplateVariadic.cpp @@ -368,8 +368,8 @@ Sema::DiagnoseUnexpandedParameterPacks(SourceLocation Loc, Locations.push_back(Unexpanded[I].second); } - DiagnosticBuilder DB = Diag(Loc, diag::err_unexpanded_parameter_pack) - << (int)UPPC << (int)Names.size(); + auto DB = Diag(Loc, diag::err_unexpanded_parameter_pack) + << (int)UPPC << (int)Names.size(); for (size_t I = 0, E = std::min(Names.size(), (size_t)2); I != E; ++I) DB << Names[I]; @@ -408,6 +408,29 @@ bool Sema::DiagnoseUnexpandedParameterPack(Expr *E, return DiagnoseUnexpandedParameterPacks(E->getBeginLoc(), UPPC, Unexpanded); } +bool Sema::DiagnoseUnexpandedParameterPackInRequiresExpr(RequiresExpr *RE) { + if (!RE->containsUnexpandedParameterPack()) + return false; + + SmallVector<UnexpandedParameterPack, 2> Unexpanded; + CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseStmt(RE); + assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs"); + + // We only care about unexpanded references to the RequiresExpr's own + // parameter packs. + auto Parms = RE->getLocalParameters(); + llvm::SmallPtrSet<NamedDecl*, 8> ParmSet(Parms.begin(), Parms.end()); + SmallVector<UnexpandedParameterPack, 2> UnexpandedParms; + for (auto Parm : Unexpanded) + if (ParmSet.contains(Parm.first.dyn_cast<NamedDecl*>())) + UnexpandedParms.push_back(Parm); + if (UnexpandedParms.empty()) + return false; + + return DiagnoseUnexpandedParameterPacks(RE->getBeginLoc(), UPPC_Requirement, + UnexpandedParms); +} + bool Sema::DiagnoseUnexpandedParameterPack(const CXXScopeSpec &SS, UnexpandedParameterPackContext UPPC) { // C++0x [temp.variadic]p5: @@ -1072,7 +1095,7 @@ Sema::getTemplateArgumentPackExpansionPattern( case TemplateArgument::TemplateExpansion: Ellipsis = OrigLoc.getTemplateEllipsisLoc(); NumExpansions = Argument.getNumTemplateExpansions(); - return TemplateArgumentLoc(Argument.getPackExpansionPattern(), + return TemplateArgumentLoc(Context, Argument.getPackExpansionPattern(), OrigLoc.getTemplateQualifierLoc(), OrigLoc.getTemplateNameLoc()); @@ -1160,7 +1183,7 @@ static void CheckFoldOperand(Sema &S, Expr *E) { } } -ExprResult Sema::ActOnCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS, +ExprResult Sema::ActOnCXXFoldExpr(Scope *S, SourceLocation LParenLoc, Expr *LHS, tok::TokenKind Operator, SourceLocation EllipsisLoc, Expr *RHS, SourceLocation RParenLoc) { @@ -1202,18 +1225,37 @@ ExprResult Sema::ActOnCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS, } BinaryOperatorKind Opc = ConvertTokenKindToBinaryOpcode(Operator); - return BuildCXXFoldExpr(LParenLoc, LHS, Opc, EllipsisLoc, RHS, RParenLoc, + + // Perform first-phase name lookup now. + UnresolvedLookupExpr *ULE = nullptr; + { + UnresolvedSet<16> Functions; + LookupBinOp(S, EllipsisLoc, Opc, Functions); + if (!Functions.empty()) { + DeclarationName OpName = Context.DeclarationNames.getCXXOperatorName( + BinaryOperator::getOverloadedOperator(Opc)); + ExprResult Callee = CreateUnresolvedLookupExpr( + /*NamingClass*/ nullptr, NestedNameSpecifierLoc(), + DeclarationNameInfo(OpName, EllipsisLoc), Functions); + if (Callee.isInvalid()) + return ExprError(); + ULE = cast<UnresolvedLookupExpr>(Callee.get()); + } + } + + return BuildCXXFoldExpr(ULE, LParenLoc, LHS, Opc, EllipsisLoc, RHS, RParenLoc, None); } -ExprResult Sema::BuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS, +ExprResult Sema::BuildCXXFoldExpr(UnresolvedLookupExpr *Callee, + SourceLocation LParenLoc, Expr *LHS, BinaryOperatorKind Operator, SourceLocation EllipsisLoc, Expr *RHS, SourceLocation RParenLoc, Optional<unsigned> NumExpansions) { - return new (Context) CXXFoldExpr(Context.DependentTy, LParenLoc, LHS, - Operator, EllipsisLoc, RHS, RParenLoc, - NumExpansions); + return new (Context) + CXXFoldExpr(Context.DependentTy, Callee, LParenLoc, LHS, Operator, + EllipsisLoc, RHS, RParenLoc, NumExpansions); } ExprResult Sema::BuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc, |