My fix for add_template_conv_candidate, implementing my suggestion for core 2189, broke calls to a function object that inherits from a generic lambda. The committee hasn't had a chance to consider this issue yet, but for now let's disable the template conversion candidate when there's a viable operator() candidate.
Tested x86_64-pc-linux-gnu, applying to trunk.
commit b56248900900e3a9f85670d3cf0bf4acdfae34f4 Author: Jason Merrill <ja...@redhat.com> Date: Thu Jul 14 16:32:27 2016 -0400 PR c++/71117 - core 2189 and generic lambda * call.c (add_template_conv_candidate): Disable if there are viable candidates. diff --git a/gcc/cp/call.c b/gcc/cp/call.c index a3c5008..889852f 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -3204,6 +3204,12 @@ add_template_conv_candidate (struct z_candidate **candidates, tree tmpl, tree return_type, tree access_path, tree conversion_path, tsubst_flags_t complain) { + /* Making this work broke PR 71117, so until the committee resolves core + issue 2189, let's disable this candidate if there are any viable call + operators. */ + if (any_strictly_viable (*candidates)) + return NULL; + return add_template_candidate_real (candidates, tmpl, NULL_TREE, NULL_TREE, NULL_TREE, arglist, return_type, access_path, diff --git a/gcc/testsuite/g++.dg/cpp0x/conv-tmpl1.C b/gcc/testsuite/g++.dg/cpp0x/conv-tmpl1.C index 7f866da..eb40dd6 100644 --- a/gcc/testsuite/g++.dg/cpp0x/conv-tmpl1.C +++ b/gcc/testsuite/g++.dg/cpp0x/conv-tmpl1.C @@ -1,3 +1,4 @@ +// Test for Core 2189. // { dg-do compile { target c++11 } } template <class T> diff --git a/gcc/testsuite/g++.dg/cpp1y/lambda-generic-conv2.C b/gcc/testsuite/g++.dg/cpp1y/lambda-generic-conv2.C new file mode 100644 index 0000000..5528455 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/lambda-generic-conv2.C @@ -0,0 +1,26 @@ +// PR c++/71117 +// { dg-do compile { target c++14 } } + +template <class T> T&& declval() noexcept; +template <class, class> +constexpr bool is_same = false; +template <class T> +constexpr bool is_same<T, T> = true; + +template <class F> +struct indirected : F { + indirected(F f) : F(f) {} + template <class I> + auto operator()(I i) -> decltype(declval<F&>()(*i)) { + return static_cast<F&>(*this)(*i); + } +}; + +int main() { + auto f = [](auto rng) { + static_assert(is_same<decltype(rng), int>, ""); + return 42; + }; + indirected<decltype(f)> i(f); + static_assert(is_same<decltype(i(declval<int*>())), int>, ""); +}