Skip to content

[clang] NFC: rename MatchedPackOnParmToNonPackOnArg to StrictPackMatch #125418

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
Feb 5, 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
12 changes: 5 additions & 7 deletions clang/include/clang/AST/DeclTemplate.h
Original file line number Diff line number Diff line change
Expand Up @@ -1842,19 +1842,19 @@ class ClassTemplateSpecializationDecl : public CXXRecordDecl,
unsigned SpecializationKind : 3;

/// Indicate that we have matched a parameter pack with a non pack
/// argument, when the opposite match is also allowed (strict pack match).
/// argument, when the opposite match is also allowed.
/// This needs to be cached as deduction is performed during declaration,
/// and we need the information to be preserved so that it is consistent
/// during instantiation.
bool MatchedPackOnParmToNonPackOnArg : 1;
bool StrictPackMatch : 1;

protected:
ClassTemplateSpecializationDecl(ASTContext &Context, Kind DK, TagKind TK,
DeclContext *DC, SourceLocation StartLoc,
SourceLocation IdLoc,
ClassTemplateDecl *SpecializedTemplate,
ArrayRef<TemplateArgument> Args,
bool MatchedPackOnParmToNonPackOnArg,
bool StrictPackMatch,
ClassTemplateSpecializationDecl *PrevDecl);

ClassTemplateSpecializationDecl(ASTContext &C, Kind DK);
Expand All @@ -1867,7 +1867,7 @@ class ClassTemplateSpecializationDecl : public CXXRecordDecl,
Create(ASTContext &Context, TagKind TK, DeclContext *DC,
SourceLocation StartLoc, SourceLocation IdLoc,
ClassTemplateDecl *SpecializedTemplate,
ArrayRef<TemplateArgument> Args, bool MatchedPackOnParmToNonPackOnArg,
ArrayRef<TemplateArgument> Args, bool StrictPackMatch,
ClassTemplateSpecializationDecl *PrevDecl);
static ClassTemplateSpecializationDecl *CreateDeserialized(ASTContext &C,
GlobalDeclID ID);
Expand Down Expand Up @@ -1938,9 +1938,7 @@ class ClassTemplateSpecializationDecl : public CXXRecordDecl,
SpecializationKind = TSK;
}

bool hasMatchedPackOnParmToNonPackOnArg() const {
return MatchedPackOnParmToNonPackOnArg;
}
bool hasStrictPackMatch() const { return StrictPackMatch; }

/// Get the point of instantiation (if any), or null if none.
SourceLocation getPointOfInstantiation() const {
Expand Down
5 changes: 2 additions & 3 deletions clang/include/clang/Sema/Overload.h
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,7 @@ class Sema;
/// Have we matched any packs on the parameter side, versus any non-packs on
/// the argument side, in a context where the opposite matching is also
/// allowed?
bool HasMatchedPackOnParmToNonPackOnArg : 1;
bool StrictPackMatch : 1;

/// True if the candidate was found using ADL.
LLVM_PREFERRED_TYPE(CallExpr::ADLCallKind)
Expand Down Expand Up @@ -1010,8 +1010,7 @@ class Sema;
friend class OverloadCandidateSet;
OverloadCandidate()
: IsSurrogate(false), IgnoreObjectArgument(false),
TookAddressOfOverload(false),
HasMatchedPackOnParmToNonPackOnArg(false),
TookAddressOfOverload(false), StrictPackMatch(false),
IsADLCandidate(llvm::to_underlying(CallExpr::NotADL)),
RewriteKind(CRK_None) {}
};
Expand Down
33 changes: 15 additions & 18 deletions clang/include/clang/Sema/Sema.h
Original file line number Diff line number Diff line change
Expand Up @@ -10180,18 +10180,15 @@ class Sema final : public SemaBase {
/// \param PartialOverloading true if we are performing "partial" overloading
/// based on an incomplete set of function arguments. This feature is used by
/// code completion.
void AddOverloadCandidate(FunctionDecl *Function, DeclAccessPair FoundDecl,
ArrayRef<Expr *> Args,
OverloadCandidateSet &CandidateSet,
bool SuppressUserConversions = false,
bool PartialOverloading = false,
bool AllowExplicit = true,
bool AllowExplicitConversion = false,
ADLCallKind IsADLCandidate = ADLCallKind::NotADL,
ConversionSequenceList EarlyConversions = {},
OverloadCandidateParamOrder PO = {},
bool AggregateCandidateDeduction = false,
bool HasMatchedPackOnParmToNonPackOnArg = false);
void AddOverloadCandidate(
FunctionDecl *Function, DeclAccessPair FoundDecl, ArrayRef<Expr *> Args,
OverloadCandidateSet &CandidateSet, bool SuppressUserConversions = false,
bool PartialOverloading = false, bool AllowExplicit = true,
bool AllowExplicitConversion = false,
ADLCallKind IsADLCandidate = ADLCallKind::NotADL,
ConversionSequenceList EarlyConversions = {},
OverloadCandidateParamOrder PO = {},
bool AggregateCandidateDeduction = false, bool StrictPackMatch = false);

/// Add all of the function declarations in the given function set to
/// the overload candidate set.
Expand Down Expand Up @@ -10227,7 +10224,7 @@ class Sema final : public SemaBase {
bool PartialOverloading = false,
ConversionSequenceList EarlyConversions = {},
OverloadCandidateParamOrder PO = {},
bool HasMatchedPackOnParmToNonPackOnArg = false);
bool StrictPackMatch = false);

