c++: braced-list overload resolution [PR100963]
authorJason Merrill <jason@redhat.com>
Tue, 8 Jun 2021 13:19:58 +0000 (09:19 -0400)
committerJason Merrill <jason@redhat.com>
Tue, 8 Jun 2021 17:28:02 +0000 (13:28 -0400)
My PR969626 patch made us ignore template candidates when there's a perfect
non-template candidate.  In this case, we were considering B(int) a perfect
match for B({0}), but the brace elision makes it imperfect.

PR c++/100963

gcc/cp/ChangeLog:

* call.c (perfect_conversion_p): Check check_narrowing.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/initlist124.C: New test.

gcc/cp/call.c
gcc/testsuite/g++.dg/cpp0x/initlist124.C [new file with mode: 0644]

index 17fc60c..d2f6ca8 100644 (file)
@@ -5880,6 +5880,9 @@ perfect_conversion_p (conversion *conv)
                        next_conversion (conv)->type))
        return false;
     }
+  if (conv->check_narrowing)
+    /* Brace elision is imperfect.  */
+    return false;
   return true;
 }
 
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist124.C b/gcc/testsuite/g++.dg/cpp0x/initlist124.C
new file mode 100644 (file)
index 0000000..45dcbb3
--- /dev/null
@@ -0,0 +1,13 @@
+// PR c++/100963
+// { dg-do compile { target c++11 } }
+
+#include <initializer_list>
+
+struct B {
+  B(int) = delete;
+  template<class T> B(std::initializer_list<T>);
+};
+
+int main() {
+  B({0});
+}