[clang] b1f1ce7 - Revert "[clang] Changes to produce sugared converted template arguments"
Matheus Izvekov via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 26 01:16:04 PDT 2022
Author: Matheus Izvekov
Date: 2022-10-26T10:14:40+02:00
New Revision: b1f1ce782c6308ae10146801bf4a6865a7429c96
URL: https://github.com/llvm/llvm-project/commit/b1f1ce782c6308ae10146801bf4a6865a7429c96
DIFF: https://github.com/llvm/llvm-project/commit/b1f1ce782c6308ae10146801bf4a6865a7429c96.diff
LOG: Revert "[clang] Changes to produce sugared converted template arguments"
This reverts commit 11ce78940b4c6f44ae6ee5a6611d6c9b1bade1c2.
Added:
Modified:
clang/include/clang/Sema/Sema.h
clang/include/clang/Sema/TemplateDeduction.h
clang/lib/Sema/SemaLookup.cpp
clang/lib/Sema/SemaOverload.cpp
clang/lib/Sema/SemaTemplate.cpp
clang/lib/Sema/SemaTemplateDeduction.cpp
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/test/SemaCXX/ppc-pair-mma-types.cpp
clang/test/SemaTemplate/deduction.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 0fdc69ef7e1df..e84e6b22f2817 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -8224,13 +8224,14 @@ class Sema final {
CTAK_DeducedFromArrayBound
};
- bool
- CheckTemplateArgument(NamedDecl *Param, TemplateArgumentLoc &Arg,
- NamedDecl *Template, SourceLocation TemplateLoc,
- SourceLocation RAngleLoc, unsigned ArgumentPackIndex,
- SmallVectorImpl<TemplateArgument> &SugaredConverted,
- SmallVectorImpl<TemplateArgument> &CanonicalConverted,
- CheckTemplateArgumentKind CTAK);
+ bool CheckTemplateArgument(NamedDecl *Param,
+ TemplateArgumentLoc &Arg,
+ NamedDecl *Template,
+ SourceLocation TemplateLoc,
+ SourceLocation RAngleLoc,
+ unsigned ArgumentPackIndex,
+ SmallVectorImpl<TemplateArgument> &Converted,
+ CheckTemplateArgumentKind CTAK = CTAK_Specified);
/// Check that the given template arguments can be be provided to
/// the given template, converting the arguments along the way.
@@ -8261,25 +8262,23 @@ class Sema final {
/// the template not being satisfied by the template arguments.
///
/// \returns true if an error occurred, false otherwise.
- bool CheckTemplateArgumentList(
- TemplateDecl *Template, SourceLocation TemplateLoc,
- TemplateArgumentListInfo &TemplateArgs, bool PartialTemplateArgs,
- SmallVectorImpl<TemplateArgument> &SugaredConverted,
- SmallVectorImpl<TemplateArgument> &CanonicalConverted,
- bool UpdateArgsWithConversions = true,
- bool *ConstraintsNotSatisfied = nullptr);
-
- bool CheckTemplateTypeArgument(
- TemplateTypeParmDecl *Param, TemplateArgumentLoc &Arg,
- SmallVectorImpl<TemplateArgument> &SugaredConverted,
- SmallVectorImpl<TemplateArgument> &CanonicalConverted);
+ bool CheckTemplateArgumentList(TemplateDecl *Template,
+ SourceLocation TemplateLoc,
+ TemplateArgumentListInfo &TemplateArgs,
+ bool PartialTemplateArgs,
+ SmallVectorImpl<TemplateArgument> &Converted,
+ bool UpdateArgsWithConversions = true,
+ bool *ConstraintsNotSatisfied = nullptr);
+
+ bool CheckTemplateTypeArgument(TemplateTypeParmDecl *Param,
+ TemplateArgumentLoc &Arg,
+ SmallVectorImpl<TemplateArgument> &Converted);
bool CheckTemplateArgument(TypeSourceInfo *Arg);
ExprResult CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
QualType InstantiatedParamType, Expr *Arg,
- TemplateArgument &SugaredConverted,
- TemplateArgument &CanonicalConverted,
- CheckTemplateArgumentKind CTAK);
+ TemplateArgument &Converted,
+ CheckTemplateArgumentKind CTAK = CTAK_Specified);
bool CheckTemplateTemplateArgument(TemplateTemplateParmDecl *Param,
TemplateParameterList *Params,
TemplateArgumentLoc &Arg);
diff --git a/clang/include/clang/Sema/TemplateDeduction.h b/clang/include/clang/Sema/TemplateDeduction.h
index ba35a5a744959..c0af9f3260b6d 100644
--- a/clang/include/clang/Sema/TemplateDeduction.h
+++ b/clang/include/clang/Sema/TemplateDeduction.h
@@ -41,7 +41,7 @@ namespace sema {
/// TemplateDeductionResult value.
class TemplateDeductionInfo {
/// The deduced template argument list.
- TemplateArgumentList *DeducedSugared = nullptr, *DeducedCanonical = nullptr;
+ TemplateArgumentList *Deduced = nullptr;
/// The source location at which template argument
/// deduction is occurring.
@@ -71,8 +71,8 @@ class TemplateDeductionInfo {
/// Create temporary template deduction info for speculatively deducing
/// against a base class of an argument's type.
TemplateDeductionInfo(ForBaseTag, const TemplateDeductionInfo &Info)
- : DeducedSugared(Info.DeducedSugared), Loc(Info.Loc),
- DeducedDepth(Info.DeducedDepth), ExplicitArgs(Info.ExplicitArgs) {}
+ : Deduced(Info.Deduced), Loc(Info.Loc), DeducedDepth(Info.DeducedDepth),
+ ExplicitArgs(Info.ExplicitArgs) {}
/// Returns the location at which template argument is
/// occurring.
@@ -91,15 +91,10 @@ class TemplateDeductionInfo {
return ExplicitArgs;
}
- /// Take ownership of the deduced template argument lists.
- TemplateArgumentList *takeSugared() {
- TemplateArgumentList *Result = DeducedSugared;
- DeducedSugared = nullptr;
- return Result;
- }
- TemplateArgumentList *takeCanonical() {
- TemplateArgumentList *Result = DeducedCanonical;
- DeducedCanonical = nullptr;
+ /// Take ownership of the deduced template argument list.
+ TemplateArgumentList *take() {
+ TemplateArgumentList *Result = Deduced;
+ Deduced = nullptr;
return Result;
}
@@ -125,20 +120,15 @@ class TemplateDeductionInfo {
/// Provide an initial template argument list that contains the
/// explicitly-specified arguments.
- void setExplicitArgs(TemplateArgumentList *NewDeducedSugared,
- TemplateArgumentList *NewDeducedCanonical) {
- assert(NewDeducedSugared->size() == NewDeducedCanonical->size());
- DeducedSugared = NewDeducedSugared;
- DeducedCanonical = NewDeducedCanonical;
- ExplicitArgs = DeducedSugared->size();
+ void setExplicitArgs(TemplateArgumentList *NewDeduced) {
+ Deduced = NewDeduced;
+ ExplicitArgs = Deduced->size();
}
/// Provide a new template argument list that contains the
/// results of template argument deduction.
- void reset(TemplateArgumentList *NewDeducedSugared,
- TemplateArgumentList *NewDeducedCanonical) {
- DeducedSugared = NewDeducedSugared;
- DeducedCanonical = NewDeducedCanonical;
+ void reset(TemplateArgumentList *NewDeduced) {
+ Deduced = NewDeduced;
}
/// Is a SFINAE diagnostic available?
diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp
index 845fa2f56df2f..a144cb40b7abc 100644
--- a/clang/lib/Sema/SemaLookup.cpp
+++ b/clang/lib/Sema/SemaLookup.cpp
@@ -3694,11 +3694,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;
+ SmallVector<TemplateArgument, 1> Checked;
TemplateArgumentLoc Arg(TemplateArgument(StringLit), StringLit);
- if (CheckTemplateArgument(
- Params->getParam(0), Arg, FD, R.getNameLoc(), R.getNameLoc(),
- 0, SugaredChecked, CanonicalChecked, CTAK_Specified) ||
+ if (CheckTemplateArgument(Params->getParam(0), Arg, FD,
+ R.getNameLoc(), R.getNameLoc(), 0,
+ Checked) ||
Trap.hasErrorOccurred())
IsTemplate = false;
}
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 4171b97cf7070..d3f6d1b256c57 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -640,7 +640,7 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
auto *Saved = new (Context) DFIDeducedMismatchArgs;
Saved->FirstArg = Info.FirstArg;
Saved->SecondArg = Info.SecondArg;
- Saved->TemplateArgs = Info.takeSugared();
+ Saved->TemplateArgs = Info.take();
Saved->CallArgIndex = Info.CallArgIndex;
Result.Data = Saved;
break;
@@ -669,7 +669,7 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
}
case Sema::TDK_SubstitutionFailure:
- Result.Data = Info.takeSugared();
+ Result.Data = Info.take();
if (Info.hasSFINAEDiagnostic()) {
PartialDiagnosticAt *Diag = new (Result.Diagnostic) PartialDiagnosticAt(
SourceLocation(), PartialDiagnostic::NullDiagnostic());
@@ -680,7 +680,7 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
case Sema::TDK_ConstraintsNotSatisfied: {
CNSInfo *Saved = new (Context) CNSInfo;
- Saved->TemplateArgs = Info.takeSugared();
+ Saved->TemplateArgs = Info.take();
Saved->Satisfaction = Info.AssociatedConstraintsSatisfaction;
Result.Data = Saved;
break;
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 86c7ce1b8ee8a..7a30a736bff9f 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -1592,10 +1592,9 @@ NamedDecl *Sema::ActOnNonTypeTemplateParameter(Scope *S, Declarator &D,
if (DiagnoseUnexpandedParameterPack(Default, UPPC_DefaultArgument))
return Param;
- TemplateArgument SugaredConverted, CanonicalConverted;
- ExprResult DefaultRes = CheckTemplateArgument(
- Param, Param->getType(), Default, SugaredConverted, CanonicalConverted,
- CTAK_Specified);
+ TemplateArgument Converted;
+ ExprResult DefaultRes =
+ CheckTemplateArgument(Param, Param->getType(), Default, Converted);
if (DefaultRes.isInvalid()) {
Param->setInvalidDecl();
return Param;
@@ -3845,9 +3844,9 @@ QualType Sema::CheckTemplateIdType(TemplateName Name,
// Check that the template argument list is well-formed for this
// template.
- SmallVector<TemplateArgument, 4> SugaredConverted, CanonicalConverted;
- if (CheckTemplateArgumentList(Template, TemplateLoc, TemplateArgs, false,
- SugaredConverted, CanonicalConverted,
+ SmallVector<TemplateArgument, 4> Converted;
+ if (CheckTemplateArgumentList(Template, TemplateLoc, TemplateArgs,
+ false, Converted,
/*UpdateArgsWithConversions=*/true))
return QualType();
@@ -3862,7 +3861,7 @@ QualType Sema::CheckTemplateIdType(TemplateName Name,
return QualType();
TemplateArgumentList StackTemplateArgs(TemplateArgumentList::OnStack,
- CanonicalConverted);
+ Converted);
// Only substitute for the innermost template argument list.
MultiLevelTemplateArgumentList TemplateArgLists;
@@ -3915,11 +3914,11 @@ QualType Sema::CheckTemplateIdType(TemplateName Name,
return QualType();
}
} else if (auto *BTD = dyn_cast<BuiltinTemplateDecl>(Template)) {
- CanonType = checkBuiltinTemplateIdType(*this, BTD, CanonicalConverted,
- TemplateLoc, TemplateArgs);
+ CanonType = checkBuiltinTemplateIdType(*this, BTD, Converted, TemplateLoc,
+ TemplateArgs);
} else if (Name.isDependent() ||
TemplateSpecializationType::anyDependentTemplateArguments(
- TemplateArgs, CanonicalConverted)) {
+ TemplateArgs, Converted)) {
// This class template specialization is a dependent
// type. Therefore, its canonical type is another class template
// specialization type that contains all of the converted
@@ -3927,8 +3926,7 @@ QualType Sema::CheckTemplateIdType(TemplateName Name,
// A<T, T> have identical types when A is declared as:
//
// template<typename T, typename U = T> struct A;
- CanonType = Context.getCanonicalTemplateSpecializationType(
- Name, CanonicalConverted);
+ CanonType = Context.getCanonicalTemplateSpecializationType(Name, Converted);
// This might work out to be a current instantiation, in which
// case the canonical type needs to be the InjectedClassNameType.
@@ -3972,8 +3970,8 @@ QualType Sema::CheckTemplateIdType(TemplateName Name,
// Find the class template specialization declaration that
// corresponds to these arguments.
void *InsertPos = nullptr;
- ClassTemplateSpecializationDecl *Decl =
- ClassTemplate->findSpecialization(CanonicalConverted, InsertPos);
+ ClassTemplateSpecializationDecl *Decl
+ = ClassTemplate->findSpecialization(Converted, InsertPos);
if (!Decl) {
// This is the first time we have referenced this class template
// specialization. Create the canonical declaration and add it to
@@ -3982,8 +3980,7 @@ QualType Sema::CheckTemplateIdType(TemplateName Name,
Context, ClassTemplate->getTemplatedDecl()->getTagKind(),
ClassTemplate->getDeclContext(),
ClassTemplate->getTemplatedDecl()->getBeginLoc(),
- ClassTemplate->getLocation(), ClassTemplate, CanonicalConverted,
- nullptr);
+ ClassTemplate->getLocation(), ClassTemplate, Converted, nullptr);
ClassTemplate->AddSpecialization(Decl, InsertPos);
if (ClassTemplate->isOutOfLine())
Decl->setLexicalDeclContext(ClassTemplate->getLexicalDeclContext());
@@ -3994,8 +3991,7 @@ QualType Sema::CheckTemplateIdType(TemplateName Name,
InstantiatingTemplate Inst(*this, TemplateLoc, Decl);
if (!Inst.isInvalid()) {
MultiLevelTemplateArgumentList TemplateArgLists;
- TemplateArgLists.addOuterTemplateArguments(Template,
- CanonicalConverted);
+ TemplateArgLists.addOuterTemplateArguments(Template, Converted);
InstantiateAttrsForDecl(TemplateArgLists,
ClassTemplate->getTemplatedDecl(), Decl);
}
@@ -4503,9 +4499,9 @@ DeclResult Sema::ActOnVarTemplateSpecialization(
// Check that the template argument list is well-formed for this
// template.
- SmallVector<TemplateArgument, 4> SugaredConverted, CanonicalConverted;
+ SmallVector<TemplateArgument, 4> Converted;
if (CheckTemplateArgumentList(VarTemplate, TemplateNameLoc, TemplateArgs,
- false, SugaredConverted, CanonicalConverted,
+ false, Converted,
/*UpdateArgsWithConversions=*/true))
return true;
@@ -4513,22 +4509,21 @@ DeclResult Sema::ActOnVarTemplateSpecialization(
// corresponds to these arguments.
if (IsPartialSpecialization) {
if (CheckTemplatePartialSpecializationArgs(TemplateNameLoc, VarTemplate,
- TemplateArgs.size(),
- CanonicalConverted))
+ TemplateArgs.size(), Converted))
return true;
// FIXME: Move these checks to CheckTemplatePartialSpecializationArgs so we
// also do them during instantiation.
if (!Name.isDependent() &&
- !TemplateSpecializationType::anyDependentTemplateArguments(
- TemplateArgs, CanonicalConverted)) {
+ !TemplateSpecializationType::anyDependentTemplateArguments(TemplateArgs,
+ Converted)) {
Diag(TemplateNameLoc, diag::err_partial_spec_fully_specialized)
<< VarTemplate->getDeclName();
IsPartialSpecialization = false;
}
if (isSameAsPrimaryTemplate(VarTemplate->getTemplateParameters(),
- CanonicalConverted) &&
+ Converted) &&
(!Context.getLangOpts().CPlusPlus20 ||
!TemplateParams->hasAssociatedConstraints())) {
// C++ [temp.class.spec]p9b3:
@@ -4549,10 +4544,10 @@ DeclResult Sema::ActOnVarTemplateSpecialization(
VarTemplateSpecializationDecl *PrevDecl = nullptr;
if (IsPartialSpecialization)
- PrevDecl = VarTemplate->findPartialSpecialization(
- CanonicalConverted, TemplateParams, InsertPos);
+ PrevDecl = VarTemplate->findPartialSpecialization(Converted, TemplateParams,
+ InsertPos);
else
- PrevDecl = VarTemplate->findSpecialization(CanonicalConverted, InsertPos);
+ PrevDecl = VarTemplate->findSpecialization(Converted, InsertPos);
VarTemplateSpecializationDecl *Specialization = nullptr;
@@ -4579,7 +4574,7 @@ DeclResult Sema::ActOnVarTemplateSpecialization(
VarTemplatePartialSpecializationDecl::Create(
Context, VarTemplate->getDeclContext(), TemplateKWLoc,
TemplateNameLoc, TemplateParams, VarTemplate, DI->getType(), DI, SC,
- CanonicalConverted, TemplateArgs);
+ Converted, TemplateArgs);
if (!PrevPartial)
VarTemplate->AddPartialSpecialization(Partial, InsertPos);
@@ -4596,7 +4591,7 @@ DeclResult Sema::ActOnVarTemplateSpecialization(
// this explicit specialization or friend declaration.
Specialization = VarTemplateSpecializationDecl::Create(
Context, VarTemplate->getDeclContext(), TemplateKWLoc, TemplateNameLoc,
- VarTemplate, DI->getType(), DI, SC, CanonicalConverted);
+ VarTemplate, DI->getType(), DI, SC, Converted);
Specialization->setTemplateArgsInfo(TemplateArgs);
if (!PrevDecl)
@@ -4674,25 +4669,24 @@ Sema::CheckVarTemplateId(VarTemplateDecl *Template, SourceLocation TemplateLoc,
assert(Template && "A variable template id without template?");
// Check that the template argument list is well-formed for this template.
- SmallVector<TemplateArgument, 4> SugaredConverted, CanonicalConverted;
+ SmallVector<TemplateArgument, 4> Converted;
if (CheckTemplateArgumentList(
Template, TemplateNameLoc,
const_cast<TemplateArgumentListInfo &>(TemplateArgs), false,
- SugaredConverted, CanonicalConverted,
- /*UpdateArgsWithConversions=*/true))
+ Converted, /*UpdateArgsWithConversions=*/true))
return true;
// Produce a placeholder value if the specialization is dependent.
if (Template->getDeclContext()->isDependentContext() ||
- TemplateSpecializationType::anyDependentTemplateArguments(
- TemplateArgs, CanonicalConverted))
+ TemplateSpecializationType::anyDependentTemplateArguments(TemplateArgs,
+ Converted))
return DeclResult();
// Find the variable template specialization declaration that
// corresponds to these arguments.
void *InsertPos = nullptr;
- if (VarTemplateSpecializationDecl *Spec =
- Template->findSpecialization(CanonicalConverted, InsertPos)) {
+ if (VarTemplateSpecializationDecl *Spec = Template->findSpecialization(
+ Converted, InsertPos)) {
checkSpecializationReachability(TemplateNameLoc, Spec);
// If we already have a variable template specialization, return it.
return Spec;
@@ -4704,7 +4698,7 @@ Sema::CheckVarTemplateId(VarTemplateDecl *Template, SourceLocation TemplateLoc,
// that it represents. That is,
VarDecl *InstantiationPattern = Template->getTemplatedDecl();
TemplateArgumentList TemplateArgList(TemplateArgumentList::OnStack,
- CanonicalConverted);
+ Converted);
TemplateArgumentList *InstantiationArgs = &TemplateArgList;
bool AmbiguousPartialSpec = false;
typedef PartialSpecMatchResult MatchResult;
@@ -4736,7 +4730,7 @@ Sema::CheckVarTemplateId(VarTemplateDecl *Template, SourceLocation TemplateLoc,
} else {
Matched.push_back(PartialSpecMatchResult());
Matched.back().Partial = Partial;
- Matched.back().Args = Info.takeCanonical();
+ Matched.back().Args = Info.take();
}
}
@@ -4792,7 +4786,7 @@ Sema::CheckVarTemplateId(VarTemplateDecl *Template, SourceLocation TemplateLoc,
// FIXME: LateAttrs et al.?
VarTemplateSpecializationDecl *Decl = BuildVarTemplateInstantiation(
Template, InstantiationPattern, *InstantiationArgs, TemplateArgs,
- CanonicalConverted, TemplateNameLoc /*, LateAttrs, StartingScope*/);
+ Converted, TemplateNameLoc /*, LateAttrs, StartingScope*/);
if (!Decl)
return true;
@@ -4863,22 +4857,22 @@ Sema::CheckConceptTemplateId(const CXXScopeSpec &SS,
const TemplateArgumentListInfo *TemplateArgs) {
assert(NamedConcept && "A concept template id without a template?");
- llvm::SmallVector<TemplateArgument, 4> SugaredConverted, CanonicalConverted;
- if (CheckTemplateArgumentList(
- NamedConcept, ConceptNameInfo.getLoc(),
- const_cast<TemplateArgumentListInfo &>(*TemplateArgs),
- /*PartialTemplateArgs=*/false, SugaredConverted, CanonicalConverted,
- /*UpdateArgsWithConversions=*/false))
+ llvm::SmallVector<TemplateArgument, 4> Converted;
+ if (CheckTemplateArgumentList(NamedConcept, ConceptNameInfo.getLoc(),
+ const_cast<TemplateArgumentListInfo&>(*TemplateArgs),
+ /*PartialTemplateArgs=*/false, Converted,
+ /*UpdateArgsWithConversions=*/false))
return ExprError();
auto *CSD = ImplicitConceptSpecializationDecl::Create(
Context, NamedConcept->getDeclContext(), NamedConcept->getLocation(),
- CanonicalConverted);
+ Converted);
ConstraintSatisfaction Satisfaction;
bool AreArgsDependent =
- TemplateSpecializationType::anyDependentTemplateArguments(
- *TemplateArgs, CanonicalConverted);
- MultiLevelTemplateArgumentList MLTAL(NamedConcept, CanonicalConverted);
+ TemplateSpecializationType::anyDependentTemplateArguments(*TemplateArgs,
+ Converted);
+ MultiLevelTemplateArgumentList MLTAL;
+ MLTAL.addOuterTemplateArguments(NamedConcept, Converted);
LocalInstantiationScope Scope(*this);
EnterExpressionEvaluationContext EECtx{
@@ -5138,10 +5132,9 @@ TemplateNameKind Sema::ActOnTemplateName(Scope *S,
return TNK_Non_template;
}
-bool Sema::CheckTemplateTypeArgument(
- TemplateTypeParmDecl *Param, TemplateArgumentLoc &AL,
- SmallVectorImpl<TemplateArgument> &SugaredConverted,
- SmallVectorImpl<TemplateArgument> &CanonicalConverted) {
+bool Sema::CheckTemplateTypeArgument(TemplateTypeParmDecl *Param,
+ TemplateArgumentLoc &AL,
+ SmallVectorImpl<TemplateArgument> &Converted) {
const TemplateArgument &Arg = AL.getArgument();
QualType ArgType;
TypeSourceInfo *TSI = nullptr;
@@ -5234,6 +5227,9 @@ bool Sema::CheckTemplateTypeArgument(
if (CheckTemplateArgument(TSI))
return true;
+ // Add the converted template type argument.
+ ArgType = Context.getCanonicalType(ArgType);
+
// Objective-C ARC:
// If an explicitly-specified template argument type is a lifetime type
// with no lifetime qualifier, the __strong lifetime qualifier is inferred.
@@ -5245,9 +5241,7 @@ bool Sema::CheckTemplateTypeArgument(
ArgType = Context.getQualifiedType(ArgType, Qs);
}
- SugaredConverted.push_back(TemplateArgument(ArgType));
- CanonicalConverted.push_back(
- TemplateArgument(Context.getCanonicalType(ArgType)));
+ Converted.push_back(TemplateArgument(ArgType));
return false;
}
@@ -5553,17 +5547,17 @@ convertTypeTemplateArgumentToTemplate(ASTContext &Context, TypeLoc TLoc) {
/// explicitly written, deduced, etc.
///
/// \returns true on error, false otherwise.
-bool Sema::CheckTemplateArgument(
- NamedDecl *Param, TemplateArgumentLoc &Arg, NamedDecl *Template,
- SourceLocation TemplateLoc, SourceLocation RAngleLoc,
- unsigned ArgumentPackIndex,
- SmallVectorImpl<TemplateArgument> &SugaredConverted,
- SmallVectorImpl<TemplateArgument> &CanonicalConverted,
- CheckTemplateArgumentKind CTAK) {
+bool Sema::CheckTemplateArgument(NamedDecl *Param,
+ TemplateArgumentLoc &Arg,
+ NamedDecl *Template,
+ SourceLocation TemplateLoc,
+ SourceLocation RAngleLoc,
+ unsigned ArgumentPackIndex,
+ SmallVectorImpl<TemplateArgument> &Converted,
+ CheckTemplateArgumentKind CTAK) {
// Check template type parameters.
if (TemplateTypeParmDecl *TTP = dyn_cast<TemplateTypeParmDecl>(Param))
- return CheckTemplateTypeArgument(TTP, Arg, SugaredConverted,
- CanonicalConverted);
+ return CheckTemplateTypeArgument(TTP, Arg, Converted);
// Check non-type template parameters.
if (NonTypeTemplateParmDecl *NTTP =dyn_cast<NonTypeTemplateParmDecl>(Param)) {
@@ -5578,14 +5572,14 @@ bool Sema::CheckTemplateArgument(
!isa<TemplateTemplateParmDecl>(Template) &&
!Template->getDeclContext()->isDependentContext()) {
// Do substitution on the type of the non-type template parameter.
- InstantiatingTemplate Inst(*this, TemplateLoc, Template, NTTP,
- CanonicalConverted,
+ InstantiatingTemplate Inst(*this, TemplateLoc, Template,
+ NTTP, Converted,
SourceRange(TemplateLoc, RAngleLoc));
if (Inst.isInvalid())
return true;
TemplateArgumentList TemplateArgs(TemplateArgumentList::OnStack,
- CanonicalConverted);
+ Converted);
MultiLevelTemplateArgumentList MLTAL(Template, TemplateArgs.asArray());
// If the parameter is a pack expansion, expand this slice of the pack.
@@ -5613,11 +5607,11 @@ bool Sema::CheckTemplateArgument(
llvm_unreachable("Should never see a NULL template argument here");
case TemplateArgument::Expression: {
- Expr *E = Arg.getArgument().getAsExpr();
- TemplateArgument SugaredResult, CanonicalResult;
+ TemplateArgument Result;
unsigned CurSFINAEErrors = NumSFINAEErrors;
- ExprResult Res = CheckTemplateArgument(NTTP, NTTPType, E, SugaredResult,
- CanonicalResult, CTAK);
+ ExprResult Res =
+ CheckTemplateArgument(NTTP, NTTPType, Arg.getArgument().getAsExpr(),
+ Result, CTAK);
if (Res.isInvalid())
return true;
// If the current template argument causes an error, give up now.
@@ -5626,13 +5620,12 @@ bool Sema::CheckTemplateArgument(
// If the resulting expression is new, then use it in place of the
// old expression in the template argument.
- if (Res.get() != E) {
+ if (Res.get() != Arg.getArgument().getAsExpr()) {
TemplateArgument TA(Res.get());
Arg = TemplateArgumentLoc(TA, Res.get());
}
- SugaredConverted.push_back(SugaredResult);
- CanonicalConverted.push_back(CanonicalResult);
+ Converted.push_back(Result);
break;
}
@@ -5641,9 +5634,7 @@ bool Sema::CheckTemplateArgument(
case TemplateArgument::NullPtr:
// We've already checked this template argument, so just copy
// it to the list of converted arguments.
- SugaredConverted.push_back(Arg.getArgument());
- CanonicalConverted.push_back(
- Context.getCanonicalTemplateArgument(Arg.getArgument()));
+ Converted.push_back(Arg.getArgument());
break;
case TemplateArgument::Template:
@@ -5679,14 +5670,12 @@ bool Sema::CheckTemplateArgument(
return true;
}
- TemplateArgument SugaredResult, CanonicalResult;
- E = CheckTemplateArgument(NTTP, NTTPType, E.get(), SugaredResult,
- CanonicalResult, CTAK_Specified);
+ TemplateArgument Result;
+ E = CheckTemplateArgument(NTTP, NTTPType, E.get(), Result);
if (E.isInvalid())
return true;
- SugaredConverted.push_back(SugaredResult);
- CanonicalConverted.push_back(CanonicalResult);
+ Converted.push_back(Result);
break;
}
@@ -5744,14 +5733,14 @@ bool Sema::CheckTemplateArgument(
// Set up a template instantiation context.
LocalInstantiationScope Scope(*this);
InstantiatingTemplate Inst(*this, TemplateLoc, Template, TempParm,
- SugaredConverted,
- SourceRange(TemplateLoc, RAngleLoc));
+ Converted, SourceRange(TemplateLoc, RAngleLoc));
if (Inst.isInvalid())
return true;
+ TemplateArgumentList TemplateArgs(TemplateArgumentList::OnStack, Converted);
Params = SubstTemplateParams(
Params, CurContext,
- MultiLevelTemplateArgumentList(Template, CanonicalConverted));
+ MultiLevelTemplateArgumentList(Template, TemplateArgs.asArray()));
if (!Params)
return true;
}
@@ -5776,8 +5765,7 @@ bool Sema::CheckTemplateArgument(
if (CheckTemplateTemplateArgument(TempParm, Params, Arg))
return true;
- SugaredConverted.push_back(Arg.getArgument());
- CanonicalConverted.push_back(
+ Converted.push_back(
Context.getCanonicalTemplateArgument(Arg.getArgument()));
break;
@@ -5845,8 +5833,7 @@ static bool diagnoseMissingArgument(Sema &S, SourceLocation Loc,
bool Sema::CheckTemplateArgumentList(
TemplateDecl *Template, SourceLocation TemplateLoc,
TemplateArgumentListInfo &TemplateArgs, bool PartialTemplateArgs,
- SmallVectorImpl<TemplateArgument> &SugaredConverted,
- SmallVectorImpl<TemplateArgument> &CanonicalConverted,
+ SmallVectorImpl<TemplateArgument> &Converted,
bool UpdateArgsWithConversions, bool *ConstraintsNotSatisfied) {
if (ConstraintsNotSatisfied)
@@ -5872,8 +5859,7 @@ bool Sema::CheckTemplateArgumentList(
// corresponding parameter declared by the template in its
// template-parameter-list.
bool isTemplateTemplateParameter = isa<TemplateTemplateParmDecl>(Template);
- SmallVector<TemplateArgument, 2> SugaredArgumentPack;
- SmallVector<TemplateArgument, 2> CanonicalArgumentPack;
+ SmallVector<TemplateArgument, 2> ArgumentPack;
unsigned ArgIdx = 0, NumArgs = NewArgs.size();
LocalInstantiationScope InstScope(*this, true);
for (TemplateParameterList::iterator Param = Params->begin(),
@@ -5882,16 +5868,12 @@ bool Sema::CheckTemplateArgumentList(
// If we have an expanded parameter pack, make sure we don't have too
// many arguments.
if (Optional<unsigned> Expansions = getExpandedPackSize(*Param)) {
- if (*Expansions == SugaredArgumentPack.size()) {
+ if (*Expansions == ArgumentPack.size()) {
// We're done with this parameter pack. Pack up its arguments and add
// them to the list.
- SugaredConverted.push_back(
- TemplateArgument::CreatePackCopy(Context, SugaredArgumentPack));
- SugaredArgumentPack.clear();
-
- CanonicalConverted.push_back(
- TemplateArgument::CreatePackCopy(Context, CanonicalArgumentPack));
- CanonicalArgumentPack.clear();
+ Converted.push_back(
+ TemplateArgument::CreatePackCopy(Context, ArgumentPack));
+ ArgumentPack.clear();
// This argument is assigned to the next parameter.
++Param;
@@ -5910,10 +5892,9 @@ bool Sema::CheckTemplateArgumentList(
if (ArgIdx < NumArgs) {
// Check the template argument we were given.
- if (CheckTemplateArgument(*Param, NewArgs[ArgIdx], Template, TemplateLoc,
- RAngleLoc, SugaredArgumentPack.size(),
- SugaredConverted, CanonicalConverted,
- CTAK_Specified))
+ if (CheckTemplateArgument(*Param, NewArgs[ArgIdx], Template,
+ TemplateLoc, RAngleLoc,
+ ArgumentPack.size(), Converted))
return true;
bool PackExpansionIntoNonPack =
@@ -5942,8 +5923,7 @@ bool Sema::CheckTemplateArgumentList(
// deduced argument and place it on the argument pack. Note that we
// stay on the same template parameter so that we can deduce more
// arguments.
- SugaredArgumentPack.push_back(SugaredConverted.pop_back_val());
- CanonicalArgumentPack.push_back(CanonicalConverted.pop_back_val());
+ ArgumentPack.push_back(Converted.pop_back_val());
} else {
// Move to the next template parameter.
++Param;
@@ -5953,25 +5933,17 @@ bool Sema::CheckTemplateArgumentList(
// the remaining arguments, because we don't know what parameters they'll
// match up with.
if (PackExpansionIntoNonPack) {
- if (!SugaredArgumentPack.empty()) {
+ if (!ArgumentPack.empty()) {
// If we were part way through filling in an expanded parameter pack,
// fall back to just producing individual arguments.
- SugaredConverted.insert(SugaredConverted.end(),
- SugaredArgumentPack.begin(),
- SugaredArgumentPack.end());
- SugaredArgumentPack.clear();
-
- CanonicalConverted.insert(CanonicalConverted.end(),
- CanonicalArgumentPack.begin(),
- CanonicalArgumentPack.end());
- CanonicalArgumentPack.clear();
+ for (const TemplateArgument &I : ArgumentPack)
+ Converted.push_back(Context.getCanonicalTemplateArgument(I));
+ ArgumentPack.clear();
}
while (ArgIdx < NumArgs) {
- const TemplateArgument &Arg = NewArgs[ArgIdx].getArgument();
- SugaredConverted.push_back(Arg);
- CanonicalConverted.push_back(
- Context.getCanonicalTemplateArgument(Arg));
+ Converted.push_back(Context.getCanonicalTemplateArgument(
+ NewArgs[ArgIdx].getArgument()));
++ArgIdx;
}
@@ -5983,12 +5955,9 @@ bool Sema::CheckTemplateArgumentList(
// If we're checking a partial template argument list, we're done.
if (PartialTemplateArgs) {
- if ((*Param)->isTemplateParameterPack() && !SugaredArgumentPack.empty()) {
- SugaredConverted.push_back(
- TemplateArgument::CreatePackCopy(Context, SugaredArgumentPack));
- CanonicalConverted.push_back(
- TemplateArgument::CreatePackCopy(Context, CanonicalArgumentPack));
- }
+ if ((*Param)->isTemplateParameterPack() && !ArgumentPack.empty())
+ Converted.push_back(
+ TemplateArgument::CreatePackCopy(Context, ArgumentPack));
return false;
}
@@ -6004,13 +5973,9 @@ bool Sema::CheckTemplateArgumentList(
if (Param + 1 != ParamEnd)
return true;
- SugaredConverted.push_back(
- TemplateArgument::CreatePackCopy(Context, SugaredArgumentPack));
- SugaredArgumentPack.clear();
-
- CanonicalConverted.push_back(
- TemplateArgument::CreatePackCopy(Context, CanonicalArgumentPack));
- CanonicalArgumentPack.clear();
+ Converted.push_back(
+ TemplateArgument::CreatePackCopy(Context, ArgumentPack));
+ ArgumentPack.clear();
++Param;
continue;
@@ -6029,8 +5994,12 @@ bool Sema::CheckTemplateArgumentList(
return diagnoseMissingArgument(*this, TemplateLoc, Template, TTP,
NewArgs);
- TypeSourceInfo *ArgType = SubstDefaultTemplateArgument(
- *this, Template, TemplateLoc, RAngleLoc, TTP, CanonicalConverted);
+ TypeSourceInfo *ArgType = SubstDefaultTemplateArgument(*this,
+ Template,
+ TemplateLoc,
+ RAngleLoc,
+ TTP,
+ Converted);
if (!ArgType)
return true;
@@ -6042,8 +6011,11 @@ bool Sema::CheckTemplateArgumentList(
return diagnoseMissingArgument(*this, TemplateLoc, Template, NTTP,
NewArgs);
- ExprResult E = SubstDefaultTemplateArgument(
- *this, Template, TemplateLoc, RAngleLoc, NTTP, CanonicalConverted);
+ ExprResult E = SubstDefaultTemplateArgument(*this, Template,
+ TemplateLoc,
+ RAngleLoc,
+ NTTP,
+ Converted);
if (E.isInvalid())
return true;
@@ -6058,9 +6030,12 @@ bool Sema::CheckTemplateArgumentList(
NewArgs);
NestedNameSpecifierLoc QualifierLoc;
- TemplateName Name = SubstDefaultTemplateArgument(
- *this, Template, TemplateLoc, RAngleLoc, TempParm, CanonicalConverted,
- QualifierLoc);
+ TemplateName Name = SubstDefaultTemplateArgument(*this, Template,
+ TemplateLoc,
+ RAngleLoc,
+ TempParm,
+ Converted,
+ QualifierLoc);
if (Name.isNull())
return true;
@@ -6073,16 +6048,14 @@ bool Sema::CheckTemplateArgumentList(
// the default template argument. We're not actually instantiating a
// template here, we just create this object to put a note into the
// context stack.
- InstantiatingTemplate Inst(*this, RAngleLoc, Template, *Param,
- CanonicalConverted,
+ InstantiatingTemplate Inst(*this, RAngleLoc, Template, *Param, Converted,
SourceRange(TemplateLoc, RAngleLoc));
if (Inst.isInvalid())
return true;
// Check the default template argument.
- if (CheckTemplateArgument(*Param, Arg, Template, TemplateLoc, RAngleLoc, 0,
- SugaredConverted, CanonicalConverted,
- CTAK_Specified))
+ if (CheckTemplateArgument(*Param, Arg, Template, TemplateLoc,
+ RAngleLoc, 0, Converted))
return true;
// Core issue 150 (assumed resolution): if this is a template template
@@ -6102,12 +6075,9 @@ bool Sema::CheckTemplateArgumentList(
// still dependent).
if (ArgIdx < NumArgs && CurrentInstantiationScope &&
CurrentInstantiationScope->getPartiallySubstitutedPack()) {
- while (ArgIdx < NumArgs &&
- NewArgs[ArgIdx].getArgument().isPackExpansion()) {
- const TemplateArgument &Arg = NewArgs[ArgIdx++].getArgument();
- SugaredConverted.push_back(Arg);
- CanonicalConverted.push_back(Context.getCanonicalTemplateArgument(Arg));
- }
+ while (ArgIdx < NumArgs && NewArgs[ArgIdx].getArgument().isPackExpansion())
+ Converted.push_back(Context.getCanonicalTemplateArgument(
+ NewArgs[ArgIdx++].getArgument()));
}
// If we have any leftover arguments, then there were too many arguments.
@@ -6130,7 +6100,7 @@ bool Sema::CheckTemplateArgumentList(
if (!PartialTemplateArgs) {
TemplateArgumentList StackTemplateArgs(TemplateArgumentList::OnStack,
- CanonicalConverted);
+ Converted);
// Setup the context/ThisScope for the case where we are needing to
// re-instantiate constraints outside of normal instantiation.
DeclContext *NewContext = Template->getDeclContext();
@@ -6647,9 +6617,12 @@ static bool CheckTemplateArgumentIsCompatibleWithParameter(
/// Checks whether the given template argument is the address
/// of an object or function according to C++ [temp.arg.nontype]p1.
-static bool CheckTemplateArgumentAddressOfObjectOrFunction(
- Sema &S, NonTypeTemplateParmDecl *Param, QualType ParamType, Expr *ArgIn,
- TemplateArgument &SugaredConverted, TemplateArgument &CanonicalConverted) {
+static bool
+CheckTemplateArgumentAddressOfObjectOrFunction(Sema &S,
+ NonTypeTemplateParmDecl *Param,
+ QualType ParamType,
+ Expr *ArgIn,
+ TemplateArgument &Converted) {
bool Invalid = false;
Expr *Arg = ArgIn;
QualType ArgType = Arg->getType();
@@ -6753,11 +6726,8 @@ static bool CheckTemplateArgumentAddressOfObjectOrFunction(
Entity)) {
case NPV_NullPointer:
S.Diag(Arg->getExprLoc(), diag::warn_cxx98_compat_template_arg_null);
- SugaredConverted = TemplateArgument(ParamType,
- /*isNullPtr=*/true);
- CanonicalConverted =
- TemplateArgument(S.Context.getCanonicalType(ParamType),
- /*isNullPtr=*/true);
+ Converted = TemplateArgument(S.Context.getCanonicalType(ParamType),
+ /*isNullPtr=*/true);
return false;
case NPV_Error:
@@ -6771,9 +6741,7 @@ static bool CheckTemplateArgumentAddressOfObjectOrFunction(
// Stop checking the precise nature of the argument if it is value dependent,
// it should be checked when instantiated.
if (Arg->isValueDependent()) {
- SugaredConverted = TemplateArgument(ArgIn);
- CanonicalConverted =
- S.Context.getCanonicalTemplateArgument(SugaredConverted);
+ Converted = TemplateArgument(ArgIn);
return false;
}
@@ -6903,21 +6871,19 @@ static bool CheckTemplateArgumentAddressOfObjectOrFunction(
return true;
// Create the template argument.
- SugaredConverted = TemplateArgument(Entity, ParamType);
- CanonicalConverted =
- TemplateArgument(cast<ValueDecl>(Entity->getCanonicalDecl()),
- S.Context.getCanonicalType(ParamType));
+ Converted = TemplateArgument(cast<ValueDecl>(Entity->getCanonicalDecl()),
+ S.Context.getCanonicalType(ParamType));
S.MarkAnyDeclReferenced(Arg->getBeginLoc(), Entity, false);
return false;
}
/// Checks whether the given template argument is a pointer to
/// member constant according to C++ [temp.arg.nontype]p1.
-static bool
-CheckTemplateArgumentPointerToMember(Sema &S, NonTypeTemplateParmDecl *Param,
- QualType ParamType, Expr *&ResultArg,
- TemplateArgument &SugaredConverted,
- TemplateArgument &CanonicalConverted) {
+static bool CheckTemplateArgumentPointerToMember(Sema &S,
+ NonTypeTemplateParmDecl *Param,
+ QualType ParamType,
+ Expr *&ResultArg,
+ TemplateArgument &Converted) {
bool Invalid = false;
Expr *Arg = ResultArg;
@@ -6965,14 +6931,10 @@ CheckTemplateArgumentPointerToMember(Sema &S, NonTypeTemplateParmDecl *Param,
if (VD->getType()->isMemberPointerType()) {
if (isa<NonTypeTemplateParmDecl>(VD)) {
if (Arg->isTypeDependent() || Arg->isValueDependent()) {
- SugaredConverted = TemplateArgument(Arg);
- CanonicalConverted =
- S.Context.getCanonicalTemplateArgument(SugaredConverted);
+ Converted = TemplateArgument(Arg);
} else {
- SugaredConverted = TemplateArgument(VD, ParamType);
- CanonicalConverted =
- TemplateArgument(cast<ValueDecl>(VD->getCanonicalDecl()),
- S.Context.getCanonicalType(ParamType));
+ VD = cast<ValueDecl>(VD->getCanonicalDecl());
+ Converted = TemplateArgument(VD, ParamType);
}
return Invalid;
}
@@ -6990,10 +6952,8 @@ CheckTemplateArgumentPointerToMember(Sema &S, NonTypeTemplateParmDecl *Param,
return true;
case NPV_NullPointer:
S.Diag(ResultArg->getExprLoc(), diag::warn_cxx98_compat_template_arg_null);
- SugaredConverted = TemplateArgument(ParamType,
- /*isNullPtr*/ true);
- CanonicalConverted = TemplateArgument(S.Context.getCanonicalType(ParamType),
- /*isNullPtr*/ true);
+ Converted = TemplateArgument(S.Context.getCanonicalType(ParamType),
+ /*isNullPtr*/true);
return false;
case NPV_NotNullPointer:
break;
@@ -7030,15 +6990,10 @@ CheckTemplateArgumentPointerToMember(Sema &S, NonTypeTemplateParmDecl *Param,
// Okay: this is the address of a non-static member, and therefore
// a member pointer constant.
if (Arg->isTypeDependent() || Arg->isValueDependent()) {
- SugaredConverted = TemplateArgument(Arg);
- CanonicalConverted =
- S.Context.getCanonicalTemplateArgument(SugaredConverted);
+ Converted = TemplateArgument(Arg);
} else {
- ValueDecl *D = DRE->getDecl();
- SugaredConverted = TemplateArgument(D, ParamType);
- CanonicalConverted =
- TemplateArgument(cast<ValueDecl>(D->getCanonicalDecl()),
- S.Context.getCanonicalType(ParamType));
+ ValueDecl *D = cast<ValueDecl>(DRE->getDecl()->getCanonicalDecl());
+ Converted = TemplateArgument(D, S.Context.getCanonicalType(ParamType));
}
return Invalid;
}
@@ -7059,8 +7014,7 @@ CheckTemplateArgumentPointerToMember(Sema &S, NonTypeTemplateParmDecl *Param,
/// type of the non-type template parameter after it has been instantiated.
ExprResult Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
QualType ParamType, Expr *Arg,
- TemplateArgument &SugaredConverted,
- TemplateArgument &CanonicalConverted,
+ TemplateArgument &Converted,
CheckTemplateArgumentKind CTAK) {
SourceLocation StartLoc = Arg->getBeginLoc();
@@ -7075,9 +7029,7 @@ ExprResult Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
if (CTAK == CTAK_Deduced && Arg->isTypeDependent()) {
auto *AT = dyn_cast<AutoType>(DeducedT);
if (AT && AT->isDecltypeAuto()) {
- SugaredConverted = TemplateArgument(Arg);
- CanonicalConverted = TemplateArgument(
- Context.getCanonicalTemplateArgument(SugaredConverted));
+ Converted = TemplateArgument(Arg);
return Arg;
}
}
@@ -7155,9 +7107,7 @@ ExprResult Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
// work. Similarly for CTAD, when comparing 'A<x>' against 'A'.
if ((ParamType->isDependentType() || Arg->isTypeDependent()) &&
!Arg->getType()->getContainedDeducedType()) {
- SugaredConverted = TemplateArgument(Arg);
- CanonicalConverted = TemplateArgument(
- Context.getCanonicalTemplateArgument(SugaredConverted));
+ Converted = TemplateArgument(Arg);
return Arg;
}
// FIXME: This attempts to implement C++ [temp.deduct.type]p17. Per DR1770,
@@ -7194,9 +7144,7 @@ ExprResult Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
PackExpansionExpr(E.get()->getType(), E.get(), PE->getEllipsisLoc(),
PE->getNumExpansions());
}
- SugaredConverted = TemplateArgument(E.get());
- CanonicalConverted = TemplateArgument(
- Context.getCanonicalTemplateArgument(SugaredConverted));
+ Converted = TemplateArgument(E.get());
return E;
}
@@ -7221,16 +7169,11 @@ ExprResult Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
Context.hasSameUnqualifiedType(ParamType, InnerArg->getType())) {
NamedDecl *ND = cast<DeclRefExpr>(InnerArg)->getDecl();
if (auto *TPO = dyn_cast<TemplateParamObjectDecl>(ND)) {
-
- SugaredConverted = TemplateArgument(TPO, ParamType);
- CanonicalConverted =
- TemplateArgument(TPO->getCanonicalDecl(), CanonParamType);
+ Converted = TemplateArgument(TPO, CanonParamType);
return Arg;
}
if (isa<NonTypeTemplateParmDecl>(ND)) {
- SugaredConverted = TemplateArgument(Arg);
- CanonicalConverted =
- Context.getCanonicalTemplateArgument(SugaredConverted);
+ Converted = TemplateArgument(Arg);
return Arg;
}
}
@@ -7247,9 +7190,7 @@ ExprResult Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
// For a value-dependent argument, CheckConvertedConstantExpression is
// permitted (and expected) to be unable to determine a value.
if (ArgResult.get()->isValueDependent()) {
- SugaredConverted = TemplateArgument(ArgResult.get());
- CanonicalConverted =
- Context.getCanonicalTemplateArgument(SugaredConverted);
+ Converted = TemplateArgument(ArgResult.get());
return ArgResult;
}
@@ -7257,17 +7198,14 @@ ExprResult Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
switch (Value.getKind()) {
case APValue::None:
assert(ParamType->isNullPtrType());
- SugaredConverted = TemplateArgument(ParamType, /*isNullPtr=*/true);
- CanonicalConverted = TemplateArgument(CanonParamType, /*isNullPtr=*/true);
+ Converted = TemplateArgument(CanonParamType, /*isNullPtr*/true);
break;
case APValue::Indeterminate:
llvm_unreachable("result of constant evaluation should be initialized");
break;
case APValue::Int:
assert(ParamType->isIntegralOrEnumerationType());
- SugaredConverted = TemplateArgument(Context, Value.getInt(), ParamType);
- CanonicalConverted =
- TemplateArgument(Context, Value.getInt(), CanonParamType);
+ Converted = TemplateArgument(Context, Value.getInt(), CanonParamType);
break;
case APValue::MemberPointer: {
assert(ParamType->isMemberPointerType());
@@ -7282,12 +7220,8 @@ ExprResult Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
}
auto *VD = const_cast<ValueDecl*>(Value.getMemberPointerDecl());
- SugaredConverted = VD ? TemplateArgument(VD, ParamType)
- : TemplateArgument(ParamType, /*isNullPtr=*/true);
- CanonicalConverted =
- VD ? TemplateArgument(cast<ValueDecl>(VD->getCanonicalDecl()),
- CanonParamType)
- : TemplateArgument(CanonParamType, /*isNullPtr=*/true);
+ Converted = VD ? TemplateArgument(VD, CanonParamType)
+ : TemplateArgument(CanonParamType, /*isNullPtr*/true);
break;
}
case APValue::LValue: {
@@ -7327,25 +7261,17 @@ ExprResult Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
"null reference should not be a constant expression");
assert((!VD || !ParamType->isNullPtrType()) &&
"non-null value of type nullptr_t?");
-
- SugaredConverted = VD ? TemplateArgument(VD, ParamType)
- : TemplateArgument(ParamType, /*isNullPtr=*/true);
- CanonicalConverted =
- VD ? TemplateArgument(cast<ValueDecl>(VD->getCanonicalDecl()),
- CanonParamType)
- : TemplateArgument(CanonParamType, /*isNullPtr=*/true);
+ Converted = VD ? TemplateArgument(VD, CanonParamType)
+ : TemplateArgument(CanonParamType, /*isNullPtr*/true);
break;
}
case APValue::Struct:
- case APValue::Union: {
+ case APValue::Union:
// Get or create the corresponding template parameter object.
- TemplateParamObjectDecl *D =
- Context.getTemplateParamObjectDecl(ParamType, Value);
- SugaredConverted = TemplateArgument(D, ParamType);
- CanonicalConverted =
- TemplateArgument(D->getCanonicalDecl(), CanonParamType);
+ Converted = TemplateArgument(
+ Context.getTemplateParamObjectDecl(CanonParamType, Value),
+ CanonParamType);
break;
- }
case APValue::AddrLabelDiff:
return Diag(StartLoc, diag::err_non_type_template_arg_addr_label_
diff );
case APValue::FixedPoint:
@@ -7395,9 +7321,7 @@ ExprResult Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
// We can't check arbitrary value-dependent arguments.
if (ArgResult.get()->isValueDependent()) {
- SugaredConverted = TemplateArgument(ArgResult.get());
- CanonicalConverted =
- Context.getCanonicalTemplateArgument(SugaredConverted);
+ Converted = TemplateArgument(ArgResult.get());
return ArgResult;
}
@@ -7411,9 +7335,8 @@ ExprResult Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
? Context.getIntWidth(IntegerType)
: Context.getTypeSize(IntegerType));
- SugaredConverted = TemplateArgument(Context, Value, ParamType);
- CanonicalConverted =
- TemplateArgument(Context, Value, Context.getCanonicalType(ParamType));
+ Converted = TemplateArgument(Context, Value,
+ Context.getCanonicalType(ParamType));
return ArgResult;
}
@@ -7483,16 +7406,13 @@ ExprResult Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
if (Arg->isValueDependent()) {
// The argument is value-dependent. Create a new
// TemplateArgument with the converted expression.
- SugaredConverted = TemplateArgument(Arg);
- CanonicalConverted =
- Context.getCanonicalTemplateArgument(SugaredConverted);
+ Converted = TemplateArgument(Arg);
return Arg;
}
- QualType IntegerType = ParamType;
- if (const EnumType *Enum = IntegerType->getAs<EnumType>()) {
- IntegerType = Enum->getDecl()->getIntegerType();
- }
+ QualType IntegerType = Context.getCanonicalType(ParamType);
+ if (const EnumType *Enum = IntegerType->getAs<EnumType>())
+ IntegerType = Context.getCanonicalType(Enum->getDecl()->getIntegerType());
if (ParamType->isBooleanType()) {
// Value must be zero or one.
@@ -7538,10 +7458,10 @@ ExprResult Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
}
}
- QualType T = ParamType->isEnumeralType() ? ParamType : IntegerType;
- SugaredConverted = TemplateArgument(Context, Value, T);
- CanonicalConverted =
- TemplateArgument(Context, Value, Context.getCanonicalType(T));
+ Converted = TemplateArgument(Context, Value,
+ ParamType->isEnumeralType()
+ ? Context.getCanonicalType(ParamType)
+ : IntegerType);
return Arg;
}
@@ -7586,15 +7506,15 @@ ExprResult Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
}
if (!ParamType->isMemberPointerType()) {
- if (CheckTemplateArgumentAddressOfObjectOrFunction(
- *this, Param, ParamType, Arg, SugaredConverted,
- CanonicalConverted))
+ if (CheckTemplateArgumentAddressOfObjectOrFunction(*this, Param,
+ ParamType,
+ Arg, Converted))
return ExprError();
return Arg;
}
- if (CheckTemplateArgumentPointerToMember(
- *this, Param, ParamType, Arg, SugaredConverted, CanonicalConverted))
+ if (CheckTemplateArgumentPointerToMember(*this, Param, ParamType, Arg,
+ Converted))
return ExprError();
return Arg;
}
@@ -7607,8 +7527,9 @@ ExprResult Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
assert(ParamType->getPointeeType()->isIncompleteOrObjectType() &&
"Only object pointers allowed here");
- if (CheckTemplateArgumentAddressOfObjectOrFunction(
- *this, Param, ParamType, Arg, SugaredConverted, CanonicalConverted))
+ if (CheckTemplateArgumentAddressOfObjectOrFunction(*this, Param,
+ ParamType,
+ Arg, Converted))
return ExprError();
return Arg;
}
@@ -7637,8 +7558,9 @@ ExprResult Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
return ExprError();
}
- if (CheckTemplateArgumentAddressOfObjectOrFunction(
- *this, Param, ParamType, Arg, SugaredConverted, CanonicalConverted))
+ if (CheckTemplateArgumentAddressOfObjectOrFunction(*this, Param,
+ ParamType,
+ Arg, Converted))
return ExprError();
return Arg;
}
@@ -7646,9 +7568,7 @@ ExprResult Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
// Deal with parameters of type std::nullptr_t.
if (ParamType->isNullPtrType()) {
if (Arg->isTypeDependent() || Arg->isValueDependent()) {
- SugaredConverted = TemplateArgument(Arg);
- CanonicalConverted =
- Context.getCanonicalTemplateArgument(SugaredConverted);
+ Converted = TemplateArgument(Arg);
return Arg;
}
@@ -7664,10 +7584,8 @@ ExprResult Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
case NPV_NullPointer:
Diag(Arg->getExprLoc(), diag::warn_cxx98_compat_template_arg_null);
- SugaredConverted = TemplateArgument(ParamType,
- /*isNullPtr=*/true);
- CanonicalConverted = TemplateArgument(Context.getCanonicalType(ParamType),
- /*isNullPtr=*/true);
+ Converted = TemplateArgument(Context.getCanonicalType(ParamType),
+ /*isNullPtr*/true);
return Arg;
}
}
@@ -7676,8 +7594,8 @@ ExprResult Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
// member, qualification conversions (4.4) are applied.
assert(ParamType->isMemberPointerType() && "Only pointers to members remain");
- if (CheckTemplateArgumentPointerToMember(
- *this, Param, ParamType, Arg, SugaredConverted, CanonicalConverted))
+ if (CheckTemplateArgumentPointerToMember(*this, Param, ParamType, Arg,
+ Converted))
return ExprError();
return Arg;
}
@@ -8678,9 +8596,9 @@ DeclResult Sema::ActOnClassTemplateSpecialization(
// Check that the template argument list is well-formed for this
// template.
- SmallVector<TemplateArgument, 4> SugaredConverted, CanonicalConverted;
- if (CheckTemplateArgumentList(ClassTemplate, TemplateNameLoc, TemplateArgs,
- false, SugaredConverted, CanonicalConverted,
+ SmallVector<TemplateArgument, 4> Converted;
+ if (CheckTemplateArgumentList(ClassTemplate, TemplateNameLoc,
+ TemplateArgs, false, Converted,
/*UpdateArgsWithConversions=*/true))
return true;
@@ -8688,15 +8606,14 @@ DeclResult Sema::ActOnClassTemplateSpecialization(
// corresponds to these arguments.
if (isPartialSpecialization) {
if (CheckTemplatePartialSpecializationArgs(TemplateNameLoc, ClassTemplate,
- TemplateArgs.size(),
- CanonicalConverted))
+ TemplateArgs.size(), Converted))
return true;
// FIXME: Move this to CheckTemplatePartialSpecializationArgs so we
// also do it during instantiation.
if (!Name.isDependent() &&
- !TemplateSpecializationType::anyDependentTemplateArguments(
- TemplateArgs, CanonicalConverted)) {
+ !TemplateSpecializationType::anyDependentTemplateArguments(TemplateArgs,
+ Converted)) {
Diag(TemplateNameLoc, diag::err_partial_spec_fully_specialized)
<< ClassTemplate->getDeclName();
isPartialSpecialization = false;
@@ -8707,10 +8624,11 @@ DeclResult Sema::ActOnClassTemplateSpecialization(
ClassTemplateSpecializationDecl *PrevDecl = nullptr;
if (isPartialSpecialization)
- PrevDecl = ClassTemplate->findPartialSpecialization(
- CanonicalConverted, TemplateParams, InsertPos);
+ PrevDecl = ClassTemplate->findPartialSpecialization(Converted,
+ TemplateParams,
+ InsertPos);
else
- PrevDecl = ClassTemplate->findSpecialization(CanonicalConverted, InsertPos);
+ PrevDecl = ClassTemplate->findSpecialization(Converted, InsertPos);
ClassTemplateSpecializationDecl *Specialization = nullptr;
@@ -8729,7 +8647,7 @@ DeclResult Sema::ActOnClassTemplateSpecialization(
// arguments of the class template partial specialization.
TemplateName CanonTemplate = Context.getCanonicalTemplateName(Name);
CanonType = Context.getTemplateSpecializationType(CanonTemplate,
- CanonicalConverted);
+ Converted);
if (Context.hasSameType(CanonType,
ClassTemplate->getInjectedClassNameSpecialization()) &&
@@ -8759,11 +8677,16 @@ DeclResult Sema::ActOnClassTemplateSpecialization(
// Create a new class template partial specialization declaration node.
ClassTemplatePartialSpecializationDecl *PrevPartial
= cast_or_null<ClassTemplatePartialSpecializationDecl>(PrevDecl);
- ClassTemplatePartialSpecializationDecl *Partial =
- ClassTemplatePartialSpecializationDecl::Create(
- Context, Kind, ClassTemplate->getDeclContext(), KWLoc,
- TemplateNameLoc, TemplateParams, ClassTemplate, CanonicalConverted,
- TemplateArgs, CanonType, PrevPartial);
+ ClassTemplatePartialSpecializationDecl *Partial
+ = ClassTemplatePartialSpecializationDecl::Create(Context, Kind,
+ ClassTemplate->getDeclContext(),
+ KWLoc, TemplateNameLoc,
+ TemplateParams,
+ ClassTemplate,
+ Converted,
+ TemplateArgs,
+ CanonType,
+ PrevPartial);
SetNestedNameSpecifier(*this, Partial, SS);
if (TemplateParameterLists.size() > 1 && SS.isSet()) {
Partial->setTemplateParameterListsInfo(
@@ -8783,9 +8706,13 @@ DeclResult Sema::ActOnClassTemplateSpecialization(
} else {
// Create a new class template specialization declaration node for
// this explicit specialization or friend declaration.
- Specialization = ClassTemplateSpecializationDecl::Create(
- Context, Kind, ClassTemplate->getDeclContext(), KWLoc, TemplateNameLoc,
- ClassTemplate, CanonicalConverted, PrevDecl);
+ Specialization
+ = ClassTemplateSpecializationDecl::Create(Context, Kind,
+ ClassTemplate->getDeclContext(),
+ KWLoc, TemplateNameLoc,
+ ClassTemplate,
+ Converted,
+ PrevDecl);
SetNestedNameSpecifier(*this, Specialization, SS);
if (TemplateParameterLists.size() > 0) {
Specialization->setTemplateParameterListsInfo(Context,
@@ -8797,8 +8724,8 @@ DeclResult Sema::ActOnClassTemplateSpecialization(
if (CurContext->isDependentContext()) {
TemplateName CanonTemplate = Context.getCanonicalTemplateName(Name);
- CanonType = Context.getTemplateSpecializationType(CanonTemplate,
- CanonicalConverted);
+ CanonType = Context.getTemplateSpecializationType(
+ CanonTemplate, Converted);
} else {
CanonType = Context.getTypeDeclType(Specialization);
}
@@ -9964,17 +9891,17 @@ DeclResult Sema::ActOnExplicitInstantiation(
// Check that the template argument list is well-formed for this
// template.
- SmallVector<TemplateArgument, 4> SugaredConverted, CanonicalConverted;
- if (CheckTemplateArgumentList(ClassTemplate, TemplateNameLoc, TemplateArgs,
- false, SugaredConverted, CanonicalConverted,
+ SmallVector<TemplateArgument, 4> Converted;
+ if (CheckTemplateArgumentList(ClassTemplate, TemplateNameLoc,
+ TemplateArgs, false, Converted,
/*UpdateArgsWithConversions=*/true))
return true;
// Find the class template specialization declaration that
// corresponds to these arguments.
void *InsertPos = nullptr;
- ClassTemplateSpecializationDecl *PrevDecl =
- ClassTemplate->findSpecialization(CanonicalConverted, InsertPos);
+ ClassTemplateSpecializationDecl *PrevDecl
+ = ClassTemplate->findSpecialization(Converted, InsertPos);
TemplateSpecializationKind PrevDecl_TSK
= PrevDecl ? PrevDecl->getTemplateSpecializationKind() : TSK_Undeclared;
@@ -10031,9 +9958,13 @@ DeclResult Sema::ActOnExplicitInstantiation(
if (!Specialization) {
// Create a new class template specialization declaration node for
// this explicit specialization.
- Specialization = ClassTemplateSpecializationDecl::Create(
- Context, Kind, ClassTemplate->getDeclContext(), KWLoc, TemplateNameLoc,
- ClassTemplate, CanonicalConverted, PrevDecl);
+ Specialization
+ = ClassTemplateSpecializationDecl::Create(Context, Kind,
+ ClassTemplate->getDeclContext(),
+ KWLoc, TemplateNameLoc,
+ ClassTemplate,
+ Converted,
+ PrevDecl);
SetNestedNameSpecifier(*this, Specialization, SS);
if (!HasNoEffect && !PrevDecl) {
diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 24629162ecfce..7bc743044b740 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -2628,11 +2628,13 @@ Sema::getIdentityTemplateArgumentLoc(NamedDecl *TemplateParm,
/// Convert the given deduced template argument and add it to the set of
/// fully-converted template arguments.
-static bool ConvertDeducedTemplateArgument(
- Sema &S, NamedDecl *Param, DeducedTemplateArgument Arg, NamedDecl *Template,
- TemplateDeductionInfo &Info, bool IsDeduced,
- SmallVectorImpl<TemplateArgument> &SugaredOutput,
- SmallVectorImpl<TemplateArgument> &CanonicalOutput) {
+static bool
+ConvertDeducedTemplateArgument(Sema &S, NamedDecl *Param,
+ DeducedTemplateArgument Arg,
+ NamedDecl *Template,
+ TemplateDeductionInfo &Info,
+ bool IsDeduced,
+ SmallVectorImpl<TemplateArgument> &Output) {
auto ConvertArg = [&](DeducedTemplateArgument Arg,
unsigned ArgumentPackIndex) {
// Convert the deduced template argument into a template
@@ -2644,8 +2646,7 @@ static bool ConvertDeducedTemplateArgument(
// Check the template argument, converting it as necessary.
return S.CheckTemplateArgument(
Param, ArgLoc, Template, Template->getLocation(),
- Template->getSourceRange().getEnd(), ArgumentPackIndex, SugaredOutput,
- CanonicalOutput,
+ Template->getSourceRange().getEnd(), ArgumentPackIndex, Output,
IsDeduced
? (Arg.wasDeducedFromArrayBound() ? Sema::CTAK_DeducedFromArrayBound
: Sema::CTAK_Deduced)
@@ -2655,8 +2656,7 @@ static bool ConvertDeducedTemplateArgument(
if (Arg.getKind() == TemplateArgument::Pack) {
// This is a template argument pack, so check each of its arguments against
// the template parameter.
- SmallVector<TemplateArgument, 2> SugaredPackedArgsBuilder,
- CanonicalPackedArgsBuilder;
+ SmallVector<TemplateArgument, 2> PackedArgsBuilder;
for (const auto &P : Arg.pack_elements()) {
// When converting the deduced template argument, append it to the
// general output list. We need to do this so that the template argument
@@ -2675,25 +2675,23 @@ static bool ConvertDeducedTemplateArgument(
<< Arg << Param;
return true;
}
- if (ConvertArg(InnerArg, SugaredPackedArgsBuilder.size()))
+ if (ConvertArg(InnerArg, PackedArgsBuilder.size()))
return true;
// Move the converted template argument into our argument pack.
- SugaredPackedArgsBuilder.push_back(SugaredOutput.pop_back_val());
- CanonicalPackedArgsBuilder.push_back(CanonicalOutput.pop_back_val());
+ PackedArgsBuilder.push_back(Output.pop_back_val());
}
// If the pack is empty, we still need to substitute into the parameter
// itself, in case that substitution fails.
- if (SugaredPackedArgsBuilder.empty()) {
+ if (PackedArgsBuilder.empty()) {
LocalInstantiationScope Scope(S);
- TemplateArgumentList TemplateArgs(TemplateArgumentList::OnStack,
- CanonicalOutput);
+ TemplateArgumentList TemplateArgs(TemplateArgumentList::OnStack, Output);
MultiLevelTemplateArgumentList Args(Template, TemplateArgs.asArray());
if (auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param)) {
Sema::InstantiatingTemplate Inst(S, Template->getLocation(), Template,
- NTTP, CanonicalOutput,
+ NTTP, Output,
Template->getSourceRange());
if (Inst.isInvalid() ||
S.SubstType(NTTP->getType(), Args, NTTP->getLocation(),
@@ -2701,7 +2699,7 @@ static bool ConvertDeducedTemplateArgument(
return true;
} else if (auto *TTP = dyn_cast<TemplateTemplateParmDecl>(Param)) {
Sema::InstantiatingTemplate Inst(S, Template->getLocation(), Template,
- TTP, CanonicalOutput,
+ TTP, Output,
Template->getSourceRange());
if (Inst.isInvalid() || !S.SubstDecl(TTP, S.CurContext, Args))
return true;
@@ -2710,10 +2708,8 @@ static bool ConvertDeducedTemplateArgument(
}
// Create the resulting argument pack.
- SugaredOutput.push_back(
- TemplateArgument::CreatePackCopy(S.Context, SugaredPackedArgsBuilder));
- CanonicalOutput.push_back(TemplateArgument::CreatePackCopy(
- S.Context, CanonicalPackedArgsBuilder));
+ Output.push_back(
+ TemplateArgument::CreatePackCopy(S.Context, PackedArgsBuilder));
return false;
}
@@ -2723,13 +2719,11 @@ static bool ConvertDeducedTemplateArgument(
// FIXME: This should not be a template, but
// ClassTemplatePartialSpecializationDecl sadly does not derive from
// TemplateDecl.
-template <typename TemplateDeclT>
+template<typename TemplateDeclT>
static Sema::TemplateDeductionResult ConvertDeducedTemplateArguments(
Sema &S, TemplateDeclT *Template, bool IsDeduced,
SmallVectorImpl<DeducedTemplateArgument> &Deduced,
- TemplateDeductionInfo &Info,
- SmallVectorImpl<TemplateArgument> &SugaredBuilder,
- SmallVectorImpl<TemplateArgument> &CanonicalBuilder,
+ TemplateDeductionInfo &Info, SmallVectorImpl<TemplateArgument> &Builder,
LocalInstantiationScope *CurrentInstantiationScope = nullptr,
unsigned NumAlreadyConverted = 0, bool PartialOverloading = false) {
TemplateParameterList *TemplateParams = Template->getTemplateParameters();
@@ -2763,9 +2757,7 @@ static Sema::TemplateDeductionResult ConvertDeducedTemplateArguments(
// We have already fully type-checked and converted this
// argument, because it was explicitly-specified. Just record the
// presence of this argument.
- SugaredBuilder.push_back(Deduced[I]);
- CanonicalBuilder.push_back(
- S.Context.getCanonicalTemplateArgument(Deduced[I]));
+ Builder.push_back(Deduced[I]);
continue;
}
}
@@ -2773,13 +2765,10 @@ static Sema::TemplateDeductionResult ConvertDeducedTemplateArguments(
// We may have deduced this argument, so it still needs to be
// checked and converted.
if (ConvertDeducedTemplateArgument(S, Param, Deduced[I], Template, Info,
- IsDeduced, SugaredBuilder,
- CanonicalBuilder)) {
+ IsDeduced, Builder)) {
Info.Param = makeTemplateParameter(Param);
// FIXME: These template arguments are temporary. Free them!
- Info.reset(
- TemplateArgumentList::CreateCopy(S.Context, SugaredBuilder),
- TemplateArgumentList::CreateCopy(S.Context, CanonicalBuilder));
+ Info.reset(TemplateArgumentList::CreateCopy(S.Context, Builder));
return Sema::TDK_SubstitutionFailure;
}
@@ -2810,16 +2799,15 @@ static Sema::TemplateDeductionResult ConvertDeducedTemplateArguments(
S.getLangOpts().CPlusPlus17);
DefArg = S.SubstDefaultTemplateArgumentIfAvailable(
- TD, TD->getLocation(), TD->getSourceRange().getEnd(), Param,
- CanonicalBuilder, HasDefaultArg);
+ TD, TD->getLocation(), TD->getSourceRange().getEnd(), Param, Builder,
+ HasDefaultArg);
}
// If there was no default argument, deduction is incomplete.
if (DefArg.getArgument().isNull()) {
Info.Param = makeTemplateParameter(
const_cast<NamedDecl *>(TemplateParams->getParam(I)));
- Info.reset(TemplateArgumentList::CreateCopy(S.Context, SugaredBuilder),
- TemplateArgumentList::CreateCopy(S.Context, CanonicalBuilder));
+ Info.reset(TemplateArgumentList::CreateCopy(S.Context, Builder));
if (PartialOverloading) break;
return HasDefaultArg ? Sema::TDK_SubstitutionFailure
@@ -2827,14 +2815,13 @@ static Sema::TemplateDeductionResult ConvertDeducedTemplateArguments(
}
// Check whether we can actually use the default argument.
- if (S.CheckTemplateArgument(
- Param, DefArg, TD, TD->getLocation(), TD->getSourceRange().getEnd(),
- 0, SugaredBuilder, CanonicalBuilder, Sema::CTAK_Specified)) {
+ if (S.CheckTemplateArgument(Param, DefArg, TD, TD->getLocation(),
+ TD->getSourceRange().getEnd(), 0, Builder,
+ Sema::CTAK_Specified)) {
Info.Param = makeTemplateParameter(
const_cast<NamedDecl *>(TemplateParams->getParam(I)));
// FIXME: These template arguments are temporary. Free them!
- Info.reset(TemplateArgumentList::CreateCopy(S.Context, SugaredBuilder),
- TemplateArgumentList::CreateCopy(S.Context, CanonicalBuilder));
+ Info.reset(TemplateArgumentList::CreateCopy(S.Context, Builder));
return Sema::TDK_SubstitutionFailure;
}
@@ -2876,18 +2863,16 @@ bool DeducedArgsNeedReplacement<ClassTemplatePartialSpecializationDecl>(
return !Spec->isClassScopeExplicitSpecialization();
}
-template <typename TemplateDeclT>
+template<typename TemplateDeclT>
static Sema::TemplateDeductionResult
-CheckDeducedArgumentConstraints(Sema &S, TemplateDeclT *Template,
- ArrayRef<TemplateArgument> SugaredDeducedArgs,
- ArrayRef<TemplateArgument> CanonicalDeducedArgs,
- TemplateDeductionInfo &Info) {
+CheckDeducedArgumentConstraints(Sema& S, TemplateDeclT *Template,
+ ArrayRef<TemplateArgument> DeducedArgs,
+ TemplateDeductionInfo& Info) {
llvm::SmallVector<const Expr *, 3> AssociatedConstraints;
Template->getAssociatedConstraints(AssociatedConstraints);
bool NeedsReplacement = DeducedArgsNeedReplacement(Template);
- TemplateArgumentList DeducedTAL{TemplateArgumentList::OnStack,
- CanonicalDeducedArgs};
+ TemplateArgumentList DeducedTAL{TemplateArgumentList::OnStack, DeducedArgs};
MultiLevelTemplateArgumentList MLTAL = S.getTemplateInstantiationArgs(
Template, /*InnerMost=*/NeedsReplacement ? nullptr : &DeducedTAL,
@@ -2899,15 +2884,13 @@ CheckDeducedArgumentConstraints(Sema &S, TemplateDeclT *Template,
// not class-scope explicit specialization, so replace with Deduced Args
// instead of adding to inner-most.
if (NeedsReplacement)
- MLTAL.replaceInnermostTemplateArguments(CanonicalDeducedArgs);
+ MLTAL.replaceInnermostTemplateArguments(DeducedArgs);
if (S.CheckConstraintSatisfaction(Template, AssociatedConstraints, MLTAL,
Info.getLocation(),
Info.AssociatedConstraintsSatisfaction) ||
!Info.AssociatedConstraintsSatisfaction.IsSatisfied) {
- Info.reset(
- TemplateArgumentList::CreateCopy(S.Context, SugaredDeducedArgs),
- TemplateArgumentList::CreateCopy(S.Context, CanonicalDeducedArgs));
+ Info.reset(TemplateArgumentList::CreateCopy(S.Context, DeducedArgs));
return Sema::TDK_ConstraintsNotSatisfied;
}
return Sema::TDK_Success;
@@ -2932,19 +2915,16 @@ FinishTemplateArgumentDeduction(
// C++ [temp.deduct.type]p2:
// [...] or if any template argument remains neither deduced nor
// explicitly specified, template argument deduction fails.
- SmallVector<TemplateArgument, 4> SugaredBuilder, CanonicalBuilder;
+ SmallVector<TemplateArgument, 4> Builder;
if (auto Result = ConvertDeducedTemplateArguments(
- S, Partial, IsPartialOrdering, Deduced, Info, SugaredBuilder,
- CanonicalBuilder))
+ S, Partial, IsPartialOrdering, Deduced, Info, Builder))
return Result;
// Form the template argument list from the deduced template arguments.
- TemplateArgumentList *SugaredDeducedArgumentList =
- TemplateArgumentList::CreateCopy(S.Context, SugaredBuilder);
- TemplateArgumentList *CanonicalDeducedArgumentList =
- TemplateArgumentList::CreateCopy(S.Context, CanonicalBuilder);
+ TemplateArgumentList *DeducedArgumentList
+ = TemplateArgumentList::CreateCopy(S.Context, Builder);
- Info.reset(SugaredDeducedArgumentList, CanonicalDeducedArgumentList);
+ Info.reset(DeducedArgumentList);
// Substitute the deduced template arguments into the template
// arguments of the class template partial specialization, and
@@ -2959,11 +2939,10 @@ FinishTemplateArgumentDeduction(
TemplateArgumentListInfo InstArgs(PartialTemplArgInfo->LAngleLoc,
PartialTemplArgInfo->RAngleLoc);
- if (S.SubstTemplateArguments(
- PartialTemplArgInfo->arguments(),
- MultiLevelTemplateArgumentList(
- Partial, CanonicalDeducedArgumentList->asArray()),
- InstArgs)) {
+ if (S.SubstTemplateArguments(PartialTemplArgInfo->arguments(),
+ MultiLevelTemplateArgumentList(
+ Partial, DeducedArgumentList->asArray()),
+ InstArgs)) {
unsigned ArgIdx = InstArgs.size(), ParamIdx = ArgIdx;
if (ParamIdx >= Partial->getTemplateParameters()->size())
ParamIdx = Partial->getTemplateParameters()->size() - 1;
@@ -2976,18 +2955,17 @@ FinishTemplateArgumentDeduction(
}
bool ConstraintsNotSatisfied;
- SmallVector<TemplateArgument, 4> SugaredConvertedInstArgs,
- CanonicalConvertedInstArgs;
- if (S.CheckTemplateArgumentList(
- Template, Partial->getLocation(), InstArgs, false,
- SugaredConvertedInstArgs, CanonicalConvertedInstArgs,
- /*UpdateArgsWithConversions=*/true, &ConstraintsNotSatisfied))
- return ConstraintsNotSatisfied ? Sema::TDK_ConstraintsNotSatisfied
- : Sema::TDK_SubstitutionFailure;
+ SmallVector<TemplateArgument, 4> ConvertedInstArgs;
+ if (S.CheckTemplateArgumentList(Template, Partial->getLocation(), InstArgs,
+ false, ConvertedInstArgs,
+ /*UpdateArgsWithConversions=*/true,
+ &ConstraintsNotSatisfied))
+ return ConstraintsNotSatisfied ? Sema::TDK_ConstraintsNotSatisfied :
+ Sema::TDK_SubstitutionFailure;
TemplateParameterList *TemplateParams = Template->getTemplateParameters();
for (unsigned I = 0, E = TemplateParams->size(); I != E; ++I) {
- TemplateArgument InstArg = SugaredConvertedInstArgs.data()[I];
+ TemplateArgument InstArg = ConvertedInstArgs.data()[I];
if (!isSameTemplateArg(S.Context, TemplateArgs[I], InstArg,
IsPartialOrdering)) {
Info.Param = makeTemplateParameter(TemplateParams->getParam(I));
@@ -3000,8 +2978,7 @@ FinishTemplateArgumentDeduction(
if (Trap.hasErrorOccurred())
return Sema::TDK_SubstitutionFailure;
- if (auto Result = CheckDeducedArgumentConstraints(S, Partial, SugaredBuilder,
- CanonicalBuilder, Info))
+ if (auto Result = CheckDeducedArgumentConstraints(S, Partial, Builder, Info))
return Result;
return Sema::TDK_Success;
@@ -3025,20 +3002,17 @@ static Sema::TemplateDeductionResult FinishTemplateArgumentDeduction(
// C++ [temp.deduct.type]p2:
// [...] or if any template argument remains neither deduced nor
// explicitly specified, template argument deduction fails.
- SmallVector<TemplateArgument, 4> SugaredBuilder, CanonicalBuilder;
+ SmallVector<TemplateArgument, 4> Builder;
if (auto Result = ConvertDeducedTemplateArguments(
- S, Template, /*IsDeduced*/ PartialOrdering, Deduced, Info,
- SugaredBuilder, CanonicalBuilder,
- /*CurrentInstantiationScope=*/nullptr,
- /*NumAlreadyConverted=*/0U, /*PartialOverloading=*/false))
+ S, Template, /*IsDeduced*/PartialOrdering, Deduced, Info, Builder))
return Result;
// Check that we produced the correct argument list.
TemplateParameterList *TemplateParams = Template->getTemplateParameters();
for (unsigned I = 0, E = TemplateParams->size(); I != E; ++I) {
- TemplateArgument InstArg = CanonicalBuilder[I];
+ TemplateArgument InstArg = Builder[I];
if (!isSameTemplateArg(S.Context, TemplateArgs[I], InstArg, PartialOrdering,
- /*PackExpansionMatchesPack=*/true)) {
+ /*PackExpansionMatchesPack*/ true)) {
Info.Param = makeTemplateParameter(TemplateParams->getParam(I));
Info.FirstArg = TemplateArgs[I];
Info.SecondArg = InstArg;
@@ -3049,8 +3023,8 @@ static Sema::TemplateDeductionResult FinishTemplateArgumentDeduction(
if (Trap.hasErrorOccurred())
return Sema::TDK_SubstitutionFailure;
- if (auto Result = CheckDeducedArgumentConstraints(S, Template, SugaredBuilder,
- CanonicalBuilder, Info))
+ if (auto Result = CheckDeducedArgumentConstraints(S, Template, Builder,
+ Info))
return Result;
return Sema::TDK_Success;
@@ -3202,12 +3176,14 @@ static bool isSimpleTemplateIdType(QualType T) {
///
/// \returns TDK_Success if substitution was successful, or some failure
/// condition.
-Sema::TemplateDeductionResult Sema::SubstituteExplicitTemplateArguments(
- FunctionTemplateDecl *FunctionTemplate,
- TemplateArgumentListInfo &ExplicitTemplateArgs,
- SmallVectorImpl<DeducedTemplateArgument> &Deduced,
- SmallVectorImpl<QualType> &ParamTypes, QualType *FunctionType,
- TemplateDeductionInfo &Info) {
+Sema::TemplateDeductionResult
+Sema::SubstituteExplicitTemplateArguments(
+ FunctionTemplateDecl *FunctionTemplate,
+ TemplateArgumentListInfo &ExplicitTemplateArgs,
+ SmallVectorImpl<DeducedTemplateArgument> &Deduced,
+ SmallVectorImpl<QualType> &ParamTypes,
+ QualType *FunctionType,
+ TemplateDeductionInfo &Info) {
FunctionDecl *Function = FunctionTemplate->getTemplatedDecl();
TemplateParameterList *TemplateParams
= FunctionTemplate->getTemplateParameters();
@@ -3233,7 +3209,7 @@ Sema::TemplateDeductionResult Sema::SubstituteExplicitTemplateArguments(
// declaration order of their corresponding template-parameters. The
// template argument list shall not specify more template-arguments than
// there are corresponding template-parameters.
- SmallVector<TemplateArgument, 4> SugaredBuilder, CanonicalBuilder;
+ SmallVector<TemplateArgument, 4> Builder;
// Enter a new template instantiation context where we check the
// explicitly-specified template arguments against this function template,
@@ -3246,11 +3222,9 @@ Sema::TemplateDeductionResult Sema::SubstituteExplicitTemplateArguments(
return TDK_InstantiationDepth;
if (CheckTemplateArgumentList(FunctionTemplate, SourceLocation(),
- ExplicitTemplateArgs, true, SugaredBuilder,
- CanonicalBuilder,
- /*UpdateArgsWithConversions=*/false) ||
+ ExplicitTemplateArgs, true, Builder, false) ||
Trap.hasErrorOccurred()) {
- unsigned Index = SugaredBuilder.size();
+ unsigned Index = Builder.size();
if (Index >= TemplateParams->size())
return TDK_SubstitutionFailure;
Info.Param = makeTemplateParameter(TemplateParams->getParam(Index));
@@ -3259,12 +3233,9 @@ Sema::TemplateDeductionResult Sema::SubstituteExplicitTemplateArguments(
// Form the template argument list from the explicitly-specified
// template arguments.
- TemplateArgumentList *SugaredExplicitArgumentList =
- TemplateArgumentList::CreateCopy(Context, SugaredBuilder);
- TemplateArgumentList *CanonicalExplicitArgumentList =
- TemplateArgumentList::CreateCopy(Context, CanonicalBuilder);
- Info.setExplicitArgs(SugaredExplicitArgumentList,
- CanonicalExplicitArgumentList);
+ TemplateArgumentList *ExplicitArgumentList
+ = TemplateArgumentList::CreateCopy(Context, Builder);
+ Info.setExplicitArgs(ExplicitArgumentList);
// Template argument deduction and the final substitution should be
// done in the context of the templated declaration. Explicit
@@ -3277,15 +3248,15 @@ Sema::TemplateDeductionResult Sema::SubstituteExplicitTemplateArguments(
// the explicit template arguments. They'll be used as part of deduction
// for this template parameter pack.
unsigned PartiallySubstitutedPackIndex = -1u;
- if (!CanonicalBuilder.empty()) {
- const TemplateArgument &Arg = CanonicalBuilder.back();
+ if (!Builder.empty()) {
+ const TemplateArgument &Arg = Builder.back();
if (Arg.getKind() == TemplateArgument::Pack) {
- auto *Param = TemplateParams->getParam(CanonicalBuilder.size() - 1);
+ auto *Param = TemplateParams->getParam(Builder.size() - 1);
// If this is a fully-saturated fixed-size pack, it should be
// fully-substituted, not partially-substituted.
Optional<unsigned> Expansions = getExpandedPackSize(Param);
if (!Expansions || Arg.pack_size() < *Expansions) {
- PartiallySubstitutedPackIndex = CanonicalBuilder.size() - 1;
+ PartiallySubstitutedPackIndex = Builder.size() - 1;
CurrentInstantiationScope->SetPartiallySubstitutedPack(
Param, Arg.pack_begin(), Arg.pack_size());
}
@@ -3306,12 +3277,11 @@ Sema::TemplateDeductionResult Sema::SubstituteExplicitTemplateArguments(
// return type, substitute it after the arguments to ensure we substitute
// in lexical order.
if (Proto->hasTrailingReturn()) {
- if (SubstParmTypes(
- Function->getLocation(), Function->parameters(),
- Proto->getExtParameterInfosOrNull(),
- MultiLevelTemplateArgumentList(
- FunctionTemplate, CanonicalExplicitArgumentList->asArray()),
- ParamTypes, /*params=*/nullptr, ExtParamInfos))
+ if (SubstParmTypes(Function->getLocation(), Function->parameters(),
+ Proto->getExtParameterInfosOrNull(),
+ MultiLevelTemplateArgumentList(
+ FunctionTemplate, ExplicitArgumentList->asArray()),
+ ParamTypes, /*params*/ nullptr, ExtParamInfos))
return TDK_SubstitutionFailure;
}
@@ -3334,11 +3304,11 @@ Sema::TemplateDeductionResult Sema::SubstituteExplicitTemplateArguments(
CXXThisScopeRAII ThisScope(*this, ThisContext, ThisTypeQuals,
getLangOpts().CPlusPlus11);
- ResultType = SubstType(
- Proto->getReturnType(),
- MultiLevelTemplateArgumentList(
- FunctionTemplate, CanonicalExplicitArgumentList->asArray()),
- Function->getTypeSpecStartLoc(), Function->getDeclName());
+ ResultType =
+ SubstType(Proto->getReturnType(),
+ MultiLevelTemplateArgumentList(
+ FunctionTemplate, ExplicitArgumentList->asArray()),
+ Function->getTypeSpecStartLoc(), Function->getDeclName());
if (ResultType.isNull() || Trap.hasErrorOccurred())
return TDK_SubstitutionFailure;
// CUDA: Kernel function must have 'void' return type.
@@ -3353,12 +3323,11 @@ Sema::TemplateDeductionResult Sema::SubstituteExplicitTemplateArguments(
// Instantiate the types of each of the function parameters given the
// explicitly-specified template arguments if we didn't do so earlier.
if (!Proto->hasTrailingReturn() &&
- SubstParmTypes(
- Function->getLocation(), Function->parameters(),
- Proto->getExtParameterInfosOrNull(),
- MultiLevelTemplateArgumentList(
- FunctionTemplate, CanonicalExplicitArgumentList->asArray()),
- ParamTypes, /*params*/ nullptr, ExtParamInfos))
+ SubstParmTypes(Function->getLocation(), Function->parameters(),
+ Proto->getExtParameterInfosOrNull(),
+ MultiLevelTemplateArgumentList(
+ FunctionTemplate, ExplicitArgumentList->asArray()),
+ ParamTypes, /*params*/ nullptr, ExtParamInfos))
return TDK_SubstitutionFailure;
if (FunctionType) {
@@ -3372,8 +3341,8 @@ Sema::TemplateDeductionResult Sema::SubstituteExplicitTemplateArguments(
if (getLangOpts().CPlusPlus17 &&
SubstExceptionSpec(
Function->getLocation(), EPI.ExceptionSpec, ExceptionStorage,
- MultiLevelTemplateArgumentList(
- FunctionTemplate, CanonicalExplicitArgumentList->asArray())))
+ MultiLevelTemplateArgumentList(FunctionTemplate,
+ ExplicitArgumentList->asArray())))
return TDK_SubstitutionFailure;
*FunctionType = BuildFunctionType(ResultType, ParamTypes,
@@ -3395,8 +3364,8 @@ Sema::TemplateDeductionResult Sema::SubstituteExplicitTemplateArguments(
// parameter pack, however, will be set to NULL since the deduction
// mechanism handles the partially-substituted argument pack directly.
Deduced.reserve(TemplateParams->size());
- for (unsigned I = 0, N = SugaredExplicitArgumentList->size(); I != N; ++I) {
- const TemplateArgument &Arg = SugaredExplicitArgumentList->get(I);
+ for (unsigned I = 0, N = ExplicitArgumentList->size(); I != N; ++I) {
+ const TemplateArgument &Arg = ExplicitArgumentList->get(I);
if (I == PartiallySubstitutedPackIndex)
Deduced.push_back(DeducedTemplateArgument());
else
@@ -3584,11 +3553,11 @@ Sema::TemplateDeductionResult Sema::FinishTemplateArgumentDeduction(
// C++ [temp.deduct.type]p2:
// [...] or if any template argument remains neither deduced nor
// explicitly specified, template argument deduction fails.
- SmallVector<TemplateArgument, 4> SugaredBuilder, CanonicalBuilder;
+ SmallVector<TemplateArgument, 4> Builder;
if (auto Result = ConvertDeducedTemplateArguments(
- *this, FunctionTemplate, /*IsDeduced*/ true, Deduced, Info,
- SugaredBuilder, CanonicalBuilder, CurrentInstantiationScope,
- NumExplicitlySpecified, PartialOverloading))
+ *this, FunctionTemplate, /*IsDeduced*/true, Deduced, Info, Builder,
+ CurrentInstantiationScope, NumExplicitlySpecified,
+ PartialOverloading))
return Result;
// C++ [temp.deduct.call]p10: [DR1391]
@@ -3604,19 +3573,17 @@ Sema::TemplateDeductionResult Sema::FinishTemplateArgumentDeduction(
return TDK_NonDependentConversionFailure;
// Form the template argument list from the deduced template arguments.
- TemplateArgumentList *SugaredDeducedArgumentList =
- TemplateArgumentList::CreateCopy(Context, SugaredBuilder);
- TemplateArgumentList *CanonicalDeducedArgumentList =
- TemplateArgumentList::CreateCopy(Context, CanonicalBuilder);
- Info.reset(SugaredDeducedArgumentList, CanonicalDeducedArgumentList);
+ TemplateArgumentList *DeducedArgumentList
+ = TemplateArgumentList::CreateCopy(Context, Builder);
+ Info.reset(DeducedArgumentList);
// Substitute the deduced template arguments into the function template
// declaration to produce the function template specialization.
DeclContext *Owner = FunctionTemplate->getDeclContext();
if (FunctionTemplate->getFriendObjectKind())
Owner = FunctionTemplate->getLexicalDeclContext();
- MultiLevelTemplateArgumentList SubstArgs(
- FunctionTemplate, CanonicalDeducedArgumentList->asArray());
+ MultiLevelTemplateArgumentList SubstArgs(FunctionTemplate,
+ DeducedArgumentList->asArray());
Specialization = cast_or_null<FunctionDecl>(
SubstDecl(FunctionTemplate->getTemplatedDecl(), Owner, SubstArgs));
if (!Specialization || Specialization->isInvalidDecl())
@@ -3627,10 +3594,9 @@ Sema::TemplateDeductionResult Sema::FinishTemplateArgumentDeduction(
// If the template argument list is owned by the function template
// specialization, release it.
- if (Specialization->getTemplateSpecializationArgs() ==
- CanonicalDeducedArgumentList &&
+ if (Specialization->getTemplateSpecializationArgs() == DeducedArgumentList &&
!Trap.hasErrorOccurred())
- Info.takeCanonical();
+ Info.take();
// There may have been an error that did not prevent us from constructing a
// declaration. Mark the declaration invalid and return with a substitution
@@ -3649,16 +3615,13 @@ Sema::TemplateDeductionResult Sema::FinishTemplateArgumentDeduction(
// ([temp.constr.constr]). If the constraints are not satisfied, type
// deduction fails.
if (!PartialOverloading ||
- (CanonicalBuilder.size() ==
- FunctionTemplate->getTemplateParameters()->size())) {
- if (CheckInstantiatedFunctionTemplateConstraints(
- Info.getLocation(), Specialization, CanonicalBuilder,
- Info.AssociatedConstraintsSatisfaction))
+ (Builder.size() == FunctionTemplate->getTemplateParameters()->size())) {
+ if (CheckInstantiatedFunctionTemplateConstraints(Info.getLocation(),
+ Specialization, Builder, Info.AssociatedConstraintsSatisfaction))
return TDK_MiscellaneousDeductionFailure;
if (!Info.AssociatedConstraintsSatisfaction.IsSatisfied) {
- Info.reset(Info.takeSugared(),
- TemplateArgumentList::CreateCopy(Context, CanonicalBuilder));
+ Info.reset(TemplateArgumentList::CreateCopy(Context, Builder));
return TDK_ConstraintsNotSatisfied;
}
}
@@ -4672,12 +4635,12 @@ static bool CheckDeducedPlaceholderConstraints(Sema &S, const AutoType &Type,
for (unsigned I = 0, C = TypeLoc.getNumArgs(); I != C; ++I)
TemplateArgs.addArgument(TypeLoc.getArgLoc(I));
- llvm::SmallVector<TemplateArgument, 4> SugaredConverted, CanonicalConverted;
+ llvm::SmallVector<TemplateArgument, 4> Converted;
if (S.CheckTemplateArgumentList(Concept, SourceLocation(), TemplateArgs,
- /*PartialTemplateArgs=*/false,
- SugaredConverted, CanonicalConverted))
+ /*PartialTemplateArgs=*/false, Converted))
return true;
- MultiLevelTemplateArgumentList MLTAL(Concept, CanonicalConverted);
+ MultiLevelTemplateArgumentList MLTAL;
+ MLTAL.addOuterTemplateArguments(Concept, Converted);
if (S.CheckConstraintSatisfaction(Concept, {Concept->getConstraintExpr()},
MLTAL, TypeLoc.getLocalSourceRange(),
Satisfaction))
@@ -5810,15 +5773,13 @@ bool Sema::isTemplateTemplateParameterAtLeastAsSpecializedAs(
// C++1z [temp.arg.template]p3:
// If the rewrite produces an invalid type, then P is not at least as
// specialized as A.
- SmallVector<TemplateArgument, 4> SugaredPArgs;
- if (CheckTemplateArgumentList(AArg, Loc, PArgList, false, SugaredPArgs,
- PArgs) ||
+ if (CheckTemplateArgumentList(AArg, Loc, PArgList, false, PArgs) ||
Trap.hasErrorOccurred())
return false;
}
- QualType AType = Context.getCanonicalTemplateSpecializationType(X, AArgs);
- QualType PType = Context.getCanonicalTemplateSpecializationType(X, PArgs);
+ QualType AType = Context.getTemplateSpecializationType(X, AArgs);
+ QualType PType = Context.getTemplateSpecializationType(X, PArgs);
// ... the function template corresponding to P is at least as specialized
// as the function template corresponding to A according to the partial
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index c19714c7a8b4d..7475289745c7d 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -1831,16 +1831,14 @@ TemplateInstantiator::TransformSubstNonTypeTemplateParmExpr(
// Type=char)),
// Type=decltype(2)))
// The call to CheckTemplateArgument here produces the ImpCast.
- TemplateArgument SugaredConverted, CanonicalConverted;
- if (SemaRef
- .CheckTemplateArgument(E->getParameter(), SubstType,
- SubstReplacement.get(), SugaredConverted,
- CanonicalConverted, Sema::CTAK_Specified)
- .isInvalid())
+ TemplateArgument Converted;
+ if (SemaRef.CheckTemplateArgument(E->getParameter(), SubstType,
+ SubstReplacement.get(),
+ Converted).isInvalid())
return true;
return transformNonTypeTemplateParmRef(E->getAssociatedDecl(),
E->getParameter(), E->getExprLoc(),
- CanonicalConverted, E->getPackIndex());
+ Converted, E->getPackIndex());
}
ExprResult TemplateInstantiator::RebuildVarDeclRefExpr(VarDecl *PD,
@@ -3447,7 +3445,7 @@ getPatternForClassTemplateSpecialization(
} else {
Matched.push_back(PartialSpecMatchResult());
Matched.back().Partial = Partial;
- Matched.back().Args = Info.takeCanonical();
+ Matched.back().Args = Info.take();
}
}
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 112137a2dcfb9..dc694b2cb7c97 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -3752,10 +3752,12 @@ TemplateDeclInstantiator::VisitClassTemplateSpecializationDecl(
// Check that the template argument list is well-formed for this
// class template.
- SmallVector<TemplateArgument, 4> SugaredConverted, CanonicalConverted;
- if (SemaRef.CheckTemplateArgumentList(InstClassTemplate, D->getLocation(),
- InstTemplateArgs, false,
- SugaredConverted, CanonicalConverted,
+ SmallVector<TemplateArgument, 4> Converted;
+ if (SemaRef.CheckTemplateArgumentList(InstClassTemplate,
+ D->getLocation(),
+ InstTemplateArgs,
+ false,
+ Converted,
/*UpdateArgsWithConversions=*/true))
return nullptr;
@@ -3763,7 +3765,7 @@ TemplateDeclInstantiator::VisitClassTemplateSpecializationDecl(
// in the member template's set of class template explicit specializations.
void *InsertPos = nullptr;
ClassTemplateSpecializationDecl *PrevDecl =
- InstClassTemplate->findSpecialization(CanonicalConverted, InsertPos);
+ InstClassTemplate->findSpecialization(Converted, InsertPos);
// Check whether we've already seen a conflicting instantiation of this
// declaration (for instance, if there was a prior implicit instantiation).
@@ -3801,7 +3803,7 @@ TemplateDeclInstantiator::VisitClassTemplateSpecializationDecl(
ClassTemplateSpecializationDecl *InstD =
ClassTemplateSpecializationDecl::Create(
SemaRef.Context, D->getTagKind(), Owner, D->getBeginLoc(),
- D->getLocation(), InstClassTemplate, CanonicalConverted, PrevDecl);
+ D->getLocation(), InstClassTemplate, Converted, PrevDecl);
// Add this partial specialization to the set of class template partial
// specializations.
@@ -3815,7 +3817,7 @@ TemplateDeclInstantiator::VisitClassTemplateSpecializationDecl(
// Build the canonical type that describes the converted template
// arguments of the class template explicit specialization.
QualType CanonType = SemaRef.Context.getTemplateSpecializationType(
- TemplateName(InstClassTemplate), CanonicalConverted,
+ TemplateName(InstClassTemplate), Converted,
SemaRef.Context.getRecordType(InstD));
// Build the fully-sugared type for this class template
@@ -3877,17 +3879,16 @@ Decl *TemplateDeclInstantiator::VisitVarTemplateSpecializationDecl(
}
// Check that the template argument list is well-formed for this template.
- SmallVector<TemplateArgument, 4> SugaredConverted, CanonicalConverted;
+ SmallVector<TemplateArgument, 4> Converted;
if (SemaRef.CheckTemplateArgumentList(InstVarTemplate, D->getLocation(),
- VarTemplateArgsInfo, false,
- SugaredConverted, CanonicalConverted,
+ VarTemplateArgsInfo, false, Converted,
/*UpdateArgsWithConversions=*/true))
return nullptr;
// Check whether we've already seen a declaration of this specialization.
void *InsertPos = nullptr;
VarTemplateSpecializationDecl *PrevDecl =
- InstVarTemplate->findSpecialization(CanonicalConverted, InsertPos);
+ InstVarTemplate->findSpecialization(Converted, InsertPos);
// Check whether we've already seen a conflicting instantiation of this
// declaration (for instance, if there was a prior implicit instantiation).
@@ -3899,7 +3900,7 @@ Decl *TemplateDeclInstantiator::VisitVarTemplateSpecializationDecl(
return nullptr;
return VisitVarTemplateSpecializationDecl(
- InstVarTemplate, D, VarTemplateArgsInfo, CanonicalConverted, PrevDecl);
+ InstVarTemplate, D, VarTemplateArgsInfo, Converted, PrevDecl);
}
Decl *TemplateDeclInstantiator::VisitVarTemplateSpecializationDecl(
@@ -4141,29 +4142,32 @@ TemplateDeclInstantiator::InstantiateClassTemplatePartialSpecialization(
// Check that the template argument list is well-formed for this
// class template.
- SmallVector<TemplateArgument, 4> SugaredConverted, CanonicalConverted;
- if (SemaRef.CheckTemplateArgumentList(
- ClassTemplate, PartialSpec->getLocation(), InstTemplateArgs,
- /*PartialTemplateArgs=*/false, SugaredConverted, CanonicalConverted))
+ SmallVector<TemplateArgument, 4> Converted;
+ if (SemaRef.CheckTemplateArgumentList(ClassTemplate,
+ PartialSpec->getLocation(),
+ InstTemplateArgs,
+ false,
+ Converted))
return nullptr;
// Check these arguments are valid for a template partial specialization.
if (SemaRef.CheckTemplatePartialSpecializationArgs(
PartialSpec->getLocation(), ClassTemplate, InstTemplateArgs.size(),
- CanonicalConverted))
+ Converted))
return nullptr;
// Figure out where to insert this class template partial specialization
// in the member template's set of class template partial specializations.
void *InsertPos = nullptr;
- ClassTemplateSpecializationDecl *PrevDecl =
- ClassTemplate->findPartialSpecialization(CanonicalConverted, InstParams,
+ ClassTemplateSpecializationDecl *PrevDecl
+ = ClassTemplate->findPartialSpecialization(Converted, InstParams,
InsertPos);
// Build the canonical type that describes the converted template
// arguments of the class template partial specialization.
- QualType CanonType = SemaRef.Context.getTemplateSpecializationType(
- TemplateName(ClassTemplate), CanonicalConverted);
+ QualType CanonType
+ = SemaRef.Context.getTemplateSpecializationType(TemplateName(ClassTemplate),
+ Converted);
// Build the fully-sugared type for this class template
// specialization as the user wrote in the specialization
@@ -4208,8 +4212,7 @@ TemplateDeclInstantiator::InstantiateClassTemplatePartialSpecialization(
ClassTemplatePartialSpecializationDecl::Create(
SemaRef.Context, PartialSpec->getTagKind(), Owner,
PartialSpec->getBeginLoc(), PartialSpec->getLocation(), InstParams,
- ClassTemplate, CanonicalConverted, InstTemplateArgs, CanonType,
- nullptr);
+ ClassTemplate, Converted, InstTemplateArgs, CanonType, nullptr);
// Substitute the nested name specifier, if any.
if (SubstQualifier(PartialSpec, InstPartialSpec))
return nullptr;
@@ -4266,29 +4269,27 @@ TemplateDeclInstantiator::InstantiateVarTemplatePartialSpecialization(
// Check that the template argument list is well-formed for this
// class template.
- SmallVector<TemplateArgument, 4> SugaredConverted, CanonicalConverted;
- if (SemaRef.CheckTemplateArgumentList(
- VarTemplate, PartialSpec->getLocation(), InstTemplateArgs,
- /*PartialTemplateArgs=*/false, SugaredConverted, CanonicalConverted))
+ SmallVector<TemplateArgument, 4> Converted;
+ if (SemaRef.CheckTemplateArgumentList(VarTemplate, PartialSpec->getLocation(),
+ InstTemplateArgs, false, Converted))
return nullptr;
// Check these arguments are valid for a template partial specialization.
if (SemaRef.CheckTemplatePartialSpecializationArgs(
PartialSpec->getLocation(), VarTemplate, InstTemplateArgs.size(),
- CanonicalConverted))
+ Converted))
return nullptr;
// Figure out where to insert this variable template partial specialization
// in the member template's set of variable template partial specializations.
void *InsertPos = nullptr;
VarTemplateSpecializationDecl *PrevDecl =
- VarTemplate->findPartialSpecialization(CanonicalConverted, InstParams,
- InsertPos);
+ VarTemplate->findPartialSpecialization(Converted, InstParams, InsertPos);
// Build the canonical type that describes the converted template
// arguments of the variable template partial specialization.
QualType CanonType = SemaRef.Context.getTemplateSpecializationType(
- TemplateName(VarTemplate), CanonicalConverted);
+ TemplateName(VarTemplate), Converted);
// Build the fully-sugared type for this variable template
// specialization as the user wrote in the specialization
@@ -4344,8 +4345,7 @@ TemplateDeclInstantiator::InstantiateVarTemplatePartialSpecialization(
VarTemplatePartialSpecializationDecl::Create(
SemaRef.Context, Owner, PartialSpec->getInnerLocStart(),
PartialSpec->getLocation(), InstParams, VarTemplate, DI->getType(),
- DI, PartialSpec->getStorageClass(), CanonicalConverted,
- InstTemplateArgs);
+ DI, PartialSpec->getStorageClass(), Converted, InstTemplateArgs);
// Substitute the nested name specifier, if any.
if (SubstQualifier(PartialSpec, InstPartialSpec))
diff --git a/clang/test/SemaCXX/ppc-pair-mma-types.cpp b/clang/test/SemaCXX/ppc-pair-mma-types.cpp
index 933990fa80ba6..085db9abd1def 100644
--- a/clang/test/SemaCXX/ppc-pair-mma-types.cpp
+++ b/clang/test/SemaCXX/ppc-pair-mma-types.cpp
@@ -85,8 +85,8 @@ class TestClassVQ {
// template argument
template <typename T = __vector_quad>
- void testVQTemplate(T v, T *p) { // expected-note {{candidate template ignored: substitution failure [with T = vq_t]: invalid use of PPC MMA type}} \
- expected-note {{candidate template ignored: substitution failure [with T = __vector_quad]: invalid use of PPC MMA type}}
+ void testVQTemplate(T v, T *p) { // expected-note {{candidate template ignored: substitution failure [with T = __vector_quad]: invalid use of PPC MMA type}} \
+ expected-note {{candidate template ignored: substitution failure [with T = __vector_quad]: invalid use of PPC MMA type}}
*(p + 1) = v;
}
@@ -276,8 +276,8 @@ class TestClassVP {
// template argument
template <typename T = __vector_pair>
- void testVPTemplate(T v, T *p) { // expected-note {{candidate template ignored: substitution failure [with T = vp_t]: invalid use of PPC MMA type}} \
- expected-note {{candidate template ignored: substitution failure [with T = __vector_pair]: invalid use of PPC MMA type}}
+ void testVPTemplate(T v, T *p) { // expected-note {{candidate template ignored: substitution failure [with T = __vector_pair]: invalid use of PPC MMA type}} \
+ expected-note {{candidate template ignored: substitution failure [with T = __vector_pair]: invalid use of PPC MMA type}}
*(p + 1) = v;
}
diff --git a/clang/test/SemaTemplate/deduction.cpp b/clang/test/SemaTemplate/deduction.cpp
index 7a45d1a425728..c865c1a2962c3 100644
--- a/clang/test/SemaTemplate/deduction.cpp
+++ b/clang/test/SemaTemplate/deduction.cpp
@@ -1,6 +1,5 @@
// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11
// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++1z
-// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++2b
// Template argument deduction with template template parameters.
template<typename T, template<T> class A>
@@ -662,25 +661,3 @@ namespace PR49724 {
template<void (A::*P)()> void f(Y<P>);
void g(Y<nullptr> y) { f(y); }
}
-
-namespace sugared_deduction {
-using Int = int;
-
-template <class T, int C> void f1(T(&)[C], T(&)[C+1]);
-// expected-note at -1 {{candidate template ignored: deduced type 'int[3]' of 2nd parameter does not match adjusted type 'Int[2]' (aka 'int[2]') of argument [with T = Int, C = 2]}}
-
-void t1() {
- Int a[2], b[2];
- f1(a, b); // expected-error {{no matching function for call to 'f1'}}
-}
-
-#if defined(__cpp_concepts)
-template <class T> void f2() requires false {}
-// expected-note at -1 {{candidate template ignored: constraints not satisfied [with T = Int]}}
-// expected-note at -2 {{because 'false' evaluated to false}}
-
-void t2() {
- f2<Int>(); // expected-error {{no matching function for call to 'f2'}}
-}
-#endif
-} // namespace sugared_deduction
More information about the cfe-commits
mailing list