This conversion is ambiguous because of its implicit context; when we
try to give the error, we need to preserve that context; a conversion
in the context of direct-initialization shouldn't get here anyway.

Tested x86_64-pc-linux-gnu, applying to trunk.
commit d7be189d5b2761f10f9c9a8de4c17d3e4d761abf
Author: Jason Merrill <ja...@redhat.com>
Date:   Tue Mar 21 12:26:51 2017 -0400

            PR c++/77563 - missing ambiguous conversion error.
    
            * call.c (convert_like_real): Use LOOKUP_IMPLICIT.

diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 86c7647..803fbd4 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -6764,7 +6764,7 @@ convert_like_real (conversion *convs, tree expr, tree fn, 
int argnum,
       if (complain & tf_error)
        {
          /* Call build_user_type_conversion again for the error.  */
-         build_user_type_conversion (totype, convs->u.expr, LOOKUP_NORMAL,
+         build_user_type_conversion (totype, convs->u.expr, LOOKUP_IMPLICIT,
                                      complain);
          if (fn)
            inform (DECL_SOURCE_LOCATION (fn),
diff --git a/gcc/testsuite/g++.dg/overload/ambig3.C 
b/gcc/testsuite/g++.dg/overload/ambig3.C
new file mode 100644
index 0000000..01d4cc6
--- /dev/null
+++ b/gcc/testsuite/g++.dg/overload/ambig3.C
@@ -0,0 +1,15 @@
+// PR c++/77563
+
+struct A {
+  A(int) {}
+  A(unsigned) {}  // Comment to make it work
+
+  explicit A(long) {}  // Comment to make it work
+};
+
+void f(A) { }
+
+int main() {
+  f(2);
+  f(3l);                       // { dg-error "ambiguous" }
+}

Reply via email to