public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/vendors/ibm/heads/gcc-9)] PR c++/90998 - ICE with copy elision in init by ctor and -Wconversion.
@ 2020-02-04 20:55 Peter Bergner
  0 siblings, 0 replies; only message in thread
From: Peter Bergner @ 2020-02-04 20:55 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:4d304b7d1b206ccbb83b23c94d895a1aa238bab7

commit 4d304b7d1b206ccbb83b23c94d895a1aa238bab7
Author: Marek Polacek <polacek@redhat.com>
Date:   Fri Nov 8 21:52:39 2019 +0000

    PR c++/90998 - ICE with copy elision in init by ctor and -Wconversion.
    
    	* call.c (joust): Don't attempt to warn if ->second_conv is null.
    
    	* g++.dg/cpp0x/overload-conv-4.C: New test.
    
    From-SVN: r277992

Diff:
---
 gcc/cp/ChangeLog                             |  8 ++++++++
 gcc/cp/call.c                                |  4 +++-
 gcc/testsuite/g++.dg/cpp0x/overload-conv-4.C | 23 +++++++++++++++++++++++
 3 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index c870d4a..f44fdee 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,11 @@
+2019-11-08  Marek Polacek  <polacek@redhat.com>
+
+	Backported from mainline
+	2019-10-29  Marek Polacek  <polacek@redhat.com>
+
+	PR c++/90998 - ICE with copy elision in init by ctor and -Wconversion.
+	* call.c (joust): Don't attempt to warn if ->second_conv is null.
+
 2019-11-08  Jakub Jelinek  <jakub@redhat.com>
 
 	Backported from mainline
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 14ddc98..8f950d1 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -10739,7 +10739,9 @@ joust (struct z_candidate *cand1, struct z_candidate *cand2, bool warn,
      either between a constructor and a conversion op, or between two
      conversion ops.  */
   if ((complain & tf_warning)
-      && winner && warn_conversion && cand1->second_conv
+      /* In C++17, the constructor might have been elided, which means that
+	 an originally null ->second_conv could become non-null.  */
+      && winner && warn_conversion && cand1->second_conv && cand2->second_conv
       && (!DECL_CONSTRUCTOR_P (cand1->fn) || !DECL_CONSTRUCTOR_P (cand2->fn))
       && winner != compare_ics (cand1->second_conv, cand2->second_conv))
     {
diff --git a/gcc/testsuite/g++.dg/cpp0x/overload-conv-4.C b/gcc/testsuite/g++.dg/cpp0x/overload-conv-4.C
new file mode 100644
index 0000000..6fcdbba
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/overload-conv-4.C
@@ -0,0 +1,23 @@
+// PR c++/90998 - ICE with copy elision in init by ctor and -Wconversion.
+// { dg-do compile { target c++11 } }
+// { dg-options "-Wconversion" }
+
+struct B;
+
+struct A {
+    operator B();
+};
+
+struct B {
+    B(A const &rs);
+    B(B const &rs);
+};
+
+B
+f (A x)
+{
+  // C++14: we call B::B(A const &)
+  // C++17: we call A::operator B()
+  return B(x); // { dg-warning "choosing .A::operator B\\(\\). over .B::B\\(const A&\\)" "" { target c++17 } }
+  // { dg-warning "for conversion from .A. to .B." "" { target c++17 } .-1 }
+}


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-02-04 20:55 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-04 20:55 [gcc(refs/vendors/ibm/heads/gcc-9)] PR c++/90998 - ICE with copy elision in init by ctor and -Wconversion Peter Bergner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).