PR c++/71117 - core 2189 and generic lambda
authorJason Merrill <jason@redhat.com>
Fri, 15 Jul 2016 18:49:25 +0000 (14:49 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Fri, 15 Jul 2016 18:49:25 +0000 (14:49 -0400)
* call.c (add_template_conv_candidate): Disable if there are
viable candidates.

From-SVN: r238394

gcc/cp/ChangeLog
gcc/cp/call.c
gcc/testsuite/g++.dg/cpp0x/conv-tmpl1.C
gcc/testsuite/g++.dg/cpp1y/lambda-generic-conv2.C [new file with mode: 0644]

index 0178f108f6c7e7783bfc1120766287658bf6c695..eb96ea3f8db22ea6bc1f09bf6379a36885c6b5e1 100644 (file)
@@ -1,5 +1,10 @@
 2016-07-15  Jason Merrill  <jason@redhat.com>
 
+       PR c++/71117
+       Core 2189
+       * call.c (add_template_conv_candidate): Disable if there are
+       viable candidates.
+
        PR c++/71511
        * typeck2.c (cxx_incomplete_type_diagnostic): Handle DECLTYPE_TYPE.
 
index 9b028144aaa6f27faff66e086a47fdbf26271476..6ae5df76b1caa01a9943d62079165848ee95c216 100644 (file)
@@ -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,
index 7f866daf4eaa139458ecefebf52959d359bcc1e4..eb40dd66a5c5a59e2bfaad01d8cceeb32bd65f95 100644 (file)
@@ -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 (file)
index 0000000..5528455
--- /dev/null
@@ -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>, "");
+}