From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 623 invoked by alias); 16 Sep 2019 04:33: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 594 invoked by uid 89); 16 Sep 2019 04:33:39 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3 autolearn=ham version=3.3.1 spammy=promotions X-HELO: us-smtp-delivery-1.mimecast.com Received: from us-smtp-2.mimecast.com (HELO us-smtp-delivery-1.mimecast.com) (207.211.31.81) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 16 Sep 2019 04:33:37 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1568608415; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7DXPVhSH8kYXcamzYsyxVEp2xTM/7FPATjwLihyr+Zo=; b=UB6E7BCG0Rr7+RTLb/KV9e4j4f9QIbra2okCmVWNoBdZe1b0YYrgwF4cd8ygVMbUXqi/no FIEfJ1B4ES4tBofXIILjJ+Qon0VjmewhxXH4oXK8ItF2x/Tgfg8pOpqDOewzcL1w9YDxlw Uz4w2U8ak1VLo1z57RGkSd6FerJnhxM= Received: from mail-io1-f69.google.com (mail-io1-f69.google.com [209.85.166.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-55-XNHFYRT0P5-7xFdYR7HlmA-1; Mon, 16 Sep 2019 00:33:33 -0400 Received: by mail-io1-f69.google.com with SMTP id g8so4078456iop.19 for ; Sun, 15 Sep 2019 21:33:32 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([72.142.123.242]) by smtp.gmail.com with ESMTPSA id c4sm28992888ioa.76.2019.09.15.21.33.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Sep 2019 21:33:30 -0700 (PDT) From: Jason Merrill To: gcc-patches@gcc.gnu.org Subject: [C++ PATCH 2/4] Fix conversions for built-in operator overloading candidates. Date: Mon, 16 Sep 2019 04:33:00 -0000 Message-Id: <20190916043328.3739-2-jason@redhat.com> In-Reply-To: <20190916043328.3739-1-jason@redhat.com> References: <20190916043328.3739-1-jason@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=WINDOWS-1252 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes X-SW-Source: 2019-09/txt/msg00923.txt.bz2 While working on C++20 operator<=3D>, I noticed that build_new_op_1 was doi= ng 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 different 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..457fa6605c2 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; } =20 - /* 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); + } =20 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); + } } - } } =20 @@ -6241,7 +6240,7 @@ build_new_op_1 (const op_location_t &loc, enum tree_c= ode code, int flags, case REALPART_EXPR: case IMAGPART_EXPR: case ABS_EXPR: - return cp_build_unary_op (code, arg1, candidates !=3D 0, complain); + return cp_build_unary_op (code, arg1, false, complain); =20 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 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -6242,7 +6242,7 @@ cp_build_unary_op (enum tree_code code, tree xarg, bo= ol 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); =20 /* Make sure the result is not an lvalue: a unary plus or minus @@ -6267,7 +6267,7 @@ cp_build_unary_op (enum tree_code code, tree xarg, bo= ol 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 (ar= g))) { /* 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 =20 PR c++/91740 - ICE with constexpr call and ?: in ARRAY_REF. --=20 2.21.0