Skip to content

Commit f36c8db

Browse files
committed
[clang] Distinguish NTTPs with deduced types in variable template partial specializations
If a template argument in a partial specialization of a variable template directly refers to a NTTP of the specialization without implicit type conversion it was assumed that the NTTP is identical to that of the primary template. This doesn't hold if the primary template's NTTP uses a deduced type, so instead compare the types explicitly as well. Fixes #118190 Fixes #152750
1 parent 0c13988 commit f36c8db

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

clang/lib/Sema/SemaTemplate.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4126,7 +4126,11 @@ static bool isTemplateArgumentTemplateParameter(const TemplateArgument &Arg,
41264126
return false;
41274127
const NonTypeTemplateParmDecl *NTTP =
41284128
dyn_cast<NonTypeTemplateParmDecl>(DRE->getDecl());
4129-
return NTTP && NTTP->getDepth() == Depth && NTTP->getIndex() == Index;
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();
41304134
}
41314135

41324136
case TemplateArgument::Template:

clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,3 +621,8 @@ namespace GH73460 {
621621
int j;
622622
template struct A<int&, j, j>;
623623
} // namespace GH73460
624+
625+
namespace GH118190 {
626+
template <auto> int x;
627+
template <int i> int x<i>;
628+
}

0 commit comments

Comments
 (0)