/// Add a C++ member function template as a candidate to the candidate
/// set, using template argument deduction to produce an appropriate member
Expand Down Expand Up @@ -10274,7 +10271,7 @@ class Sema final : public SemaBase {
CXXRecordDecl *ActingContext, Expr *From, QualType ToType,
OverloadCandidateSet &CandidateSet, bool AllowObjCConversionOnExplicit,
bool AllowExplicit, bool AllowResultConversion = true,
bool HasMatchedPackOnParmToNonPackOnArg = false);
bool StrictPackMatch = false);

/// Adds a conversion function template specialization
/// candidate to the overload set, using template argument deduction
Expand Down Expand Up @@ -11694,7 +11691,7 @@ class Sema final : public SemaBase {

/// Is set to true when, in the context of TTP matching, a pack parameter
/// matches non-pack arguments.
bool MatchedPackOnParmToNonPackOnArg = false;
bool StrictPackMatch = false;
};

/// Check that the given template argument corresponds to the given
Expand Down Expand Up @@ -11803,7 +11800,7 @@ class Sema final : public SemaBase {
TemplateParameterList *Params,
TemplateArgumentLoc &Arg,
bool PartialOrdering,
bool *MatchedPackOnParmToNonPackOnArg);
bool *StrictPackMatch);

void NoteTemplateLocation(const NamedDecl &Decl,
std::optional<SourceRange> ParamRange = {});
Expand Down Expand Up @@ -12497,7 +12494,7 @@ class Sema final : public SemaBase {
bool isTemplateTemplateParameterAtLeastAsSpecializedAs(
TemplateParameterList *PParam, TemplateDecl *PArg, TemplateDecl *AArg,
const DefaultArguments &DefaultArgs, SourceLocation ArgLoc,
bool PartialOrdering, bool *MatchedPackOnParmToNonPackOnArg);
bool PartialOrdering, bool *StrictPackMatch);

/// Mark which template parameters are used in a given expression.
///
Expand Down Expand Up @@ -13500,7 +13497,7 @@ class Sema final : public SemaBase {
SourceLocation PointOfInstantiation,
ClassTemplateSpecializationDecl *ClassTemplateSpec,
TemplateSpecializationKind TSK, bool Complain,
bool PrimaryHasMatchedPackOnParmToNonPackOnArg);
bool PrimaryStrictPackMatch);

/// Instantiates the definitions of all of the member
/// of the given class, which is an instantiation of a class template
Expand Down
10 changes: 3 additions & 7 deletions clang/include/clang/Sema/TemplateDeduction.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class TemplateDeductionInfo {
/// Have we matched any packs on the parameter side, versus any non-packs on
/// the argument side, in a context where the opposite matching is also
/// allowed?
bool MatchedPackOnParmToNonPackOnArg = false;
bool StrictPackMatch = false;

/// The template parameter depth for which we're performing deduction.
unsigned DeducedDepth;
Expand Down Expand Up @@ -92,13 +92,9 @@ class TemplateDeductionInfo {
return DeducedDepth;
}

bool hasMatchedPackOnParmToNonPackOnArg() const {
return MatchedPackOnParmToNonPackOnArg;
}
bool hasStrictPackMatch() const { return StrictPackMatch; }

void setMatchedPackOnParmToNonPackOnArg() {
MatchedPackOnParmToNonPackOnArg = true;
}
void setStrictPackMatch() { StrictPackMatch = true; }

/// Get the number of explicitly-specified arguments.
unsigned getNumExplicitArgs() const {
Expand Down
8 changes: 4 additions & 4 deletions clang/lib/AST/ASTImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6320,10 +6320,10 @@ ExpectedDecl ASTNodeImporter::VisitClassTemplateSpecializationDecl(

updateLookupTableForTemplateParameters(*ToTPList);
} else { // Not a partial specialization.
if (GetImportedOrCreateDecl(
D2, D, Importer.getToContext(), D->getTagKind(), DC, *BeginLocOrErr,
*IdLocOrErr, ClassTemplate, TemplateArgs,
D->hasMatchedPackOnParmToNonPackOnArg(), PrevDecl))
if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), D->getTagKind(),
DC, *BeginLocOrErr, *IdLocOrErr, ClassTemplate,
TemplateArgs, D->hasStrictPackMatch(),
PrevDecl))
return D2;

