diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 4702b8c10cdbb..28ac54127383a 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -708,6 +708,8 @@ Bug Fixes to C++ Support expression. - Fix a bug in access control checking due to dealyed checking of friend declaration. Fixes (#GH12361). - Correctly treat the compound statement of an ``if consteval`` as an immediate context. Fixes (#GH91509). +- When partial ordering alias templates against template template parameters, + allow pack expansions when the alias has a fixed-size parameter list. Fixes (#GH62529). Bug Fixes to AST Handling ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 4efd3878e861b..869769f95fd7f 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -9216,6 +9216,12 @@ class Sema final : public SemaBase { /// receive true if the cause for the error is the associated constraints of /// the template not being satisfied by the template arguments. /// + /// \param PartialOrderingTTP If true, assume these template arguments are + /// the injected template arguments for a template template parameter. + /// This will relax the requirement that all its possible uses are valid: + /// TTP checking is loose, and assumes that invalid uses will be diagnosed + /// during instantiation. + /// /// \returns true if an error occurred, false otherwise. bool CheckTemplateArgumentList( TemplateDecl *Template, SourceLocation TemplateLoc, @@ -9223,7 +9229,7 @@ class Sema final : public SemaBase { SmallVectorImpl &SugaredConverted, SmallVectorImpl &CanonicalConverted, bool UpdateArgsWithConversions = true, - bool *ConstraintsNotSatisfied = nullptr); + bool *ConstraintsNotSatisfied = nullptr, bool PartialOrderingTTP = false); bool CheckTemplateTypeArgument( TemplateTypeParmDecl *Param, TemplateArgumentLoc &Arg, diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index bae00c6292703..8219d5eed8db7 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -6556,7 +6556,8 @@ bool Sema::CheckTemplateArgumentList( TemplateArgumentListInfo &TemplateArgs, bool PartialTemplateArgs, SmallVectorImpl &SugaredConverted, SmallVectorImpl &CanonicalConverted, - bool UpdateArgsWithConversions, bool *ConstraintsNotSatisfied) { + bool UpdateArgsWithConversions, bool *ConstraintsNotSatisfied, + bool PartialOrderingTTP) { if (ConstraintsNotSatisfied) *ConstraintsNotSatisfied = false; @@ -6627,9 +6628,14 @@ bool Sema::CheckTemplateArgumentList( bool PackExpansionIntoNonPack = NewArgs[ArgIdx].getArgument().isPackExpansion() && (!(*Param)->isTemplateParameterPack() || getExpandedPackSize(*Param)); - if (PackExpansionIntoNonPack && (isa(Template) || - isa(Template))) { - // Core issue 1430: we have a pack expansion as an argument to an + // CWG1430: Don't diagnose this pack expansion when partial + // ordering template template parameters. Some uses of the template could + // be valid, and invalid uses will be diagnosed later during + // instantiation. + if (PackExpansionIntoNonPack && !PartialOrderingTTP && + (isa(Template) || + isa(Template))) { + // CWG1430: we have a pack expansion as an argument to an // alias template, and it's not part of a parameter pack. This // can't be canonicalized, so reject it now. // As for concepts - we cannot normalize constraints where this diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp index fe7e35d841510..853c0e1b50619 100644 --- a/clang/lib/Sema/SemaTemplateDeduction.cpp +++ b/clang/lib/Sema/SemaTemplateDeduction.cpp @@ -6243,7 +6243,9 @@ bool Sema::isTemplateTemplateParameterAtLeastAsSpecializedAs( // specialized as A. SmallVector SugaredPArgs; if (CheckTemplateArgumentList(AArg, Loc, PArgList, false, SugaredPArgs, - PArgs) || + PArgs, /*UpdateArgsWithConversions=*/true, + /*ConstraintsNotSatisfied=*/nullptr, + /*PartialOrderTTP=*/true) || Trap.hasErrorOccurred()) return false; } diff --git a/clang/test/SemaTemplate/temp_arg_template_cxx1z.cpp b/clang/test/SemaTemplate/temp_arg_template_p0522.cpp similarity index 91% rename from clang/test/SemaTemplate/temp_arg_template_cxx1z.cpp rename to clang/test/SemaTemplate/temp_arg_template_p0522.cpp index 372a00efc601e..251b6fc7d2be1 100644 --- a/clang/test/SemaTemplate/temp_arg_template_cxx1z.cpp +++ b/clang/test/SemaTemplate/temp_arg_template_p0522.cpp @@ -1,6 +1,6 @@ -// RUN: %clang_cc1 -fsyntax-only -verify -std=c++1z %s +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s -// expected-note@temp_arg_template_cxx1z.cpp:* 1+{{}} +// expected-note@temp_arg_template_p0522.cpp:* 1+{{}} template typename> struct Ti; template typename> struct TPi; @@ -118,3 +118,11 @@ namespace Auto { TInt isf; // FIXME: this should be ill-formed TIntPtr ipsf; } + +namespace GH62529 { + // Note: the constraint here is just for bypassing a fast-path. + template requires(true) using A = int; + template class TT1, class T3> struct B {}; + template B f(); + auto t = f(); +} // namespace GH62529