From: Marek Polacek Date: Fri, 8 Nov 2019 21:52:39 +0000 (+0000) Subject: PR c++/90998 - ICE with copy elision in init by ctor and -Wconversion. X-Git-Tag: releases/gcc-9.3.0~406 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4d304b7d1b206ccbb83b23c94d895a1aa238bab7;p=thirdparty%2Fgcc.git 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 --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index c870d4a3817e..f44fdee6aa1b 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,11 @@ +2019-11-08 Marek Polacek + + Backported from mainline + 2019-10-29 Marek Polacek + + 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 Backported from mainline diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 14ddc98f3014..8f950d133214 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 000000000000..6fcdbbaa6a4b --- /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 } +}