Skip to content

Commit

Permalink
[clang] NFC: cleanup check template argument (#124668)
Browse files Browse the repository at this point in the history
  • Loading branch information
mizvekov authored Jan 28, 2025
1 parent 4eb7c34 commit 6bb6c30
Show file tree
Hide file tree
Showing 5 changed files with 307 additions and 301 deletions.
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,
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

0 comments on commit 6bb6c30

Please sign in to comment.