-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Reland: [clang] Finish implementation of P0522 #111711
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reland: [clang] Finish implementation of P0522 #111711
Conversation
This finishes the clang implementation of P0522, getting rid of the fallback to the old, pre-P0522 rules. Before this patch, when partial ordering template template parameters, we would perform, in order: * If the old rules would match, we would accept it. Otherwise, don't generate diagnostics yet. * If the new rules would match, just accept it. Otherwise, don't generate any diagnostics yet again. * Apply the old rules again, this time with diagnostics. This situation was far from ideal, as we would sometimes: * Accept some things we shouldn't. * Reject some things we shouldn't. * Only diagnose rejection in terms of the old rules. With this patch, we apply the P0522 rules throughout. This needed to extend template argument deduction in order to accept the historial rule for TTP matching pack parameter to non-pack arguments. This change also makes us accept some combinations of historical and P0522 allowances we wouldn't before. It also fixes a bunch of bugs that were documented in the test suite, which I am not sure there are issues already created for them. This causes a lot of changes to the way these failures are diagnosed, with related test suite churn. The problem here is that the old rules were very simple and non-recursive, making it easy to provide customized diagnostics, and to keep them consistent with each other. The new rules are a lot more complex and rely on template argument deduction, substitutions, and they are recursive. The approach taken here is to mostly rely on existing diagnostics, and create a new instantiation context that keeps track of this context. So for example when a substitution failure occurs, we use the error produced there unmodified, and just attach notes to it explaining that it occurred in the context of partial ordering this template argument against that template parameter. This diverges from the old diagnostics, which would lead with an error pointing to the template argument, explain the problem in subsequent notes, and produce a final note pointing to the parameter.
@llvm/pr-subscribers-clang @llvm/pr-subscribers-clang-modules Author: Matheus Izvekov (mizvekov) ChangesThis finishes the clang implementation of P0522, getting rid of the fallback to the old, pre-P0522 rules. Before this patch, when partial ordering template template parameters, we would perform, in order:
This situation was far from ideal, as we would sometimes:
With this patch, we apply the P0522 rules throughout. This needed to extend template argument deduction in order to accept the historial rule for TTP matching pack parameter to non-pack arguments. It also fixes a bunch of bugs that were documented in the test suite, which I am not sure there are issues already created for them. This causes a lot of changes to the way these failures are diagnosed, with related test suite churn. The problem here is that the old rules were very simple and non-recursive, making it easy to provide customized diagnostics, and to keep them consistent with each other. The new rules are a lot more complex and rely on template argument deduction, substitutions, and they are recursive. The approach taken here is to mostly rely on existing diagnostics, and create a new instantiation context that keeps track of this context. So for example when a substitution failure occurs, we use the error produced there unmodified, and just attach notes to it explaining that it occurred in the context of partial ordering this template argument against that template parameter. This diverges from the old diagnostics, which would lead with an error pointing to the template argument, explain the problem in subsequent notes, and produce a final note pointing to the parameter. Patch is 73.23 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/111711.diff 17 Files Affected:
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index a4bb303a2bc42b..7270e6898dbc7f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -174,6 +174,10 @@ C++23 Feature Support
C++20 Feature Support
^^^^^^^^^^^^^^^^^^^^^
+C++17 Feature Support
+^^^^^^^^^^^^^^^^^^^^^
+- The implementation of the relaxed template template argument matching rules is
+ more complete and reliable, and should provide more accurate diagnostics.
Resolutions to C++ Defect Reports
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -331,6 +335,10 @@ Improvements to Clang's diagnostics
- Clang now diagnoses when the result of a [[nodiscard]] function is discarded after being cast in C. Fixes #GH104391.
+- Clang now properly explains the reason a template template argument failed to
+ match a template template parameter, in terms of the C++17 relaxed matching rules
+ instead of the old ones.
+
- Don't emit duplicated dangling diagnostics. (#GH93386).
- Improved diagnostic when trying to befriend a concept. (#GH45182).
@@ -440,6 +448,8 @@ Bug Fixes to C++ Support
- Correctly check constraints of explicit instantiations of member functions. (#GH46029)
- When performing partial ordering of function templates, clang now checks that
the deduction was consistent. Fixes (#GH18291).
+- Fixes to several issues in partial ordering of template template parameters, which
+ were documented in the test suite.
- Fixed an assertion failure about a constraint of a friend function template references to a value with greater
template depth than the friend function template. (#GH98258)
- Clang now rebuilds the template parameters of out-of-line declarations and specializations in the context
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 777ea1f37cea46..f4a2d4a3f0656a 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5262,6 +5262,13 @@ def note_template_arg_refers_here_func : Note<
def err_template_arg_template_params_mismatch : Error<
"template template argument has different template parameters than its "
"corresponding template template parameter">;
+def note_template_arg_template_params_mismatch : Note<
+ "template template argument has different template parameters than its "
+ "corresponding template template parameter">;
+def err_non_deduced_mismatch : Error<
+ "could not match %diff{$ against $|types}0,1">;
+def err_inconsistent_deduction : Error<
+ "conflicting deduction %diff{$ against $|types}0,1 for parameter">;
def err_template_arg_not_integral_or_enumeral : Error<
"non-type template argument of type %0 must have an integral or enumeration"
" type">;
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 86053bd7da1725..043456438b6d03 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -12417,8 +12417,9 @@ class Sema final : public SemaBase {
sema::TemplateDeductionInfo &Info);
bool isTemplateTemplateParameterAtLeastAsSpecializedAs(
- TemplateParameterList *PParam, TemplateDecl *AArg,
- const DefaultArguments &DefaultArgs, SourceLocation Loc, bool IsDeduced);
+ TemplateParameterList *PParam, TemplateDecl *PArg, TemplateDecl *AArg,
+ const DefaultArguments &DefaultArgs, SourceLocation ArgLoc,
+ bool IsDeduced);
/// Mark which template parameters are used in a given expression.
///
@@ -12727,6 +12728,9 @@ class Sema final : public SemaBase {
/// We are instantiating a type alias template declaration.
TypeAliasTemplateInstantiation,
+
+ /// We are performing partial ordering for template template parameters.
+ PartialOrderingTTP,
} Kind;
/// Was the enclosing context a non-instantiation SFINAE context?
@@ -12948,6 +12952,12 @@ class Sema final : public SemaBase {
TemplateDecl *Entity, BuildingDeductionGuidesTag,
SourceRange InstantiationRange = SourceRange());
+ struct PartialOrderingTTP {};
+ /// \brief Note that we are partial ordering template template parameters.
+ InstantiatingTemplate(Sema &SemaRef, SourceLocation ArgLoc,
+ PartialOrderingTTP, TemplateDecl *PArg,
+ SourceRange InstantiationRange = SourceRange());
+
/// Note that we have finished instantiating this template.
void Clear();
diff --git a/clang/lib/Frontend/FrontendActions.cpp b/clang/lib/Frontend/FrontendActions.cpp
index 64f90c493c1055..e4b462b9b0fd81 100644
--- a/clang/lib/Frontend/FrontendActions.cpp
+++ b/clang/lib/Frontend/FrontendActions.cpp
@@ -457,6 +457,8 @@ class DefaultTemplateInstCallback : public TemplateInstantiationCallback {
return "BuildingDeductionGuides";
case CodeSynthesisContext::TypeAliasTemplateInstantiation:
return "TypeAliasTemplateInstantiation";
+ case CodeSynthesisContext::PartialOrderingTTP:
+ return "PartialOrderingTTP";
}
return "";
}
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index dfd56debc75e99..fc56d737fb2325 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -5498,8 +5498,7 @@ bool Sema::CheckTemplateArgumentList(
DefaultArgs && ParamIdx >= DefaultArgs.StartPos) {
// All written arguments should have been consumed by this point.
assert(ArgIdx == NumArgs && "bad default argument deduction");
- // FIXME: Don't ignore parameter packs.
- if (ParamIdx == DefaultArgs.StartPos && !(*Param)->isParameterPack()) {
+ if (ParamIdx == DefaultArgs.StartPos) {
assert(Param + DefaultArgs.Args.size() <= ParamEnd);
// Default arguments from a DeducedTemplateName are already converted.
for (const TemplateArgument &DefArg : DefaultArgs.Args) {
@@ -5724,8 +5723,9 @@ bool Sema::CheckTemplateArgumentList(
// pack expansions; they might be empty. This can happen even if
// PartialTemplateArgs is false (the list of arguments is complete but
// still dependent).
- if (ArgIdx < NumArgs && CurrentInstantiationScope &&
- CurrentInstantiationScope->getPartiallySubstitutedPack()) {
+ if (PartialOrderingTTP ||
+ (CurrentInstantiationScope &&
+ CurrentInstantiationScope->getPartiallySubstitutedPack())) {
while (ArgIdx < NumArgs &&
NewArgs[ArgIdx].getArgument().isPackExpansion()) {
const TemplateArgument &Arg = NewArgs[ArgIdx++].getArgument();
@@ -7321,64 +7321,46 @@ bool Sema::CheckTemplateTemplateArgument(TemplateTemplateParmDecl *Param,
<< Template;
}
+ if (!getLangOpts().RelaxedTemplateTemplateArgs)
+ return !TemplateParameterListsAreEqual(
+ Template->getTemplateParameters(), Params, /*Complain=*/true,
+ TPL_TemplateTemplateArgumentMatch, Arg.getLocation());
+
// C++1z [temp.arg.template]p3: (DR 150)
// A template-argument matches a template template-parameter P when P
// is at least as specialized as the template-argument A.
- if (getLangOpts().RelaxedTemplateTemplateArgs) {
- // Quick check for the common case:
- // If P contains a parameter pack, then A [...] matches P if each of A's
- // template parameters matches the corresponding template parameter in
- // the template-parameter-list of P.
- if (TemplateParameterListsAreEqual(
- Template->getTemplateParameters(), Params, false,
- TPL_TemplateTemplateArgumentMatch, Arg.getLocation()) &&
- // If the argument has no associated constraints, then the parameter is
- // definitely at least as specialized as the argument.
- // Otherwise - we need a more thorough check.
- !Template->hasAssociatedConstraints())
- return false;
-
- if (isTemplateTemplateParameterAtLeastAsSpecializedAs(
- Params, Template, DefaultArgs, Arg.getLocation(), IsDeduced)) {
- // P2113
- // C++20[temp.func.order]p2
- // [...] If both deductions succeed, the partial ordering selects the
- // more constrained template (if one exists) as determined below.
- SmallVector<const Expr *, 3> ParamsAC, TemplateAC;
- Params->getAssociatedConstraints(ParamsAC);
- // C++2a[temp.arg.template]p3
- // [...] In this comparison, if P is unconstrained, the constraints on A
- // are not considered.
- if (ParamsAC.empty())
- return false;
+ if (!isTemplateTemplateParameterAtLeastAsSpecializedAs(
+ Params, Param, Template, DefaultArgs, Arg.getLocation(), IsDeduced))
+ return true;
+ // P2113
+ // C++20[temp.func.order]p2
+ // [...] If both deductions succeed, the partial ordering selects the
+ // more constrained template (if one exists) as determined below.
+ SmallVector<const Expr *, 3> ParamsAC, TemplateAC;
+ Params->getAssociatedConstraints(ParamsAC);
+ // C++20[temp.arg.template]p3
+ // [...] In this comparison, if P is unconstrained, the constraints on A
+ // are not considered.
+ if (ParamsAC.empty())
+ return false;
- Template->getAssociatedConstraints(TemplateAC);
+ Template->getAssociatedConstraints(TemplateAC);
- bool IsParamAtLeastAsConstrained;
- if (IsAtLeastAsConstrained(Param, ParamsAC, Template, TemplateAC,
- IsParamAtLeastAsConstrained))
- return true;
- if (!IsParamAtLeastAsConstrained) {
- Diag(Arg.getLocation(),
- diag::err_template_template_parameter_not_at_least_as_constrained)
- << Template << Param << Arg.getSourceRange();
- Diag(Param->getLocation(), diag::note_entity_declared_at) << Param;
- Diag(Template->getLocation(), diag::note_entity_declared_at)
- << Template;
- MaybeEmitAmbiguousAtomicConstraintsDiagnostic(Param, ParamsAC, Template,
- TemplateAC);
- return true;
- }
- return false;
- }
- // FIXME: Produce better diagnostics for deduction failures.
+ bool IsParamAtLeastAsConstrained;
+ if (IsAtLeastAsConstrained(Param, ParamsAC, Template, TemplateAC,
+ IsParamAtLeastAsConstrained))
+ return true;
+ if (!IsParamAtLeastAsConstrained) {
+ Diag(Arg.getLocation(),
+ diag::err_template_template_parameter_not_at_least_as_constrained)
+ << Template << Param << Arg.getSourceRange();
+ Diag(Param->getLocation(), diag::note_entity_declared_at) << Param;
+ Diag(Template->getLocation(), diag::note_entity_declared_at) << Template;
+ MaybeEmitAmbiguousAtomicConstraintsDiagnostic(Param, ParamsAC, Template,
+ TemplateAC);
+ return true;
}
-
- return !TemplateParameterListsAreEqual(Template->getTemplateParameters(),
- Params,
- true,
- TPL_TemplateTemplateArgumentMatch,
- Arg.getLocation());
+ return false;
}
static Sema::SemaDiagnosticBuilder noteLocation(Sema &S, const NamedDecl &Decl,
diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp
index dfae0d6cda0d9b..2d527e662fe3b4 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -145,7 +145,9 @@ static TemplateDeductionResult DeduceTemplateArgumentsByTypeMatch(
PartialOrderingKind POK, bool DeducedFromArrayBound,
bool *HasDeducedAnyParam);
-enum class PackFold { ParameterToArgument, ArgumentToParameter };
+/// What directions packs are allowed to match non-packs.
+enum class PackFold { ParameterToArgument, ArgumentToParameter, Both };
+
static TemplateDeductionResult
DeduceTemplateArguments(Sema &S, TemplateParameterList *TemplateParams,
ArrayRef<TemplateArgument> Ps,
@@ -1711,7 +1713,21 @@ static TemplateDeductionResult DeduceTemplateArgumentsByTypeMatch(
DeducedTemplateArgument Result =
checkDeducedTemplateArguments(S.Context, Deduced[Index], NewDeduced);
if (Result.isNull()) {
- Info.Param = cast<TemplateTypeParmDecl>(TemplateParams->getParam(Index));
+ // We can also get inconsistencies when matching NTTP type.
+ switch (NamedDecl *Param = TemplateParams->getParam(Index);
+ Param->getKind()) {
+ case Decl::TemplateTypeParm:
+ Info.Param = cast<TemplateTypeParmDecl>(Param);
+ break;
+ case Decl::NonTypeTemplateParm:
+ Info.Param = cast<NonTypeTemplateParmDecl>(Param);
+ break;
+ case Decl::TemplateTemplateParm:
+ Info.Param = cast<TemplateTemplateParmDecl>(Param);
+ break;
+ default:
+ llvm_unreachable("unexpected kind");
+ }
Info.FirstArg = Deduced[Index];
Info.SecondArg = NewDeduced;
return TemplateDeductionResult::Inconsistent;
@@ -2549,8 +2565,31 @@ DeduceTemplateArguments(Sema &S, TemplateParameterList *TemplateParams,
if (const NonTypeTemplateParmDecl *NTTP =
getDeducedParameterFromExpr(Info, P.getAsExpr())) {
switch (A.getKind()) {
+ case TemplateArgument::Expression: {
+ const Expr *E = A.getAsExpr();
+ // When checking NTTP, if either the parameter or the argument is
+ // dependent, as there would be otherwise nothing to deduce, we force
+ // the argument to the parameter type using this dependent implicit
+ // cast, in order to maintain invariants. Now we can deduce the
+ // resulting type from the original type, and deduce the original type
+ // against the parameter we are checking.
+ if (const auto *ICE = dyn_cast<ImplicitCastExpr>(E);
+ ICE && ICE->getCastKind() == clang::CK_Dependent) {
+ E = ICE->getSubExpr();
+ if (auto Result = DeduceTemplateArgumentsByTypeMatch(
+ S, TemplateParams, ICE->getType(), E->getType(), Info,
+ Deduced, TDF_SkipNonDependent,
+ PartialOrdering ? PartialOrderingKind::NonCall
+ : PartialOrderingKind::None,
+ /*DeducedFromArrayBound=*/false, HasDeducedAnyParam);
+ Result != TemplateDeductionResult::Success)
+ return Result;
+ }
+ return DeduceNonTypeTemplateArgument(
+ S, TemplateParams, NTTP, DeducedTemplateArgument(A), E->getType(),
+ Info, PartialOrdering, Deduced, HasDeducedAnyParam);
+ }
case TemplateArgument::Integral:
- case TemplateArgument::Expression:
case TemplateArgument::StructuralValue:
return DeduceNonTypeTemplateArgument(
S, TemplateParams, NTTP, DeducedTemplateArgument(A),
@@ -2639,50 +2678,75 @@ DeduceTemplateArguments(Sema &S, TemplateParameterList *TemplateParams,
SmallVectorImpl<DeducedTemplateArgument> &Deduced,
bool NumberOfArgumentsMustMatch, bool PartialOrdering,
PackFold PackFold, bool *HasDeducedAnyParam) {
- if (PackFold == PackFold::ArgumentToParameter)
- std::swap(Ps, As);
+ bool FoldPackParameter = PackFold == PackFold::ParameterToArgument ||
+ PackFold == PackFold::Both,
+ FoldPackArgument = PackFold == PackFold::ArgumentToParameter ||
+ PackFold == PackFold::Both;
+
// C++0x [temp.deduct.type]p9:
// If the template argument list of P contains a pack expansion that is not
// the last template argument, the entire template argument list is a
// non-deduced context.
- if (hasPackExpansionBeforeEnd(Ps))
+ if (FoldPackParameter && hasPackExpansionBeforeEnd(Ps))
+ return TemplateDeductionResult::Success;
+
+ if (FoldPackArgument && hasPackExpansionBeforeEnd(As))
return TemplateDeductionResult::Success;
// C++0x [temp.deduct.type]p9:
// If P has a form that contains <T> or <i>, then each argument Pi of the
// respective template argument list P is compared with the corresponding
// argument Ai of the corresponding template argument list of A.
- unsigned ArgIdx = 0, ParamIdx = 0;
- for (; hasTemplateArgumentForDeduction(Ps, ParamIdx); ++ParamIdx) {
- const TemplateArgument &P = Ps[ParamIdx];
- if (!P.isPackExpansion()) {
+ for (unsigned ArgIdx = 0, ParamIdx = 0; /**/; /**/) {
+ if (!hasTemplateArgumentForDeduction(Ps, ParamIdx))
+ return !FoldPackParameter && hasTemplateArgumentForDeduction(As, ArgIdx)
+ ? TemplateDeductionResult::MiscellaneousDeductionFailure
+ : TemplateDeductionResult::Success;
+
+ if (!Ps[ParamIdx].isPackExpansion()) {
// The simple case: deduce template arguments by matching Pi and Ai.
// Check whether we have enough arguments.
if (!hasTemplateArgumentForDeduction(As, ArgIdx))
- return NumberOfArgumentsMustMatch
+ return !FoldPackArgument && NumberOfArgumentsMustMatch
? TemplateDeductionResult::MiscellaneousDeductionFailure
: TemplateDeductionResult::Success;
- // C++1z [temp.deduct.type]p9:
- // During partial ordering, if Ai was originally a pack expansion [and]
- // Pi is not a pack expansion, template argument deduction fails.
- if (As[ArgIdx].isPackExpansion())
- return TemplateDeductionResult::MiscellaneousDeductionFailure;
+ if (As[ArgIdx].isPackExpansion()) {
+ // C++1z [temp.deduct.type]p9:
+ // During partial ordering, if Ai was originally a pack expansion
+ // [and] Pi is not a pack expansion, template argument deduction
+ // fails.
+ if (!FoldPackArgument)
+ return TemplateDeductionResult::MiscellaneousDeductionFailure;
+
+ TemplateArgument Pattern = As[ArgIdx].getPackExpansionPattern();
+ for (;;) {
+ // Deduce template parameters from the pattern.
+ if (auto Result = DeduceTemplateArguments(
+ S, TemplateParams, Ps[ParamIdx], Pattern, Info,
+ PartialOrdering, Deduced, HasDeducedAnyParam);
+ Result != TemplateDeductionResult::Success)
+ return Result;
- // Perform deduction for this Pi/Ai pair.
- TemplateArgument Pi = P, Ai = As[ArgIdx];
- if (PackFold == PackFold::ArgumentToParameter)
- std::swap(Pi, Ai);
- if (auto Result = DeduceTemplateArguments(S, TemplateParams, Pi, Ai, Info,
- PartialOrdering, Deduced,
- HasDeducedAnyParam);
- Result != TemplateDeductionResult::Success)
- return Result;
+ ++ParamIdx;
+ if (!hasTemplateArgumentForDeduction(Ps, ParamIdx))
+ return TemplateDeductionResult::Success;
+ if (Ps[ParamIdx].isPackExpansion())
+ break;
+ }
+ } else {
+ // Perform deduction for this Pi/Ai pair.
+ if (auto Result = DeduceTemplateArguments(
+ S, TemplateParams, Ps[ParamIdx], As[ArgIdx], Info,
+ PartialOrdering, Deduced, HasDeducedAnyParam);
+ Result != TemplateDeductionResult::Success)
+ return Result;
- // Move to the next argument.
- ++ArgIdx;
- continue;
+ ++ArgIdx;
+ ++ParamIdx;
+ continue;
+ }
}
// The parameter is a pack expansion.
@@ -2692,7 +2756,7 @@ DeduceTemplateArguments(Sema &S, TemplateParameterList *TemplateParams,
// each remaining argument in the template argument list of A. Each
// comparison deduces template arguments for subsequent positions in the
// template parameter packs expanded by Pi.
- TemplateArgument Pattern = P.getPackExpansionPattern();
+ TemplateArgument Pattern = Ps[ParamIdx].getPackExpansionPattern();
// Prepare to deduce the packs within the pattern.
PackDeductionScope PackScope(S, TemplateParams, Deduced, Info, Pattern);
@@ -2703,13 +2767,12 @@ DeduceTemplateArguments(Sema &S, TemplateParameterList *TemplateParams,
for (; hasTemplateArgumentForDeduction(As, ArgIdx) &&
PackScope.hasNextElement();
++ArgIdx) {
- TemplateArgument Pi = Pattern, A...
[truncated]
|
What's the difference between this pr and the one that was reverted? |
No difference at all. It's just that the PR which will take care of the problem is not small, so I want to keep them separate and merge them all in one go. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, i see.
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/123/builds/7265 Here is the relevant piece of the build log for the reference
|
To make it easier to find, that PR is #111457 and it landed soon after. |
Here's another test-case which is broken by this commit (both at this commit, and after the follow-up PRs). It seems to no longer allow non-type template packs of multiple types. I'm surprised we have no test-cases for this in the clang test-suite!
|
I am going to revert this, sorry |
…ent-indentonly * llvm-trunk/main: (6379 commits) [gn build] Port 1c94388 [RISCV] Introduce VLOptimizer pass (llvm#108640) [mlir][vector] Add more tests for ConvertVectorToLLVM (7/n) (llvm#111895) [libc++] Add output groups to run-buildbot (llvm#111739) [libc++abi] Remove unused LIBCXXABI_LIBCXX_INCLUDES CMake option (llvm#111824) [clang] Ignore inline namespace for `hasName` (llvm#109147) [AArch64] Disable consecutive store merging when Neon is unavailable (llvm#111519) [lldb] Fix finding make tool for tests (llvm#111980) Turn `-Wdeprecated-literal-operator` on by default (llvm#111027) [AMDGPU] Rewrite RegSeqNames using !foreach. NFC. (llvm#111994) Revert "Reland: [clang] Finish implementation of P0522 (llvm#111711)" Revert "[clang] CWG2398: improve overload resolution backwards compat (llvm#107350)" Revert "[clang] Implement TTP P0522 pack matching for deduced function template calls. (llvm#111457)" [Clang] Replace Intrinsic::getDeclaration with getOrInsertDeclaration (llvm#111990) Revert "[NVPTX] Prefer prmt.b32 over bfi.b32 (llvm#110766)" [RISCV] Add DAG combine to turn (sub (shl X, 8-Y), (shr X, Y)) into orc.b (llvm#111828) [libc] Fix compilation of new trig functions (llvm#111987) [NFC] Rename `Intrinsic::getDeclaration` to `getOrInsertDeclaration` (llvm#111752) [NFC][CodingStandard] Add additional example for if-else brace rule (llvm#111733) CodeGen: Remove redundant REQUIRES registered-target from tests (llvm#111982) ...
This finishes the clang implementation of P0522, getting rid of the fallback to the old, pre-P0522 rules. Before this patch, when partial ordering template template parameters, we would perform, in order: * If the old rules would match, we would accept it. Otherwise, don't generate diagnostics yet. * If the new rules would match, just accept it. Otherwise, don't generate any diagnostics yet again. * Apply the old rules again, this time with diagnostics. This situation was far from ideal, as we would sometimes: * Accept some things we shouldn't. * Reject some things we shouldn't. * Only diagnose rejection in terms of the old rules. With this patch, we apply the P0522 rules throughout. This needed to extend template argument deduction in order to accept the historial rule for TTP matching pack parameter to non-pack arguments. This change also makes us accept some combinations of historical and P0522 allowances we wouldn't before. It also fixes a bunch of bugs that were documented in the test suite, which I am not sure there are issues already created for them. This causes a lot of changes to the way these failures are diagnosed, with related test suite churn. The problem here is that the old rules were very simple and non-recursive, making it easy to provide customized diagnostics, and to keep them consistent with each other. The new rules are a lot more complex and rely on template argument deduction, substitutions, and they are recursive. The approach taken here is to mostly rely on existing diagnostics, and create a new instantiation context that keeps track of this context. So for example when a substitution failure occurs, we use the error produced there unmodified, and just attach notes to it explaining that it occurred in the context of partial ordering this template argument against that template parameter. This diverges from the old diagnostics, which would lead with an error pointing to the template argument, explain the problem in subsequent notes, and produce a final note pointing to the parameter.
…n template calls. (llvm#111457)" See discussion in llvm#111711 This reverts commit 4dadf42.
…llvm#107350)" See discussion in llvm#111711 This reverts commit 224519b.
See discussion in llvm#111711 This reverts commit 6213aa5.
…ation of P3310 (#124137) This patch relands the following PRs: * #111711 * #107350 * #111457 All of these patches were reverted due to an issue reported in #111711 (comment), due to interdependencies. --- [clang] Finish implementation of P0522 This finishes the clang implementation of P0522, getting rid of the fallback to the old, pre-P0522 rules. Before this patch, when partial ordering template template parameters, we would perform, in order: * If the old rules would match, we would accept it. Otherwise, don't generate diagnostics yet. * If the new rules would match, just accept it. Otherwise, don't generate any diagnostics yet again. * Apply the old rules again, this time with diagnostics. This situation was far from ideal, as we would sometimes: * Accept some things we shouldn't. * Reject some things we shouldn't. * Only diagnose rejection in terms of the old rules. With this patch, we apply the P0522 rules throughout. This needed to extend template argument deduction in order to accept the historial rule for TTP matching pack parameter to non-pack arguments. This change also makes us accept some combinations of historical and P0522 allowances we wouldn't before. It also fixes a bunch of bugs that were documented in the test suite, which I am not sure there are issues already created for them. This causes a lot of changes to the way these failures are diagnosed, with related test suite churn. The problem here is that the old rules were very simple and non-recursive, making it easy to provide customized diagnostics, and to keep them consistent with each other. The new rules are a lot more complex and rely on template argument deduction, substitutions, and they are recursive. The approach taken here is to mostly rely on existing diagnostics, and create a new instantiation context that keeps track of this context. So for example when a substitution failure occurs, we use the error produced there unmodified, and just attach notes to it explaining that it occurred in the context of partial ordering this template argument against that template parameter. This diverges from the old diagnostics, which would lead with an error pointing to the template argument, explain the problem in subsequent notes, and produce a final note pointing to the parameter. --- [clang] CWG2398: improve overload resolution backwards compat With this change, we discriminate if the primary template and which partial specializations would have participated in overload resolution prior to P0522 changes. We collect those in an initial set. If this set is not empty, or the primary template would have matched, we proceed with this set as the candidates for overload resolution. Otherwise, we build a new overload set with everything else, and proceed as usual. --- [clang] Implement TTP 'reversed' pack matching for deduced function template calls. Clang previously missed implementing P0522 pack matching for deduced function template calls.
…s implementation of P3310 (#124137) This patch relands the following PRs: * #111711 * #107350 * #111457 All of these patches were reverted due to an issue reported in llvm/llvm-project#111711 (comment), due to interdependencies. --- [clang] Finish implementation of P0522 This finishes the clang implementation of P0522, getting rid of the fallback to the old, pre-P0522 rules. Before this patch, when partial ordering template template parameters, we would perform, in order: * If the old rules would match, we would accept it. Otherwise, don't generate diagnostics yet. * If the new rules would match, just accept it. Otherwise, don't generate any diagnostics yet again. * Apply the old rules again, this time with diagnostics. This situation was far from ideal, as we would sometimes: * Accept some things we shouldn't. * Reject some things we shouldn't. * Only diagnose rejection in terms of the old rules. With this patch, we apply the P0522 rules throughout. This needed to extend template argument deduction in order to accept the historial rule for TTP matching pack parameter to non-pack arguments. This change also makes us accept some combinations of historical and P0522 allowances we wouldn't before. It also fixes a bunch of bugs that were documented in the test suite, which I am not sure there are issues already created for them. This causes a lot of changes to the way these failures are diagnosed, with related test suite churn. The problem here is that the old rules were very simple and non-recursive, making it easy to provide customized diagnostics, and to keep them consistent with each other. The new rules are a lot more complex and rely on template argument deduction, substitutions, and they are recursive. The approach taken here is to mostly rely on existing diagnostics, and create a new instantiation context that keeps track of this context. So for example when a substitution failure occurs, we use the error produced there unmodified, and just attach notes to it explaining that it occurred in the context of partial ordering this template argument against that template parameter. This diverges from the old diagnostics, which would lead with an error pointing to the template argument, explain the problem in subsequent notes, and produce a final note pointing to the parameter. --- [clang] CWG2398: improve overload resolution backwards compat With this change, we discriminate if the primary template and which partial specializations would have participated in overload resolution prior to P0522 changes. We collect those in an initial set. If this set is not empty, or the primary template would have matched, we proceed with this set as the candidates for overload resolution. Otherwise, we build a new overload set with everything else, and proceed as usual. --- [clang] Implement TTP 'reversed' pack matching for deduced function template calls. Clang previously missed implementing P0522 pack matching for deduced function template calls.
This finishes the clang implementation of P0522, getting rid of the fallback to the old, pre-P0522 rules.
Before this patch, when partial ordering template template parameters, we would perform, in order:
This situation was far from ideal, as we would sometimes:
With this patch, we apply the P0522 rules throughout.
This needed to extend template argument deduction in order to accept the historial rule for TTP matching pack parameter to non-pack arguments.
This change also makes us accept some combinations of historical and P0522 allowances we wouldn't before.
It also fixes a bunch of bugs that were documented in the test suite, which I am not sure there are issues already created for them.
This causes a lot of changes to the way these failures are diagnosed, with related test suite churn.
The problem here is that the old rules were very simple and non-recursive, making it easy to provide customized diagnostics, and to keep them consistent with each other.
The new rules are a lot more complex and rely on template argument deduction, substitutions, and they are recursive.
The approach taken here is to mostly rely on existing diagnostics, and create a new instantiation context that keeps track of this context.
So for example when a substitution failure occurs, we use the error produced there unmodified, and just attach notes to it explaining that it occurred in the context of partial ordering this template argument against that template parameter.
This diverges from the old diagnostics, which would lead with an error pointing to the template argument, explain the problem in subsequent notes, and produce a final note pointing to the parameter.