r291075 - Per [temp.deduct.call], do not deduce an array bound of 0 from an empty initializer list.
Richard Smith via cfe-commits
cfe-commits at lists.llvm.org
Wed Jan 4 20:16:30 PST 2017
Author: rsmith
Date: Wed Jan 4 22:16:30 2017
New Revision: 291075
URL: http://llvm.org/viewvc/llvm-project?rev=291075&view=rev
Log:
Per [temp.deduct.call], do not deduce an array bound of 0 from an empty initializer list.
Modified:
cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
cfe/trunk/test/SemaTemplate/deduction.cpp
Modified: cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp?rev=291075&r1=291074&r2=291075&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp Wed Jan 4 22:16:30 2017
@@ -3219,6 +3219,9 @@ static Sema::TemplateDeductionResult Ded
// 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 Ded
// 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<DependentSizedArrayType>(ArrTy)) {
// Determine the array bound is something we can deduce.
if (NonTypeTemplateParmDecl *NTTP =
Modified: cfe/trunk/test/SemaTemplate/deduction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/deduction.cpp?rev=291075&r1=291074&r2=291075&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/deduction.cpp (original)
+++ cfe/trunk/test/SemaTemplate/deduction.cpp Wed Jan 4 22:16:30 2017
@@ -414,3 +414,17 @@ namespace b29946541 {
void f(C<T, U>); // expected-note {{failed template argument deduction}}
void g(A<int> a) { f(a); } // expected-error {{no match}}
}
+
+namespace deduction_from_empty_list {
+ template<int M, int N = 5> 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}}
+ }
+}
More information about the cfe-commits
mailing list