c++: Fix constrained conversion op.
authorJason Merrill <jason@redhat.com>
Fri, 28 Feb 2020 18:43:55 +0000 (13:43 -0500)
committerJason Merrill <jason@redhat.com>
Fri, 28 Feb 2020 18:44:44 +0000 (13:44 -0500)
We don't want to promote a conversion from viable == 0 to viable == -1.
Found in ranges-v3.

gcc/cp/ChangeLog
2020-02-28  Jason Merrill  <jason@redhat.com>

* call.c (build_user_type_conversion_1): Don't look at the second
conversion of a non-viable candidate.

gcc/cp/ChangeLog
gcc/cp/call.c
gcc/testsuite/g++.dg/cpp2a/concepts-conv1.C [new file with mode: 0644]

index 4dc30e0a321b0348c50c7fc0c4bc8d38b8e1ca6f..8a8de3237cd8c077dbc93189f65d99635bdb92a0 100644 (file)
@@ -1,3 +1,8 @@
+2020-02-28  Jason Merrill  <jason@redhat.com>
+
+       * call.c (build_user_type_conversion_1): Don't look at the second
+       conversion of a non-viable candidate.
+
 2020-02-28  Jakub Jelinek  <jakub@redhat.com>
 
        P1937R2 - Fixing inconsistencies between const{expr,eval} functions
index e07ee85c06ee26ebc472f80c7a9de7d7e83d3384..85bbd043a1df3429396a21fd89ce52cf7fffc4ef 100644 (file)
@@ -4083,6 +4083,10 @@ build_user_type_conversion_1 (tree totype, tree expr, int flags,
 
       for (cand = candidates; cand != old_candidates; cand = cand->next)
        {
+         if (cand->viable == 0)
+           /* Already rejected, don't change to -1.  */
+           continue;
+
          tree rettype = TREE_TYPE (TREE_TYPE (cand->fn));
          conversion *ics
            = implicit_conversion (totype,
diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-conv1.C b/gcc/testsuite/g++.dg/cpp2a/concepts-conv1.C
new file mode 100644 (file)
index 0000000..aa29acb
--- /dev/null
@@ -0,0 +1,15 @@
+// { dg-do compile { target concepts } }
+
+template <class T> concept False = false;
+
+template <class T>
+struct A
+{
+  explicit operator bool ();
+  explicit operator bool () requires False<T>;
+};
+
+int main()
+{
+  int i { A<int>() };          // { dg-error "" }
+}