r291170 - If an explicitly-specified pack might have been extended by template argument
Richard Smith via cfe-commits
cfe-commits at lists.llvm.org
Thu Jan 5 12:27:28 PST 2017
Author: rsmith
Date: Thu Jan 5 14:27:28 2017
New Revision: 291170
URL: http://llvm.org/viewvc/llvm-project?rev=291170&view=rev
Log:
If an explicitly-specified pack might have been extended by template argument
deduction, don't forget to check the argument is valid.
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=291170&r1=291169&r2=291170&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp Thu Jan 5 14:27:28 2017
@@ -2215,25 +2215,26 @@ static Sema::TemplateDeductionResult Con
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)) {
Modified: cfe/trunk/test/SemaTemplate/deduction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/deduction.cpp?rev=291170&r1=291169&r2=291170&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/deduction.cpp (original)
+++ cfe/trunk/test/SemaTemplate/deduction.cpp Thu Jan 5 14:27:28 2017
@@ -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}}
+}
More information about the cfe-commits
mailing list