From edf1a2e89340c8fa64a679e7d4ec2b5ee92ec40f Mon Sep 17 00:00:00 2001 From: Matheus Izvekov Date: Fri, 28 Oct 2022 22:22:39 +0200 Subject: [PATCH] [clang] Fix handling of unexpanded packs in template argument expressions. Closes #58679. Signed-off-by: Matheus Izvekov Differential Revision: https://reviews.llvm.org/D136977 --- clang/docs/ReleaseNotes.rst | 2 ++ clang/include/clang/Sema/Sema.h | 3 ++- clang/lib/Sema/SemaExprCXX.cpp | 6 +++--- clang/lib/Sema/SemaOverload.cpp | 6 +++--- clang/lib/Sema/SemaTemplate.cpp | 7 ++----- .../CXX/temp/temp.decls/temp.variadic/p5.cpp | 19 +++++++++++++++++++ 6 files changed, 31 insertions(+), 12 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 95910fd9f426..f751f96d29e9 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -266,6 +266,8 @@ Bug Fixes `Issue 45736 `_ - Fix an issue when performing constraints partial ordering on non-template functions. `Issue 56154 `_ +- Fix handling of unexpanded packs in template argument expressions. + `Issue 58679 `_ Improvements to Clang's diagnostics ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 23b4e3f60cef..917c6c162e6d 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -6818,7 +6818,8 @@ public: Expr, Expr ? Expr->getExprLoc() : SourceLocation(), DiscardedValue); } ExprResult ActOnFinishFullExpr(Expr *Expr, SourceLocation CC, - bool DiscardedValue, bool IsConstexpr = false); + bool DiscardedValue, bool IsConstexpr = false, + bool IsTemplateArgument = false); StmtResult ActOnFinishFullStmt(Stmt *Stmt); // Marks SS invalid if it represents an incomplete type. diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp index bb9cfe30e5d4..41c4348de079 100644 --- a/clang/lib/Sema/SemaExprCXX.cpp +++ b/clang/lib/Sema/SemaExprCXX.cpp @@ -8713,14 +8713,14 @@ Sema::CorrectDelayedTyposInExpr(Expr *E, VarDecl *InitDecl, } ExprResult Sema::ActOnFinishFullExpr(Expr *FE, SourceLocation CC, - bool DiscardedValue, - bool IsConstexpr) { + bool DiscardedValue, bool IsConstexpr, + bool IsTemplateArgument) { ExprResult FullExpr = FE; if (!FullExpr.get()) return ExprError(); - if (DiagnoseUnexpandedParameterPack(FullExpr.get())) + if (!IsTemplateArgument && DiagnoseUnexpandedParameterPack(FullExpr.get())) return ExprError(); if (DiscardedValue) { diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp index 45bca3a31d3a..a65cdbed7fd0 100644 --- a/clang/lib/Sema/SemaOverload.cpp +++ b/clang/lib/Sema/SemaOverload.cpp @@ -5862,9 +5862,9 @@ static ExprResult CheckConvertedConstantExpression(Sema &S, Expr *From, // C++2a [intro.execution]p5: // A full-expression is [...] a constant-expression [...] - Result = - S.ActOnFinishFullExpr(Result.get(), From->getExprLoc(), - /*DiscardedValue=*/false, /*IsConstexpr=*/true); + Result = S.ActOnFinishFullExpr(Result.get(), From->getExprLoc(), + /*DiscardedValue=*/false, /*IsConstexpr=*/true, + CCE == Sema::CCEKind::CCEK_TemplateArg); if (Result.isInvalid()) return Result; diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index bf6acd52f285..985ac271e9d1 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -7156,11 +7156,8 @@ ExprResult Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param, } // If either the parameter has a dependent type or the argument is - // type-dependent, there's nothing we can check now. The argument only - // contains an unexpanded pack during partial ordering, and there's - // nothing more we can check in that case. - if (ParamType->isDependentType() || Arg->isTypeDependent() || - Arg->containsUnexpandedParameterPack()) { + // type-dependent, there's nothing we can check now. + if (ParamType->isDependentType() || Arg->isTypeDependent()) { // Force the argument to the type of the parameter to maintain invariants. auto *PE = dyn_cast(Arg); if (PE) diff --git a/clang/test/CXX/temp/temp.decls/temp.variadic/p5.cpp b/clang/test/CXX/temp/temp.decls/temp.variadic/p5.cpp index fb8d931710ca..2d82a4f26b14 100644 --- a/clang/test/CXX/temp/temp.decls/temp.variadic/p5.cpp +++ b/clang/test/CXX/temp/temp.decls/temp.variadic/p5.cpp @@ -502,3 +502,22 @@ template using B = char; template int C{ A>{}... }; // expected-error {{implicit instantiation of undefined template}} #endif } // namespace GH56094 + +namespace GH58679 { +#if __cplusplus >= 201402L +template constexpr int A = 1; + +template struct B; +template <> struct B<1> { using b1 = void; }; + +template using C = char; + +template int D{ B>>{}... }; + +struct E { + template >::b1> E(E1); +}; + +template int F{ E(C{})... }; +#endif +} // namespace GH58679 -- 2.34.1