From 9771f500f29235d79276c30d784859572aefc764 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Mon, 24 Jun 2019 05:53:11 +0000 Subject: [PATCH] PR42362: Fix auto deduction of template parameter packs from type-dependent argument packs. We need to strip off the PackExpansionExpr to get the real (dependent) type rather than an opaque DependentTy. llvm-svn: 364165 --- clang/lib/Sema/SemaTemplate.cpp | 5 ++++- .../test/SemaTemplate/temp_arg_nontype_cxx1z.cpp | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index 7b0a3a3e094c..49ba771379e1 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -6323,9 +6323,12 @@ ExprResult Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param, // the type is dependent, in order to check the types of non-type template // arguments line up properly in partial ordering. Optional Depth = Param->getDepth() + 1; + Expr *DeductionArg = Arg; + if (auto *PE = dyn_cast(DeductionArg)) + DeductionArg = PE->getPattern(); if (DeduceAutoType( Context.getTrivialTypeSourceInfo(ParamType, Param->getLocation()), - Arg, ParamType, Depth) == DAR_Failed) { + DeductionArg, ParamType, Depth) == DAR_Failed) { Diag(Arg->getExprLoc(), diag::err_non_type_template_parm_type_deduction_failure) << Param->getDeclName() << Param->getType() << Arg->getType() diff --git a/clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp b/clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp index b887c7f47d3c..d73a88777d0c 100644 --- a/clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp +++ b/clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp @@ -378,3 +378,18 @@ template struct M { } }; } + +namespace PR42362 { + template struct X { struct Y; void f(int...[A]); }; + template struct X::Y {}; + template void X::f(int...[A]) {} + void f() { X<1, 2>::Y y; X<1, 2>().f(0, 0); } + + template struct Y; + template struct Y {}; + Y y; + + template struct Z { struct Q; }; + template struct Z::Q {}; + Z::Q q; +}