// Update InsertPos, because preceding import calls may have invalidated
Expand Down
18 changes: 7 additions & 11 deletions clang/lib/AST/DeclTemplate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -961,16 +961,13 @@ ClassTemplateSpecializationDecl::ClassTemplateSpecializationDecl(
ASTContext &Context, Kind DK, TagKind TK, DeclContext *DC,
SourceLocation StartLoc, SourceLocation IdLoc,
ClassTemplateDecl *SpecializedTemplate, ArrayRef<TemplateArgument> Args,
bool MatchedPackOnParmToNonPackOnArg,
ClassTemplateSpecializationDecl *PrevDecl)
bool StrictPackMatch, ClassTemplateSpecializationDecl *PrevDecl)
: CXXRecordDecl(DK, TK, Context, DC, StartLoc, IdLoc,
SpecializedTemplate->getIdentifier(), PrevDecl),
SpecializedTemplate(SpecializedTemplate),
TemplateArgs(TemplateArgumentList::CreateCopy(Context, Args)),
SpecializationKind(TSK_Undeclared),
MatchedPackOnParmToNonPackOnArg(MatchedPackOnParmToNonPackOnArg) {
assert(DK == Kind::ClassTemplateSpecialization ||
MatchedPackOnParmToNonPackOnArg == false);
SpecializationKind(TSK_Undeclared), StrictPackMatch(StrictPackMatch) {
assert(DK == Kind::ClassTemplateSpecialization || StrictPackMatch == false);
}

ClassTemplateSpecializationDecl::ClassTemplateSpecializationDecl(ASTContext &C,
Expand All @@ -982,11 +979,11 @@ ClassTemplateSpecializationDecl::ClassTemplateSpecializationDecl(ASTContext &C,
ClassTemplateSpecializationDecl *ClassTemplateSpecializationDecl::Create(
ASTContext &Context, TagKind TK, DeclContext *DC, SourceLocation StartLoc,
SourceLocation IdLoc, ClassTemplateDecl *SpecializedTemplate,
ArrayRef<TemplateArgument> Args, bool MatchedPackOnParmToNonPackOnArg,
ArrayRef<TemplateArgument> Args, bool StrictPackMatch,
ClassTemplateSpecializationDecl *PrevDecl) {
auto *Result = new (Context, DC) ClassTemplateSpecializationDecl(
Context, ClassTemplateSpecialization, TK, DC, StartLoc, IdLoc,
SpecializedTemplate, Args, MatchedPackOnParmToNonPackOnArg, PrevDecl);
SpecializedTemplate, Args, StrictPackMatch, PrevDecl);
Result->setMayHaveOutOfDateDef(false);

// If the template decl is incomplete, copy the external lexical storage from
Expand Down Expand Up @@ -1173,10 +1170,9 @@ ClassTemplatePartialSpecializationDecl::ClassTemplatePartialSpecializationDecl(
ClassTemplatePartialSpecializationDecl *PrevDecl)
: ClassTemplateSpecializationDecl(
Context, ClassTemplatePartialSpecialization, TK, DC, StartLoc, IdLoc,
// Tracking MatchedPackOnParmToNonPackOnArg for Partial
// Tracking StrictPackMatch for Partial
// Specializations is not needed.
SpecializedTemplate, Args, /*MatchedPackOnParmToNonPackOnArg=*/false,
PrevDecl),
SpecializedTemplate, Args, /*StrictPackMatch=*/false, PrevDecl),
TemplateParams(Params), InstantiatedFromMember(nullptr, false) {
if (AdoptTemplateParameterList(Params, this))
setInvalidDecl();
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/AST/JSONNodeDumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1004,7 +1004,7 @@ void JSONNodeDumper::VisitCXXRecordDecl(const CXXRecordDecl *RD) {
VisitRecordDecl(RD);

if (const auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(RD)) {
if (CTSD->hasMatchedPackOnParmToNonPackOnArg())
if (CTSD->hasStrictPackMatch())
JOS.attribute("strict-pack-match", true);
}

Expand Down
2 changes: 1 addition & 1 deletion clang/lib/AST/TextNodeDumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2527,7 +2527,7 @@ void TextNodeDumper::VisitCXXRecordDecl(const CXXRecordDecl *D) {
}
if (const auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(D)) {
dumpTemplateSpecializationKind(CTSD->getSpecializationKind());
if (CTSD->hasMatchedPackOnParmToNonPackOnArg())
if (CTSD->hasStrictPackMatch())
OS << " strict-pack-match";
}

Expand Down
30 changes: 12 additions & 18 deletions clang/lib/Sema/SemaOverload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6927,7 +6927,7 @@ void Sema::AddOverloadCandidate(
bool PartialOverloading, bool AllowExplicit, bool AllowExplicitConversions,
ADLCallKind IsADLCandidate, ConversionSequenceList EarlyConversions,
OverloadCandidateParamOrder PO, bool AggregateCandidateDeduction,
bool HasMatchedPackOnParmToNonPackOnArg) {
bool StrictPackMatch) {
const FunctionProtoType *Proto
= dyn_cast<FunctionProtoType>(Function->getType()->getAs<FunctionType>());
assert(Proto && "Functions without a prototype cannot be overloaded");
Expand All @@ -6947,7 +6947,7 @@ void Sema::AddOverloadCandidate(
Expr::Classification::makeSimpleLValue(), Args,
CandidateSet, SuppressUserConversions,
PartialOverloading, EarlyConversions, PO,
HasMatchedPackOnParmToNonPackOnArg);
StrictPackMatch);
return;
}
// We treat a constructor like a non-member function, since its object
Expand Down Expand Up @@ -6990,8 +6990,7 @@ void Sema::AddOverloadCandidate(
CandidateSet.getRewriteInfo().getRewriteKind(Function, PO);
Candidate.IsADLCandidate = llvm::to_underlying(IsADLCandidate);
Candidate.ExplicitCallArguments = Args.size();
Candidate.HasMatchedPackOnParmToNonPackOnArg =
HasMatchedPackOnParmToNonPackOnArg;
Candidate.StrictPackMatch = StrictPackMatch;

// Explicit functions are not actually candidates at all if we're not
// allowing them in this context, but keep them around so we can point
Expand Down Expand Up @@ -7563,7 +7562,7 @@ void Sema::AddMethodCandidate(
Expr::Classification ObjectClassification, ArrayRef<Expr *> Args,
OverloadCandidateSet &CandidateSet, bool SuppressUserConversions,
bool PartialOverloading, ConversionSequenceList EarlyConversions,
OverloadCandidateParamOrder PO, bool HasMatchedPackOnParmToNonPackOnArg) {
OverloadCandidateParamOrder PO, bool StrictPackMatch) {
const FunctionProtoType *Proto
= dyn_cast<FunctionProtoType>(Method->getType()->getAs<FunctionType>());
assert(Proto && "Methods without a prototype cannot be overloaded");
Expand Down Expand Up @@ -7594,8 +7593,7 @@ void Sema::AddMethodCandidate(
Candidate.TookAddressOfOverload =
CandidateSet.getKind() == OverloadCandidateSet::CSK_AddressOfOverloadSet;
Candidate.ExplicitCallArguments = Args.size();
Candidate.HasMatchedPackOnParmToNonPackOnArg =
HasMatchedPackOnParmToNonPackOnArg;
Candidate.StrictPackMatch = StrictPackMatch;

bool IgnoreExplicitObject =
(Method->isExplicitObjectMemberFunction() &&
Expand Down Expand Up @@ -7805,8 +7803,7 @@ void Sema::AddMethodTemplateCandidate(
AddMethodCandidate(cast<CXXMethodDecl>(Specialization), FoundDecl,
ActingContext, ObjectType, ObjectClassification, Args,
CandidateSet, SuppressUserConversions, PartialOverloading,
Conversions, PO,
Info.hasMatchedPackOnParmToNonPackOnArg());
Conversions, PO, Info.hasStrictPackMatch());
}

/// Determine whether a given function template has a simple explicit specifier
Expand Down Expand Up @@ -7894,7 +7891,7 @@ void Sema::AddTemplateOverloadCandidate(
PartialOverloading, AllowExplicit,
/*AllowExplicitConversions=*/false, IsADLCandidate, Conversions, PO,
Info.AggregateDeductionCandidateHasMismatchedArity,
Info.hasMatchedPackOnParmToNonPackOnArg());
Info.hasStrictPackMatch());
}

bool Sema::CheckNonDependentConversions(
Expand Down Expand Up @@ -8016,8 +8013,7 @@ void Sema::AddConversionCandidate(
CXXConversionDecl *Conversion, DeclAccessPair FoundDecl,
CXXRecordDecl *ActingContext, Expr *From, QualType ToType,
OverloadCandidateSet &CandidateSet, bool AllowObjCConversionOnExplicit,
bool AllowExplicit, bool AllowResultConversion,
bool HasMatchedPackOnParmToNonPackOnArg) {
bool AllowExplicit, bool AllowResultConversion, bool StrictPackMatch) {
assert(!Conversion->getDescribedFunctionTemplate() &&
"Conversion function templates use AddTemplateConversionCandidate");
QualType ConvType = Conversion->getConversionType().getNonReferenceType();
Expand Down Expand Up @@ -8062,8 +8058,7 @@ void Sema::AddConversionCandidate(
Candidate.FinalConversion.setAllToTypes(ToType);
Candidate.Viable = true;
Candidate.ExplicitCallArguments = 1;
Candidate.HasMatchedPackOnParmToNonPackOnArg =
HasMatchedPackOnParmToNonPackOnArg;
Candidate.StrictPackMatch = StrictPackMatch;

// Explicit functions are not actually candidates at all if we're not
// allowing them in this context, but keep them around so we can point
Expand Down Expand Up @@ -8266,7 +8261,7 @@ void Sema::AddTemplateConversionCandidate(
AddConversionCandidate(Specialization, FoundDecl, ActingDC, From, ToType,
CandidateSet, AllowObjCConversionOnExplicit,
AllowExplicit, AllowResultConversion,
Info.hasMatchedPackOnParmToNonPackOnArg());
Info.hasStrictPackMatch());
}

void Sema::AddSurrogateCandidate(CXXConversionDecl *Conversion,
Expand Down Expand Up @@ -10618,9 +10613,8 @@ bool clang::isBetterOverloadCandidate(
isa<CXXConstructorDecl>(Cand2.Function))
return isa<CXXConstructorDecl>(Cand1.Function);

if (Cand1.HasMatchedPackOnParmToNonPackOnArg !=
Cand2.HasMatchedPackOnParmToNonPackOnArg)
return Cand2.HasMatchedPackOnParmToNonPackOnArg;
if (Cand1.StrictPackMatch != Cand2.StrictPackMatch)
return Cand2.StrictPackMatch;

// -- F1 is a non-template function and F2 is a function template
// specialization, or, if not that,
Expand Down
Loading