[gcc(refs/vendors/ibm/heads/perf)] c++: Fix constrained conversion op.

Jiu Fu Guo guojiufu@gcc.gnu.org
Thu Mar 19 05:58:39 GMT 2020


https://gcc.gnu.org/g:586b016cd48f5a5f6f2ba9f179105fabaa3e85dd

commit 586b016cd48f5a5f6f2ba9f179105fabaa3e85dd
Author: Jason Merrill <jason@redhat.com>
Date:   Fri Feb 28 13:43:55 2020 -0500

    c++: Fix constrained conversion op.
    
    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.

Diff:
---
 gcc/cp/ChangeLog                            |  5 +++++
 gcc/cp/call.c                               |  4 ++++
 gcc/testsuite/g++.dg/cpp2a/concepts-conv1.C | 15 +++++++++++++++
 3 files changed, 24 insertions(+)

diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 4dc30e0a321..8a8de3237cd 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -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
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index e07ee85c06e..85bbd043a1d 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -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
index 00000000000..aa29acbcb13
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/concepts-conv1.C
@@ -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 "" }
+}


More information about the Gcc-cvs mailing list