If an explicitly-specified pack might have been extended by template argument

deduction, don't forget to check the argument is valid.

llvm-svn: 291170
This commit is contained in:
Richard Smith 2017-01-05 20:27:28 +00:00
parent 1172332203
commit 9c0c98604a
2 changed files with 28 additions and 13 deletions

View File

@ -2215,25 +2215,26 @@ static Sema::TemplateDeductionResult ConvertDeducedTemplateArguments(
if (!Deduced[I].isNull()) {
if (I < NumAlreadyConverted) {
// We have already fully type-checked and converted this
// argument, because it was explicitly-specified. Just record the
// presence of this argument.
Builder.push_back(Deduced[I]);
// We may have had explicitly-specified template arguments for a
// template parameter pack (that may or may not have been extended
// via additional deduced arguments).
if (Param->isParameterPack() && CurrentInstantiationScope) {
if (CurrentInstantiationScope->getPartiallySubstitutedPack() ==
Param) {
// Forget the partially-substituted pack; its substitution is now
// complete.
CurrentInstantiationScope->ResetPartiallySubstitutedPack();
}
if (Param->isParameterPack() && CurrentInstantiationScope &&
CurrentInstantiationScope->getPartiallySubstitutedPack() == Param) {
// Forget the partially-substituted pack; its substitution is now
// complete.
CurrentInstantiationScope->ResetPartiallySubstitutedPack();
// We still need to check the argument in case it was extended by
// deduction.
} else {
// We have already fully type-checked and converted this
// argument, because it was explicitly-specified. Just record the
// presence of this argument.
Builder.push_back(Deduced[I]);
continue;
}
continue;
}
// We have deduced this argument, so it still needs to be
// We may have deduced this argument, so it still needs to be
// checked and converted.
if (ConvertDeducedTemplateArgument(S, Param, Deduced[I], Template, Info,
IsDeduced, Builder)) {

View File

@ -428,3 +428,17 @@ namespace deduction_from_empty_list {
f<1>({0}, {0, 1}); // expected-error {{no matching}}
}
}
namespace check_extended_pack {
template<typename T> struct X { typedef int type; };
template<typename ...T> void f(typename X<T>::type...);
template<typename T> void f(T, int, int);
void g() {
f<int>(0, 0, 0);
}
template<int, int*> struct Y {};
template<int ...N> void g(Y<N...>); // expected-note {{deduced non-type template argument does not have the same type as the corresponding template parameter ('int *' vs 'int')}}
int n;
void h() { g<0>(Y<0, &n>()); } // expected-error {{no matching function}}
}