Skip to content

[clang] fix partial ordering of NTTP packs #134461

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

Merged
merged 1 commit into from
Apr 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ Bug Fixes to C++ Support
- Improved fix for an issue with pack expansions of type constraints, where this
now also works if the constraint has non-type or template template parameters.
(#GH131798)
- Fixes to partial ordering of non-type template parameter packs. (#GH132562)
- Fix crash when evaluating the trailing requires clause of generic lambdas which are part of
a pack expansion.
- Fixes matching of nested template template parameters. (#GH130362)
Expand Down
6 changes: 3 additions & 3 deletions clang/include/clang/AST/ExprCXX.h
Original file line number Diff line number Diff line change
Expand Up @@ -4209,10 +4209,10 @@ class PackExpansionExpr : public Expr {
Stmt *Pattern;

public:
PackExpansionExpr(QualType T, Expr *Pattern, SourceLocation EllipsisLoc,
PackExpansionExpr(Expr *Pattern, SourceLocation EllipsisLoc,
UnsignedOrNone NumExpansions)
: Expr(PackExpansionExprClass, T, Pattern->getValueKind(),
Pattern->getObjectKind()),
: Expr(PackExpansionExprClass, Pattern->getType(),
Pattern->getValueKind(), Pattern->getObjectKind()),
EllipsisLoc(EllipsisLoc),
NumExpansions(NumExpansions ? *NumExpansions + 1 : 0),
Pattern(Pattern) {
Expand Down
17 changes: 9 additions & 8 deletions clang/include/clang/Sema/Sema.h
Original file line number Diff line number Diff line change
Expand Up @@ -10126,13 +10126,14 @@ class Sema final : public SemaBase {

/// Contexts in which a converted constant expression is required.
enum CCEKind {
CCEK_CaseValue, ///< Expression in a case label.
CCEK_Enumerator, ///< Enumerator value with fixed underlying type.
CCEK_TemplateArg, ///< Value of a non-type template parameter.
CCEK_InjectedTTP, ///< Injected parameter of a template template parameter.
CCEK_ArrayBound, ///< Array bound in array declarator or new-expression.
CCEK_ExplicitBool, ///< Condition in an explicit(bool) specifier.
CCEK_Noexcept, ///< Condition in a noexcept(bool) specifier.
CCEK_CaseValue, ///< Expression in a case label.
CCEK_Enumerator, ///< Enumerator value with fixed underlying type.
CCEK_TemplateArg, ///< Value of a non-type template parameter.
CCEK_TempArgStrict, ///< As above, but applies strict template checking
///< rules.
CCEK_ArrayBound, ///< Array bound in array declarator or new-expression.
CCEK_ExplicitBool, ///< Condition in an explicit(bool) specifier.
CCEK_Noexcept, ///< Condition in a noexcept(bool) specifier.
CCEK_StaticAssertMessageSize, ///< Call to size() in a static assert
///< message.
CCEK_StaticAssertMessageData, ///< Call to data() in a static assert
Expand Down Expand Up @@ -11894,7 +11895,7 @@ class Sema final : public SemaBase {
QualType InstantiatedParamType, Expr *Arg,
TemplateArgument &SugaredConverted,
TemplateArgument &CanonicalConverted,
bool MatchingTTP,
bool StrictCheck,
CheckTemplateArgumentKind CTAK);

/// Check a template argument against its corresponding
Expand Down
3 changes: 1 addition & 2 deletions clang/lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5852,8 +5852,7 @@ TemplateArgument ASTContext::getInjectedTemplateArg(NamedDecl *Param) const {
T, VK, NTTP->getLocation());

if (NTTP->isParameterPack())
E = new (*this)
PackExpansionExpr(DependentTy, E, NTTP->getLocation(), std::nullopt);
E = new (*this) PackExpansionExpr(E, NTTP->getLocation(), std::nullopt);
Arg = TemplateArgument(E);
} else {
auto *TTP = cast<TemplateTemplateParmDecl>(Param);
Expand Down
7 changes: 3 additions & 4 deletions clang/lib/AST/ASTImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8273,14 +8273,13 @@ ASTNodeImporter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) {

ExpectedStmt ASTNodeImporter::VisitPackExpansionExpr(PackExpansionExpr *E) {
Error Err = Error::success();
auto ToType = importChecked(Err, E->getType());
auto ToPattern = importChecked(Err, E->getPattern());
auto *ToPattern = importChecked(Err, E->getPattern());
auto ToEllipsisLoc = importChecked(Err, E->getEllipsisLoc());
if (Err)
return std::move(Err);

return new (Importer.getToContext()) PackExpansionExpr(
ToType, ToPattern, ToEllipsisLoc, E->getNumExpansions());
return new (Importer.getToContext())
PackExpansionExpr(ToPattern, ToEllipsisLoc, E->getNumExpansions());
}

ExpectedStmt ASTNodeImporter::VisitSizeOfPackExpr(SizeOfPackExpr *E) {
Expand Down
8 changes: 4 additions & 4 deletions clang/lib/Sema/SemaOverload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6201,7 +6201,7 @@ static ExprResult BuildConvertedConstantExpression(Sema &S, Expr *From,
Sema::CCEKind CCE,
NamedDecl *Dest,
APValue &PreNarrowingValue) {
assert((S.getLangOpts().CPlusPlus11 || CCE == Sema::CCEK_InjectedTTP) &&
assert((S.getLangOpts().CPlusPlus11 || CCE == Sema::CCEK_TempArgStrict) &&
"converted constant expression outside C++11 or TTP matching");

if (checkPlaceholderForOverload(S, From))
Expand Down Expand Up @@ -6272,7 +6272,7 @@ static ExprResult BuildConvertedConstantExpression(Sema &S, Expr *From,
// class type.
ExprResult Result;
bool IsTemplateArgument =
CCE == Sema::CCEK_TemplateArg || CCE == Sema::CCEK_InjectedTTP;
CCE == Sema::CCEK_TemplateArg || CCE == Sema::CCEK_TempArgStrict;
if (T->isRecordType()) {
assert(IsTemplateArgument &&
"unexpected class type converted constant expr");
Expand Down Expand Up @@ -6325,7 +6325,7 @@ static ExprResult BuildConvertedConstantExpression(Sema &S, Expr *From,
// value-dependent so we can't tell whether it's actually narrowing.
// For matching the parameters of a TTP, the conversion is ill-formed
// if it may narrow.
if (CCE != Sema::CCEK_InjectedTTP)
if (CCE != Sema::CCEK_TempArgStrict)
break;
[[fallthrough]];
case NK_Type_Narrowing:
Expand Down Expand Up @@ -6400,7 +6400,7 @@ Sema::EvaluateConvertedConstantExpression(Expr *E, QualType T, APValue &Value,
Expr::EvalResult Eval;
Eval.Diag = &Notes;

assert(CCE != Sema::CCEK_InjectedTTP && "unnexpected CCE Kind");
assert(CCE != Sema::CCEK_TempArgStrict && "unnexpected CCE Kind");

ConstantExprKind Kind;
if (CCE == Sema::CCEK_TemplateArg && T->isRecordType())
Expand Down
Loading