From patchwork Mon Sep 16 04:33:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1162609 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-509033-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="sFSaBCQX"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="UB6E7BCG"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46Wtfs4tF6z9sNk for ; Mon, 16 Sep 2019 14:33:57 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:in-reply-to:references:mime-version :content-type:content-transfer-encoding; q=dns; s=default; b=Gaq Jr18LzqlJqJl16Z0v21j/URN74mT4KZYpIJ14rXZ8KhUAw1d8c1WN3SYQjyyapt9 UP9n+7Zr6EcuaVUPqtCVaZ1zIK9rC1SopNdVv3yx7r9O9cuD6JsOZofeCR8X/vsO n5hl3NJhv1lJuPV/uNfZ+2g/+uceIb32f3U/rLSE= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:in-reply-to:references:mime-version :content-type:content-transfer-encoding; s=default; bh=gveQnEFAO dJRM2SPwcJguzsVdvg=; b=sFSaBCQXC+US6hRT++PE0ieerO8yL4UWzC+WYRkd9 uMg2upCCBbfOVezYDdTJ+zBoLVnzjMt6gnkIn5CU7NVa28uJN8cqT06BiXoTIOp9 afGM7rjgf5dzCJ1ezr4hMR0gs2/5rDqf8XfzyKJnNevXvHiDinEsRLFNMphzra4n i0= 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-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@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) 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 00:33:26 -0400 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 X-IsSubscribed: yes While working on C++20 operator<=>, 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<=> 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; } - /* 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 = cand->convs[0]; - if (conv->kind == ck_ref_bind) - conv = next_conversion (conv); - arg1 = convert_like (conv, arg1, complain); + if (conv->user_conv_p) + { + while (conv->kind != ck_user) + conv = next_conversion (conv); + arg1 = convert_like (conv, arg1, complain); + } if (arg2) { conv = cand->convs[1]; - if (conv->kind == ck_ref_bind) - conv = next_conversion (conv); - else - arg2 = 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 = convert_like (conv, arg2, complain); + if (conv->user_conv_p) + { + while (conv->kind != ck_user) + conv = next_conversion (conv); + arg2 = convert_like (conv, arg2, complain); + } } + if (arg3) { conv = cand->convs[2]; - if (conv->kind == ck_ref_bind) - conv = next_conversion (conv); - convert_like (conv, arg3, complain); + if (conv->user_conv_p) + { + while (conv->kind != ck_user) + conv = next_conversion (conv); + arg3 = 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 != 0, complain); + 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 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, 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 = cp_perform_integral_promotions (arg, complain); /* 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, bool noconvert, | WANT_VECTOR_OR_COMPLEX, arg, true))) errstring = _("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)) == 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.