Skip to content

Commit efcfa6e

Browse files
committed
Revert "Reland: [clang] Finish implementation of P0522 (#111711)"
See discussion in #111711 This reverts commit 6213aa5.
1 parent bdd46cc commit efcfa6e

File tree

17 files changed

+266
-652
lines changed

17 files changed

+266
-652
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,6 @@ C++23 Feature Support
177177
C++20 Feature Support
178178
^^^^^^^^^^^^^^^^^^^^^
179179

180-
C++17 Feature Support
181-
^^^^^^^^^^^^^^^^^^^^^
182-
- The implementation of the relaxed template template argument matching rules is
183-
more complete and reliable, and should provide more accurate diagnostics.
184180

185181
Resolutions to C++ Defect Reports
186182
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -338,10 +334,6 @@ Improvements to Clang's diagnostics
338334

339335
- Clang now diagnoses when the result of a [[nodiscard]] function is discarded after being cast in C. Fixes #GH104391.
340336

341-
- Clang now properly explains the reason a template template argument failed to
342-
match a template template parameter, in terms of the C++17 relaxed matching rules
343-
instead of the old ones.
344-
345337
- Don't emit duplicated dangling diagnostics. (#GH93386).
346338

347339
- Improved diagnostic when trying to befriend a concept. (#GH45182).
@@ -451,8 +443,6 @@ Bug Fixes to C++ Support
451443
- Correctly check constraints of explicit instantiations of member functions. (#GH46029)
452444
- When performing partial ordering of function templates, clang now checks that
453445
the deduction was consistent. Fixes (#GH18291).
454-
- Fixes to several issues in partial ordering of template template parameters, which
455-
were documented in the test suite.
456446
- Fixed an assertion failure about a constraint of a friend function template references to a value with greater
457447
template depth than the friend function template. (#GH98258)
458448
- Clang now rebuilds the template parameters of out-of-line declarations and specializations in the context

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5262,13 +5262,6 @@ def note_template_arg_refers_here_func : Note<
52625262
def err_template_arg_template_params_mismatch : Error<
52635263
"template template argument has different template parameters than its "
52645264
"corresponding template template parameter">;
5265-
def note_template_arg_template_params_mismatch : Note<
5266-
"template template argument has different template parameters than its "
5267-
"corresponding template template parameter">;
5268-
def err_non_deduced_mismatch : Error<
5269-
"could not match %diff{$ against $|types}0,1">;
5270-
def err_inconsistent_deduction : Error<
5271-
"conflicting deduction %diff{$ against $|types}0,1 for parameter">;
52725265
def err_template_arg_not_integral_or_enumeral : Error<
52735266
"non-type template argument of type %0 must have an integral or enumeration"
52745267
" type">;

clang/include/clang/Sema/Sema.h

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12418,9 +12418,8 @@ class Sema final : public SemaBase {
1241812418
sema::TemplateDeductionInfo &Info);
1241912419

1242012420
bool isTemplateTemplateParameterAtLeastAsSpecializedAs(
12421-
TemplateParameterList *PParam, TemplateDecl *PArg, TemplateDecl *AArg,
12422-
const DefaultArguments &DefaultArgs, SourceLocation ArgLoc,
12423-
bool IsDeduced);
12421+
TemplateParameterList *PParam, TemplateDecl *AArg,
12422+
const DefaultArguments &DefaultArgs, SourceLocation Loc, bool IsDeduced);
1242412423

1242512424
/// Mark which template parameters are used in a given expression.
1242612425
///
@@ -12729,9 +12728,6 @@ class Sema final : public SemaBase {
1272912728

1273012729
/// We are instantiating a type alias template declaration.
1273112730
TypeAliasTemplateInstantiation,
12732-
12733-
/// We are performing partial ordering for template template parameters.
12734-
PartialOrderingTTP,
1273512731
} Kind;
1273612732

1273712733
/// Was the enclosing context a non-instantiation SFINAE context?
@@ -12953,12 +12949,6 @@ class Sema final : public SemaBase {
1295312949
TemplateDecl *Entity, BuildingDeductionGuidesTag,
1295412950
SourceRange InstantiationRange = SourceRange());
1295512951

12956-
struct PartialOrderingTTP {};
12957-
/// \brief Note that we are partial ordering template template parameters.
12958-
InstantiatingTemplate(Sema &SemaRef, SourceLocation ArgLoc,
12959-
PartialOrderingTTP, TemplateDecl *PArg,
12960-
SourceRange InstantiationRange = SourceRange());
12961-
1296212952
/// Note that we have finished instantiating this template.
1296312953
void Clear();
1296412954

clang/lib/Frontend/FrontendActions.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,8 +457,6 @@ class DefaultTemplateInstCallback : public TemplateInstantiationCallback {
457457
return "BuildingDeductionGuides";
458458
case CodeSynthesisContext::TypeAliasTemplateInstantiation:
459459
return "TypeAliasTemplateInstantiation";
460-
case CodeSynthesisContext::PartialOrderingTTP:
461-
return "PartialOrderingTTP";
462460
}
463461
return "";
464462
}

clang/lib/Sema/SemaTemplate.cpp

Lines changed: 56 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5502,7 +5502,8 @@ bool Sema::CheckTemplateArgumentList(
55025502
DefaultArgs && ParamIdx >= DefaultArgs.StartPos) {
55035503
// All written arguments should have been consumed by this point.
55045504
assert(ArgIdx == NumArgs && "bad default argument deduction");
5505-
if (ParamIdx == DefaultArgs.StartPos) {
5505+
// FIXME: Don't ignore parameter packs.
5506+
if (ParamIdx == DefaultArgs.StartPos && !(*Param)->isParameterPack()) {
55065507
assert(Param + DefaultArgs.Args.size() <= ParamEnd);
55075508
// Default arguments from a DeducedTemplateName are already converted.
55085509
for (const TemplateArgument &DefArg : DefaultArgs.Args) {
@@ -5727,9 +5728,8 @@ bool Sema::CheckTemplateArgumentList(
57275728
// pack expansions; they might be empty. This can happen even if
57285729
// PartialTemplateArgs is false (the list of arguments is complete but
57295730
// still dependent).
5730-
if (PartialOrderingTTP ||
5731-
(CurrentInstantiationScope &&
5732-
CurrentInstantiationScope->getPartiallySubstitutedPack())) {
5731+
if (ArgIdx < NumArgs && CurrentInstantiationScope &&
5732+
CurrentInstantiationScope->getPartiallySubstitutedPack()) {
57335733
while (ArgIdx < NumArgs &&
57345734
NewArgs[ArgIdx].getArgument().isPackExpansion()) {
57355735
const TemplateArgument &Arg = NewArgs[ArgIdx++].getArgument();
@@ -7327,46 +7327,64 @@ bool Sema::CheckTemplateTemplateArgument(TemplateTemplateParmDecl *Param,
73277327
<< Template;
73287328
}
73297329

7330-
if (!getLangOpts().RelaxedTemplateTemplateArgs)
7331-
return !TemplateParameterListsAreEqual(
7332-
Template->getTemplateParameters(), Params, /*Complain=*/true,
7333-
TPL_TemplateTemplateArgumentMatch, Arg.getLocation());
7334-
73357330
// C++1z [temp.arg.template]p3: (DR 150)
73367331
// A template-argument matches a template template-parameter P when P
73377332
// is at least as specialized as the template-argument A.
7338-
if (!isTemplateTemplateParameterAtLeastAsSpecializedAs(
7339-
Params, Param, Template, DefaultArgs, Arg.getLocation(), IsDeduced))
7340-
return true;
7341-
// P2113
7342-
// C++20[temp.func.order]p2
7343-
// [...] If both deductions succeed, the partial ordering selects the
7344-
// more constrained template (if one exists) as determined below.
7345-
SmallVector<const Expr *, 3> ParamsAC, TemplateAC;
7346-
Params->getAssociatedConstraints(ParamsAC);
7347-
// C++20[temp.arg.template]p3
7348-
// [...] In this comparison, if P is unconstrained, the constraints on A
7349-
// are not considered.
7350-
if (ParamsAC.empty())
7351-
return false;
7333+
if (getLangOpts().RelaxedTemplateTemplateArgs) {
7334+
// Quick check for the common case:
7335+
// If P contains a parameter pack, then A [...] matches P if each of A's
7336+
// template parameters matches the corresponding template parameter in
7337+
// the template-parameter-list of P.
7338+
if (TemplateParameterListsAreEqual(
7339+
Template->getTemplateParameters(), Params, false,
7340+
TPL_TemplateTemplateArgumentMatch, Arg.getLocation()) &&
7341+
// If the argument has no associated constraints, then the parameter is
7342+
// definitely at least as specialized as the argument.
7343+
// Otherwise - we need a more thorough check.
7344+
!Template->hasAssociatedConstraints())
7345+
return false;
73527346

7353-
Template->getAssociatedConstraints(TemplateAC);
7347+
if (isTemplateTemplateParameterAtLeastAsSpecializedAs(
7348+
Params, Template, DefaultArgs, Arg.getLocation(), IsDeduced)) {
7349+
// P2113
7350+
// C++20[temp.func.order]p2
7351+
// [...] If both deductions succeed, the partial ordering selects the
7352+
// more constrained template (if one exists) as determined below.
7353+
SmallVector<const Expr *, 3> ParamsAC, TemplateAC;
7354+
Params->getAssociatedConstraints(ParamsAC);
7355+
// C++2a[temp.arg.template]p3
7356+
// [...] In this comparison, if P is unconstrained, the constraints on A
7357+
// are not considered.
7358+
if (ParamsAC.empty())
7359+
return false;
73547360

7355-
bool IsParamAtLeastAsConstrained;
7356-
if (IsAtLeastAsConstrained(Param, ParamsAC, Template, TemplateAC,
7357-
IsParamAtLeastAsConstrained))
7358-
return true;
7359-
if (!IsParamAtLeastAsConstrained) {
7360-
Diag(Arg.getLocation(),
7361-
diag::err_template_template_parameter_not_at_least_as_constrained)
7362-
<< Template << Param << Arg.getSourceRange();
7363-
Diag(Param->getLocation(), diag::note_entity_declared_at) << Param;
7364-
Diag(Template->getLocation(), diag::note_entity_declared_at) << Template;
7365-
MaybeEmitAmbiguousAtomicConstraintsDiagnostic(Param, ParamsAC, Template,
7366-
TemplateAC);
7367-
return true;
7361+
Template->getAssociatedConstraints(TemplateAC);
7362+
7363+
bool IsParamAtLeastAsConstrained;
7364+
if (IsAtLeastAsConstrained(Param, ParamsAC, Template, TemplateAC,
7365+
IsParamAtLeastAsConstrained))
7366+
return true;
7367+
if (!IsParamAtLeastAsConstrained) {
7368+
Diag(Arg.getLocation(),
7369+
diag::err_template_template_parameter_not_at_least_as_constrained)
7370+
<< Template << Param << Arg.getSourceRange();
7371+
Diag(Param->getLocation(), diag::note_entity_declared_at) << Param;
7372+
Diag(Template->getLocation(), diag::note_entity_declared_at)
7373+
<< Template;
7374+
MaybeEmitAmbiguousAtomicConstraintsDiagnostic(Param, ParamsAC, Template,
7375+
TemplateAC);
7376+
return true;
7377+
}
7378+
return false;
7379+
}
7380+
// FIXME: Produce better diagnostics for deduction failures.
73687381
}
7369-
return false;
7382+
7383+
return !TemplateParameterListsAreEqual(Template->getTemplateParameters(),
7384+
Params,
7385+
true,
7386+
TPL_TemplateTemplateArgumentMatch,
7387+
Arg.getLocation());
73707388
}
73717389

73727390
static Sema::SemaDiagnosticBuilder noteLocation(Sema &S, const NamedDecl &Decl,

0 commit comments

Comments
 (0)