forked from OSchip/llvm-project
Per [temp.deduct.call], do not deduce an array bound of 0 from an empty initializer list.
llvm-svn: 291075
This commit is contained in:
parent
707eab6655
commit
9c5534ceb1
|
@ -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<DependentSizedArrayType>(ArrTy)) {
|
||||
// Determine the array bound is something we can deduce.
|
||||
if (NonTypeTemplateParmDecl *NTTP =
|
||||
|
|
|
@ -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}}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue