Skip to content

Commit 6bb6c30

Browse files
authored
[clang] NFC: cleanup check template argument (#124668)
1 parent 4eb7c34 commit 6bb6c30

File tree

5 files changed

+307
-301
lines changed

5 files changed

+307
-301
lines changed

Diff for: clang/include/clang/Sema/Sema.h

+42-28
Original file line numberDiff line numberDiff line change
@@ -11651,6 +11651,33 @@ class Sema final : public SemaBase {
1165111651
CTAK_DeducedFromArrayBound
1165211652
};
1165311653

11654+
struct CheckTemplateArgumentInfo {
11655+
explicit CheckTemplateArgumentInfo(bool PartialOrdering = false,
11656+
bool MatchingTTP = false)
11657+
: PartialOrdering(PartialOrdering), MatchingTTP(MatchingTTP) {}
11658+
CheckTemplateArgumentInfo(const CheckTemplateArgumentInfo &) = delete;
11659+
CheckTemplateArgumentInfo &
11660+
operator=(const CheckTemplateArgumentInfo &) = delete;
11661+
11662+
/// The checked, converted argument will be added to the
11663+
/// end of these vectors.
11664+
SmallVector<TemplateArgument, 4> SugaredConverted, CanonicalConverted;
11665+
11666+
/// The check is being performed in the context of partial ordering.
11667+
bool PartialOrdering;
11668+
11669+
/// If true, assume these template arguments are
11670+
/// the injected template arguments for a template template parameter.
11671+
/// This will relax the requirement that all its possible uses are valid:
11672+
/// TTP checking is loose, and assumes that invalid uses will be diagnosed
11673+
/// during instantiation.
11674+
bool MatchingTTP;
11675+
11676+
/// Is set to true when, in the context of TTP matching, a pack parameter
11677+
/// matches non-pack arguments.
11678+
bool MatchedPackOnParmToNonPackOnArg = false;
11679+
};
11680+
1165411681
/// Check that the given template argument corresponds to the given
1165511682
/// template parameter.
1165611683
///
@@ -11670,22 +11697,16 @@ class Sema final : public SemaBase {
1167011697
/// \param ArgumentPackIndex The index into the argument pack where this
1167111698
/// argument will be placed. Only valid if the parameter is a parameter pack.
1167211699
///
11673-
/// \param Converted The checked, converted argument will be added to the
11674-
/// end of this small vector.
11675-
///
1167611700
/// \param CTAK Describes how we arrived at this particular template argument:
1167711701
/// explicitly written, deduced, etc.
1167811702
///
1167911703
/// \returns true on error, false otherwise.
11680-
bool
11681-
CheckTemplateArgument(NamedDecl *Param, TemplateArgumentLoc &Arg,
11682-
NamedDecl *Template, SourceLocation TemplateLoc,
11683-
SourceLocation RAngleLoc, unsigned ArgumentPackIndex,
11684-
SmallVectorImpl<TemplateArgument> &SugaredConverted,
11685-
SmallVectorImpl<TemplateArgument> &CanonicalConverted,
11686-
CheckTemplateArgumentKind CTAK, bool PartialOrdering,
11687-
bool PartialOrderingTTP,
11688-
bool *MatchedPackOnParmToNonPackOnArg);
11704+
bool CheckTemplateArgument(NamedDecl *Param, TemplateArgumentLoc &Arg,
11705+
NamedDecl *Template, SourceLocation TemplateLoc,
11706+
SourceLocation RAngleLoc,
11707+
unsigned ArgumentPackIndex,
11708+
CheckTemplateArgumentInfo &CTAI,
11709+
CheckTemplateArgumentKind CTAK);
1168911710

1169011711
/// Check that the given template arguments can be provided to
1169111712
/// the given template, converting the arguments along the way.
@@ -11718,22 +11739,15 @@ class Sema final : public SemaBase {
1171811739
/// \param DefaultArgs any default arguments from template specialization
1171911740
/// deduction.
1172011741
///
11721-
/// \param PartialOrderingTTP If true, assume these template arguments are
11722-
/// the injected template arguments for a template template parameter.
11723-
/// This will relax the requirement that all its possible uses are valid:
11724-
/// TTP checking is loose, and assumes that invalid uses will be diagnosed
11725-
/// during instantiation.
11726-
///
1172711742
/// \returns true if an error occurred, false otherwise.
11728-
bool CheckTemplateArgumentList(
11729-
TemplateDecl *Template, SourceLocation TemplateLoc,
11730-
TemplateArgumentListInfo &TemplateArgs,
11731-
const DefaultArguments &DefaultArgs, bool PartialTemplateArgs,
11732-
SmallVectorImpl<TemplateArgument> &SugaredConverted,
11733-
SmallVectorImpl<TemplateArgument> &CanonicalConverted,
11734-
bool UpdateArgsWithConversions = true,
11735-
bool *ConstraintsNotSatisfied = nullptr, bool PartialOrderingTTP = false,
11736-
bool *MatchedPackOnParmToNonPackOnArg = nullptr);
11743+
bool CheckTemplateArgumentList(TemplateDecl *Template,
11744+
SourceLocation TemplateLoc,
11745+
TemplateArgumentListInfo &TemplateArgs,
11746+
const DefaultArguments &DefaultArgs,
11747+
bool PartialTemplateArgs,
11748+
CheckTemplateArgumentInfo &CTAI,
11749+
bool UpdateArgsWithConversions = true,
11750+
bool *ConstraintsNotSatisfied = nullptr);
1173711751

1173811752
bool CheckTemplateTypeArgument(
1173911753
TemplateTypeParmDecl *Param, TemplateArgumentLoc &Arg,
@@ -11758,7 +11772,7 @@ class Sema final : public SemaBase {
1175811772
QualType InstantiatedParamType, Expr *Arg,
1175911773
TemplateArgument &SugaredConverted,
1176011774
TemplateArgument &CanonicalConverted,
11761-
bool PartialOrderingTTP,
11775+
bool MatchingTTP,
1176211776
CheckTemplateArgumentKind CTAK);
1176311777

1176411778
/// Check a template argument against its corresponding

Diff for: clang/lib/Sema/SemaLookup.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -3721,13 +3721,11 @@ Sema::LookupLiteralOperator(Scope *S, LookupResult &R,
37213721
// is a well-formed template argument for the template parameter.
37223722
if (StringLit) {
37233723
SFINAETrap Trap(*this);
3724-
SmallVector<TemplateArgument, 1> SugaredChecked, CanonicalChecked;
3724+
CheckTemplateArgumentInfo CTAI;
37253725
TemplateArgumentLoc Arg(TemplateArgument(StringLit), StringLit);
37263726
if (CheckTemplateArgument(
37273727
Params->getParam(0), Arg, FD, R.getNameLoc(), R.getNameLoc(),
3728-
0, SugaredChecked, CanonicalChecked, CTAK_Specified,
3729-
/*PartialOrdering=*/false, /*PartialOrderingTTP=*/false,
3730-
/*MatchedPackOnParmToNonPackOnArg=*/nullptr) ||
3728+
/*ArgumentPackIndex=*/0, CTAI, CTAK_Specified) ||
37313729
Trap.hasErrorOccurred())
37323730
IsTemplate = false;
37333731
}

0 commit comments

Comments
 (0)