This is an archive of the discontinued LLVM Phabricator instance.

Consolidate and unify initializer list deduction
ClosedPublic

Authored by hubert.reinterpretcast on Jun 23 2015, 7:38 PM.

Details

Summary

This patch reduces duplication in the template argument deduction code
for handling deduction from initializer lists in a function call. This
extends the fix for PR12119 to also apply to the case where the
corresponding parameter is a trailing parameter pack.

Diff Detail

Event Timeline

hubert.reinterpretcast retitled this revision from to Consolidate and unify initializer list deduction.
hubert.reinterpretcast updated this object.
hubert.reinterpretcast edited the test plan for this revision. (Show Details)
hubert.reinterpretcast added a subscriber: Unknown Object (MLST).
rsmith added inline comments.Jun 24 2015, 12:25 PM
lib/Sema/SemaTemplateDeduction.cpp
3201

Maybe just make this return the TemplateDeductionResult? You -- almost, see below -- always treat a return of false from here and a return of true with Result == TDK_Success the same (which makes sense, because they mean the same thing -- deduction succeeded).

3432–3433

Is this really right? It seems to cause an accepts-invalid on this:

#include <initializer_list>
#include <tuple>
template<typename ...T> void f(std::tuple<T...> a, T ...b);
void g() { f(std::make_tuple(1, 2), {}, 3.0); }

Should this instead be ignoring this P/A pair and carrying on to the next, as we do if deduction succeeds? (This is a pre-existing bug, but it's the only barrier to the cleanup I suggested above.)

The additional bug appears to affect more than just the part being changed here. I think it would make sense to leave that change for a separate commit (and get the clean up done there).

lib/Sema/SemaTemplateDeduction.cpp
3432–3433

This seems to be a larger issue having to do with undeduced contexts and trailing parameter packs.

#include <initializer_list>
#include <tuple>
void f();
void f(bool);

typedef void (*fptype)();
struct Func { operator fptype(); } func;

template<typename ...T> void f(std::tuple<T...> a, T ...b);
void g() { f(std::make_tuple(fptype(), fptype()), f, func); } // Clang and GCC accept
void g1() { f(std::make_tuple(fptype(), fptype()), func, f); } // GCC accepts, Clang rejects
rsmith accepted this revision.Jun 24 2015, 3:19 PM
rsmith edited edge metadata.

OK, separating the two fixes sounds fine to me.

This revision is now accepted and ready to land.Jun 24 2015, 3:19 PM