llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: None (keinflue) <details> <summary>Changes</summary> 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. The affected function is used only to provide an improved early error if the partial specialization has identical template arguments to the primary template. The actual check that the partial specialization is more specialized happens later. Fixes #<!-- -->118190 Fixes #<!-- -->152750 --- Full diff: https://github.com/llvm/llvm-project/pull/152864.diff 2 Files Affected: - (modified) clang/lib/Sema/SemaTemplate.cpp (+5-1) - (modified) clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp (+5) ``````````diff diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index 2d8fdb5b766fc..ae16323535bdc 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -4126,7 +4126,11 @@ static bool isTemplateArgumentTemplateParameter(const TemplateArgument &Arg, return false; const NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(DRE->getDecl()); - return NTTP && NTTP->getDepth() == Depth && NTTP->getIndex() == Index; + if (!NTTP || NTTP->getDepth() != Depth || NTTP->getIndex() != Index) + return false; + QualType ParamType = cast<NonTypeTemplateParmDecl>(Param)->getType(); + QualType NTTPType = NTTP->getType(); + return ParamType.getCanonicalType() == NTTPType.getCanonicalType(); } case TemplateArgument::Template: diff --git a/clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp b/clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp index c35743b87adbc..9c25e26f43c36 100644 --- a/clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp +++ b/clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp @@ -621,3 +621,8 @@ namespace GH73460 { int j; template struct A<int&, j, j>; } // namespace GH73460 + +namespace GH118190 { + template <auto> int x; + template <int i> int x<i>; +} `````````` </details> https://github.com/llvm/llvm-project/pull/152864 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits