Skip to content

Commit 07c9546

Browse files
committed
Relocate new check into caller to not mess up interpretation of callee.
Also remove unused and potentially confusing paramter from isTemplateArgumentTemplateParamter.
1 parent f36c8db commit 07c9546

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

clang/lib/Sema/SemaTemplate.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4099,7 +4099,6 @@ static bool CheckTemplateSpecializationScope(Sema &S, NamedDecl *Specialized,
40994099
static TemplateSpecializationKind getTemplateSpecializationKind(Decl *D);
41004100

41014101
static bool isTemplateArgumentTemplateParameter(const TemplateArgument &Arg,
4102-
NamedDecl *Param,
41034102
unsigned Depth,
41044103
unsigned Index) {
41054104
switch (Arg.getKind()) {
@@ -4126,11 +4125,7 @@ static bool isTemplateArgumentTemplateParameter(const TemplateArgument &Arg,
41264125
return false;
41274126
const NonTypeTemplateParmDecl *NTTP =
41284127
dyn_cast<NonTypeTemplateParmDecl>(DRE->getDecl());
4129-
if (!NTTP || NTTP->getDepth() != Depth || NTTP->getIndex() != Index)
4130-
return false;
4131-
QualType ParamType = cast<NonTypeTemplateParmDecl>(Param)->getType();
4132-
QualType NTTPType = NTTP->getType();
4133-
return ParamType.getCanonicalType() == NTTPType.getCanonicalType();
4128+
return NTTP && NTTP->getDepth() == Depth && NTTP->getIndex() == Index;
41344129
}
41354130

41364131
case TemplateArgument::Template:
@@ -4143,8 +4138,9 @@ static bool isTemplateArgumentTemplateParameter(const TemplateArgument &Arg,
41434138
}
41444139

41454140
static bool isSameAsPrimaryTemplate(TemplateParameterList *Params,
4141+
TemplateParameterList *SpecParams,
41464142
ArrayRef<TemplateArgument> Args) {
4147-
if (Params->size() != Args.size())
4143+
if (Params->size() != Args.size() || Params->size() != SpecParams->size())
41484144
return false;
41494145

41504146
unsigned Depth = Params->getDepth();
@@ -4161,9 +4157,19 @@ static bool isSameAsPrimaryTemplate(TemplateParameterList *Params,
41614157
Arg = Arg.pack_begin()->getPackExpansionPattern();
41624158
}
41634159

4164-
if (!isTemplateArgumentTemplateParameter(Arg, Params->getParam(I), Depth,
4165-
I))
4160+
if (!isTemplateArgumentTemplateParameter(Arg, Depth, I))
41664161
return false;
4162+
4163+
// For NTTPs further specialization is allowed via deduced types, so
4164+
// we need to make sure to only reject here if primary template and
4165+
// specialization use the same type for the NTTP.
4166+
if (auto *SpecNTTP =
4167+
dyn_cast<NonTypeTemplateParmDecl>(SpecParams->getParam(I))) {
4168+
auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Params->getParam(I));
4169+
if (!NTTP || NTTP->getType().getCanonicalType() !=
4170+
SpecNTTP->getType().getCanonicalType())
4171+
return false;
4172+
}
41674173
}
41684174

41694175
return true;
@@ -4361,7 +4367,7 @@ DeclResult Sema::ActOnVarTemplateSpecialization(
43614367
}
43624368

43634369
if (isSameAsPrimaryTemplate(VarTemplate->getTemplateParameters(),
4364-
CTAI.CanonicalConverted) &&
4370+
TemplateParams, CTAI.CanonicalConverted) &&
43654371
(!Context.getLangOpts().CPlusPlus20 ||
43664372
!TemplateParams->hasAssociatedConstraints())) {
43674373
// C++ [temp.class.spec]p9b3:

0 commit comments

Comments
 (0)