From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 57314 invoked by alias); 19 Sep 2019 19:43:39 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 57222 invoked by uid 89); 19 Sep 2019 19:43:39 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-16.0 required=5.0 tests=AWL,BAYES_00,BODY_8BITS,GARBLED_BODY,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: us-smtp-1.mimecast.com Received: from us-smtp-delivery-1.mimecast.com (HELO us-smtp-1.mimecast.com) (205.139.110.120) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 19 Sep 2019 19:43:37 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1568922214; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6GnC29ZOZZ98hVgsNUoJcHwAIG2RCAqBBbqjBOwCxUg=; b=bNKD7S8S4kyK4W0jQ7uoLcLMj0tfm9dnPAQG33egCKV2aOLVBREHhcSYiK5ZF7Sw3wEATl FPOR57b/yZLgGavQb2QPZOImWFUrUy0bT2wpw3aQsdvG57RIpA2pcle5+a6yE1syQucGcG rGMzrKhJKlgPcKf/hTO7GxOyCBqOaxM= Received: from mail-ot1-f71.google.com (mail-ot1-f71.google.com [209.85.210.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-296-t5tvoBBcPnelkFp3UtpbNQ-1; Thu, 19 Sep 2019 15:43:33 -0400 Received: by mail-ot1-f71.google.com with SMTP id o4so2388936otp.16 for ; Thu, 19 Sep 2019 12:43:33 -0700 (PDT) MIME-Version: 1.0 References: <20190916043328.3739-1-jason@redhat.com> <20190916043328.3739-2-jason@redhat.com> In-Reply-To: From: Jason Merrill Date: Thu, 19 Sep 2019 19:43:00 -0000 Message-ID: Subject: Re: [C++ PATCH 2/4] Fix conversions for built-in operator overloading candidates. To: JiangNing OS Cc: "gcc-patches@gcc.gnu.org" , Feng Xue OS X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes X-SW-Source: 2019-09/txt/msg01214.txt.bz2 I've reverted this patch for the moment. On Wed, Sep 18, 2019 at 8:19 PM JiangNing OS wrote: > > Hi Jason, > > This commit caused boot-strap failure on aarch64. Is it a bug? Can this b= e fixed ASAP? > > ../../gcc/gcc/expmed.c:5602:19: error: =EF=BF=BD=EF=BF=BD=EF=BF=BDint_mod= e=EF=BF=BD=EF=BF=BD=EF=BF=BD may be used uninitialized in this function [-W= error=3Dmaybe-uninitialized] > 5602 | scalar_int_mode int_mode; > | ^~~~~~~~ > > Thanks, > -Jiangning > > > -----Original Message----- > > From: gcc-patches-owner@gcc.gnu.org > > On Behalf Of Jason Merrill > > Sent: Monday, September 16, 2019 12:33 PM > > To: gcc-patches@gcc.gnu.org > > Subject: [C++ PATCH 2/4] Fix conversions for built-in operator overload= ing > > candidates. > > > > While working on C++20 operator<=3D>, I noticed that build_new_op_1 was > > doing too much conversion when a built-in candidate was selected; the > > standard says it should only perform user-defined conversions, and then > > leave the normal operator semantics to handle any standard conversions. > > This is important for operator<=3D> because a comparison of two differe= nt > > unscoped enums is ill-formed; if we promote the enums to int here, > > cp_build_binary_op never gets to see the original operand types, so we = can't > > give the error. > > > > Tested x86_64-pc-linux-gnu, applying to trunk. > > > > * call.c (build_new_op_1): Don't apply any standard conversions to > > the operands of a built-in operator. Don't suppress conversions = in > > cp_build_unary_op. > > * typeck.c (cp_build_unary_op): Do integral promotions for enums. > > --- > > gcc/cp/call.c | 51 ++++++++++++++++++++++++------------------------ > > gcc/cp/typeck.c | 4 ++-- > > gcc/cp/ChangeLog | 7 +++++++ > > 3 files changed, 34 insertions(+), 28 deletions(-) > > > > diff --git a/gcc/cp/call.c b/gcc/cp/call.c index c3045d948c5..457fa6605= c2 > > 100644 > > --- a/gcc/cp/call.c > > +++ b/gcc/cp/call.c > > @@ -6139,41 +6139,40 @@ build_new_op_1 (const op_location_t &loc, > > enum tree_code code, int flags, > > break; > > } > > > > - /* We need to strip any leading REF_BIND so that bitfields > > - don't cause errors. This should not remove any important > > - conversions, because builtins don't apply to class > > - objects directly. */ > > + /* "If a built-in candidate is selected by overload resolution,= the > > + operands of class type are converted to the types of the > > + corresponding parameters of the selected operation function, > > + except that the second standard conversion sequence of a > > + user-defined conversion sequence (12.3.3.1.2) is not applied= ." > > +*/ > > conv =3D cand->convs[0]; > > - if (conv->kind =3D=3D ck_ref_bind) > > - conv =3D next_conversion (conv); > > - arg1 =3D convert_like (conv, arg1, complain); > > + if (conv->user_conv_p) > > + { > > + while (conv->kind !=3D ck_user) > > + conv =3D next_conversion (conv); > > + arg1 =3D convert_like (conv, arg1, complain); > > + } > > > > if (arg2) > > { > > conv =3D cand->convs[1]; > > - if (conv->kind =3D=3D ck_ref_bind) > > - conv =3D next_conversion (conv); > > - else > > - arg2 =3D decay_conversion (arg2, complain); > > - > > - /* We need to call warn_logical_operator before > > - converting arg2 to a boolean_type, but after > > - decaying an enumerator to its value. */ > > - if (complain & tf_warning) > > - warn_logical_operator (loc, code, boolean_type_node, > > - code_orig_arg1, arg1, > > - code_orig_arg2, arg2); > > - > > - arg2 =3D convert_like (conv, arg2, complain); > > + if (conv->user_conv_p) > > + { > > + while (conv->kind !=3D ck_user) > > + conv =3D next_conversion (conv); > > + arg2 =3D convert_like (conv, arg2, complain); > > + } > > } > > + > > if (arg3) > > { > > conv =3D cand->convs[2]; > > - if (conv->kind =3D=3D ck_ref_bind) > > - conv =3D next_conversion (conv); > > - convert_like (conv, arg3, complain); > > + if (conv->user_conv_p) > > + { > > + while (conv->kind !=3D ck_user) > > + conv =3D next_conversion (conv); > > + arg3 =3D convert_like (conv, arg3, complain); > > + } > > } > > - > > } > > } > > > > @@ -6241,7 +6240,7 @@ build_new_op_1 (const op_location_t &loc, enum > > tree_code code, int flags, > > case REALPART_EXPR: > > case IMAGPART_EXPR: > > case ABS_EXPR: > > - return cp_build_unary_op (code, arg1, candidates !=3D 0, complai= n); > > + return cp_build_unary_op (code, arg1, false, complain); > > > > case ARRAY_REF: > > return cp_build_array_ref (input_location, arg1, arg2, complain)= ; diff --git > > a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 70094d1b426..620f2c9afdf 1006= 44 > > --- a/gcc/cp/typeck.c > > +++ b/gcc/cp/typeck.c > > @@ -6242,7 +6242,7 @@ cp_build_unary_op (enum tree_code code, tree > > xarg, bool noconvert, > > : _("wrong type argument to unary plus")); > > else > > { > > - if (!noconvert && CP_INTEGRAL_TYPE_P (TREE_TYPE (arg))) > > + if (!noconvert && INTEGRAL_OR_ENUMERATION_TYPE_P > > (TREE_TYPE > > +(arg))) > > arg =3D cp_perform_integral_promotions (arg, complain); > > > > /* Make sure the result is not an lvalue: a unary plus or min= us @@ > > -6267,7 +6267,7 @@ cp_build_unary_op (enum tree_code code, tree xarg, > > bool noconvert, > > | > > WANT_VECTOR_OR_COMPLEX, > > arg, true))) > > errstring =3D _("wrong type argument to bit-complement"); > > - else if (!noconvert && CP_INTEGRAL_TYPE_P (TREE_TYPE (arg))) > > + else if (!noconvert && INTEGRAL_OR_ENUMERATION_TYPE_P > > (TREE_TYPE > > + (arg))) > > { > > /* Warn if the expression has boolean value. */ > > if (TREE_CODE (TREE_TYPE (arg)) =3D=3D BOOLEAN_TYPE diff --git > > a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index e92d49f1b76..a03a428109b > > 100644 > > --- a/gcc/cp/ChangeLog > > +++ b/gcc/cp/ChangeLog > > @@ -1,3 +1,10 @@ > > +2019-09-15 Jason Merrill > > + > > + * call.c (build_new_op_1): Don't apply any standard conversions to > > + the operands of a built-in operator. Don't suppress conversions = in > > + cp_build_unary_op. > > + * typeck.c (cp_build_unary_op): Do integral promotions for enums. > > + > > 2019-09-15 Marek Polacek > > > > PR c++/91740 - ICE with constexpr call and ?: in ARRAY_REF. > > -- > > 2.21.0 >