r290933 - Fix deduction of pack elements after a braced-init-list.
Richard Smith via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 3 18:59:16 PST 2017
Author: rsmith
Date: Tue Jan 3 20:59:16 2017
New Revision: 290933
URL: http://llvm.org/viewvc/llvm-project?rev=290933&view=rev
Log:
Fix deduction of pack elements after a braced-init-list.
Previously, if the arguments for a parameter pack contained a braced-init-list,
we would abort deduction (keeping the pack deductions from prior arguments) at
the point when we reached the braced-init-list, resulting in wrong deductions
and rejects-valids. We now just leave a "hole" in the pack for such an argument,
which needs to be filled by another deduction of the same pack.
Modified:
cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
cfe/trunk/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp
Modified: cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp?rev=290933&r1=290932&r2=290933&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp Tue Jan 3 20:59:16 2017
@@ -3468,12 +3468,8 @@ Sema::TemplateDeductionResult Sema::Dedu
if (InitListExpr *ILE = dyn_cast<InitListExpr>(Arg)) {
TemplateDeductionResult Result;
if (!DeduceFromInitializerList(*this, TemplateParams, ParamType, ILE,
- Info, Deduced, TDF, Result)) {
- // FIXME: Bailing out here is wrong; we could still need to deduce
- // from later pack elements.
- ++ArgIdx;
- break;
- }
+ Info, Deduced, TDF, Result))
+ continue;
if (Result)
return Result;
Modified: cfe/trunk/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp?rev=290933&r1=290932&r2=290933&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp (original)
+++ cfe/trunk/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp Tue Jan 3 20:59:16 2017
@@ -103,6 +103,12 @@ T deduce(std::initializer_list<T>); // e
template <typename T>
T deduce_ref(const std::initializer_list<T>&); // expected-note {{conflicting types for parameter 'T' ('int' vs. 'double')}}
+template<typename T, typename U> struct pair { pair(...); };
+template<typename T> void deduce_pairs(std::initializer_list<pair<T, typename T::type>>);
+struct WithIntType { typedef int type; };
+
+template<typename ...T> void deduce_after_init_list_in_pack(void (*)(T...), T...); // expected-note {{<int, int> vs. <(no value), double>}}
+
void argument_deduction() {
static_assert(same_type<decltype(deduce({1, 2, 3})), int>::value, "bad deduction");
static_assert(same_type<decltype(deduce({1.0, 2.0, 3.0})), double>::value, "bad deduction");
@@ -113,6 +119,14 @@ void argument_deduction() {
static_assert(same_type<decltype(deduce_ref({1.0, 2.0, 3.0})), double>::value, "bad deduction");
deduce_ref({1, 2.0}); // expected-error {{no matching function}}
+
+ pair<WithIntType, int> pi;
+ pair<WithIntType, float> pf;
+ deduce_pairs({pi, pi, pi}); // ok
+ deduce_pairs({pi, pf, pi}); // FIXME: This should be rejected, as we fail to produce a type that exactly matches the argument type.
+
+ deduce_after_init_list_in_pack((void(*)(int,int))0, {}, 0);
+ deduce_after_init_list_in_pack((void(*)(int,int))0, {}, 0.0); // expected-error {{no matching function}}
}
void auto_deduction() {
More information about the cfe-commits
mailing list