From 0738ab99fd30ec6658d5550a2d50409247a73090 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Thu, 5 Jan 2017 04:16:30 +0000 Subject: [PATCH] Per [temp.deduct.call], do not deduce an array bound of 0 from an empty initializer list. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@291075 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaTemplateDeduction.cpp | 4 +++- test/SemaTemplate/deduction.cpp | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/Sema/SemaTemplateDeduction.cpp b/lib/Sema/SemaTemplateDeduction.cpp index 35f2de1682..6c90b5c226 100644 --- a/lib/Sema/SemaTemplateDeduction.cpp +++ b/lib/Sema/SemaTemplateDeduction.cpp @@ -3219,6 +3219,9 @@ static Sema::TemplateDeductionResult DeduceFromInitializerList( // parameter type and the initializer element as its argument // // We've already removed references and cv-qualifiers here. + if (!ILE->getNumInits()) + return Sema::TDK_Success; + QualType ElTy; auto *ArrTy = S.Context.getAsArrayType(AdjustedParamType); if (ArrTy) @@ -3241,7 +3244,6 @@ static Sema::TemplateDeductionResult DeduceFromInitializerList( // in the P0[N] case, if N is a non-type template parameter, N is deduced // from the length of the initializer list. - // FIXME: We're not supposed to get here if N would be deduced as 0. if (auto *DependentArrTy = dyn_cast_or_null(ArrTy)) { // Determine the array bound is something we can deduce. if (NonTypeTemplateParmDecl *NTTP = diff --git a/test/SemaTemplate/deduction.cpp b/test/SemaTemplate/deduction.cpp index f98fd9bea0..940f6018f2 100644 --- a/test/SemaTemplate/deduction.cpp +++ b/test/SemaTemplate/deduction.cpp @@ -414,3 +414,17 @@ namespace b29946541 { void f(C); // expected-note {{failed template argument deduction}} void g(A a) { f(a); } // expected-error {{no match}} } + +namespace deduction_from_empty_list { + template void f(int (&&)[N], int (&&)[N]) { // expected-note {{1 vs. 2}} + static_assert(M == N, ""); + } + + void test() { + f<5>({}, {}); + f<1>({}, {0}); + f<1>({0}, {}); + f<1>({0}, {0}); + f<1>({0}, {0, 1}); // expected-error {{no matching}} + } +} -- 2.40.0