Skip to content
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

[clang] NFC: cleanup check template argument #124668

Merged
merged 1 commit into from
Jan 28, 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
70 changes: 42 additions & 28 deletions clang/include/clang/Sema/Sema.h
Original file line number Diff line number Diff line change
Expand Up @@ -11651,6 +11651,33 @@ class Sema final : public SemaBase {
CTAK_DeducedFromArrayBound
};

struct CheckTemplateArgumentInfo {
explicit CheckTemplateArgumentInfo(bool PartialOrdering = false,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This constructor doesn't make it completely better? We still end up having 2 very similar bools (actually, looks like 3?) that are pretty easily confused.

I DO like the documentation and pulling the converted together into 1 though. But it would be great if we had a better way to represent the bools that made construction less obtuse.

bool MatchingTTP = false)
: PartialOrdering(PartialOrdering), MatchingTTP(MatchingTTP) {}
CheckTemplateArgumentInfo(const CheckTemplateArgumentInfo &) = delete;
CheckTemplateArgumentInfo &
operator=(const CheckTemplateArgumentInfo &) = delete;

/// The checked, converted argument will be added to the
/// end of these vectors.
SmallVector<TemplateArgument, 4> SugaredConverted, CanonicalConverted;

/// The check is being performed in the context of partial ordering.
bool PartialOrdering;

/// 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.
bool MatchingTTP;

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

/// Check that the given template argument corresponds to the given
/// template parameter.
///
Expand All @@ -11670,22 +11697,16 @@ class Sema final : public SemaBase {
/// \param ArgumentPackIndex The index into the argument pack where this
/// argument will be placed. Only valid if the parameter is a parameter pack.
///
/// \param Converted The checked, converted argument will be added to the
/// end of this small vector.
///
/// \param CTAK Describes how we arrived at this particular template argument:
/// explicitly written, deduced, etc.
///
/// \returns true on error, false otherwise.
bool
CheckTemplateArgument(NamedDecl *Param, TemplateArgumentLoc &Arg,
NamedDecl *Template, SourceLocation TemplateLoc,
SourceLocation RAngleLoc, unsigned ArgumentPackIndex,
SmallVectorImpl<TemplateArgument> &SugaredConverted,
SmallVectorImpl<TemplateArgument> &CanonicalConverted,
CheckTemplateArgumentKind CTAK, bool PartialOrdering,
bool PartialOrderingTTP,
bool *MatchedPackOnParmToNonPackOnArg);
bool CheckTemplateArgument(NamedDecl *Param, TemplateArgumentLoc &Arg,
NamedDecl *Template, SourceLocation TemplateLoc,
SourceLocation RAngleLoc,
unsigned ArgumentPackIndex,
CheckTemplateArgumentInfo &CTAI,
CheckTemplateArgumentKind CTAK);

/// Check that the given template arguments can be provided to
/// the given template, converting the arguments along the way.
Expand Down Expand Up @@ -11718,22 +11739,15 @@ class Sema final : public SemaBase {
/// \param DefaultArgs any default arguments from template specialization
/// deduction.
///
/// \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,
TemplateArgumentListInfo &TemplateArgs,
const DefaultArguments &DefaultArgs, bool PartialTemplateArgs,
SmallVectorImpl<TemplateArgument> &SugaredConverted,
SmallVectorImpl<TemplateArgument> &CanonicalConverted,
bool UpdateArgsWithConversions = true,
bool *ConstraintsNotSatisfied = nullptr, bool PartialOrderingTTP = false,
bool *MatchedPackOnParmToNonPackOnArg = nullptr);
bool CheckTemplateArgumentList(TemplateDecl *Template,
SourceLocation TemplateLoc,
TemplateArgumentListInfo &TemplateArgs,
const DefaultArguments &DefaultArgs,
bool PartialTemplateArgs,
CheckTemplateArgumentInfo &CTAI,
bool UpdateArgsWithConversions = true,
bool *ConstraintsNotSatisfied = nullptr);

bool CheckTemplateTypeArgument(
TemplateTypeParmDecl *Param, TemplateArgumentLoc &Arg,
Expand All @@ -11758,7 +11772,7 @@ class Sema final : public SemaBase {
QualType InstantiatedParamType, Expr *Arg,
TemplateArgument &SugaredConverted,
TemplateArgument &CanonicalConverted,
bool PartialOrderingTTP,
bool MatchingTTP,
CheckTemplateArgumentKind CTAK);

/// Check a template argument against its corresponding
Expand Down
6 changes: 2 additions & 4 deletions clang/lib/Sema/SemaLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3721,13 +3721,11 @@ Sema::LookupLiteralOperator(Scope *S, LookupResult &R,
// is a well-formed template argument for the template parameter.
if (StringLit) {
SFINAETrap Trap(*this);
SmallVector<TemplateArgument, 1> SugaredChecked, CanonicalChecked;
CheckTemplateArgumentInfo CTAI;
TemplateArgumentLoc Arg(TemplateArgument(StringLit), StringLit);
if (CheckTemplateArgument(
Params->getParam(0), Arg, FD, R.getNameLoc(), R.getNameLoc(),
0, SugaredChecked, CanonicalChecked, CTAK_Specified,
/*PartialOrdering=*/false, /*PartialOrderingTTP=*/false,
/*MatchedPackOnParmToNonPackOnArg=*/nullptr) ||
/*ArgumentPackIndex=*/0, CTAI, CTAK_Specified) ||
Trap.hasErrorOccurred())
IsTemplate = false;
}
Expand Down
Loading