From patchwork Fri Mar 6 18:41:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1250575 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-520801-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.a=rsa-sha1 header.s=default header.b=QFDctx/i; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=UjdK0FWt; 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 48YxLZ4lZPz9sPK for ; Sat, 7 Mar 2020 05:42:30 +1100 (AEDT) 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:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; q=dns; s= default; b=f7rXvbBH3e/LA0xLwkb6V4uNRVeWqu4glz+K7gHPBH2JJTQ6Zjwwo g8hspRZEWU4vC3Tlr3UMXJW+rm0weLGw9BH1SVkvRJd3neqW4PjLeiQFhOpjuSdG 5KtzyosXyH7pNIg0l75a4heNLSY/VYSw7sL6JY3Fl1qPS6hHRNZMXE= 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:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; s=default; bh=biZXXeeknb37qDVDsB6n4PMSjGg=; b=QFDctx/iV2Oodp/lwbRo4eia9lIr tGQK2vZ0mE6cXFUX4vemPT5BnLpx3R34n568rJCdBuT/Oj+edYJLenbWgmxEStVL 8zmiKnJVLeqwmzbtUHqBxQtrG0L+AwjNWIkwtFtJw87RTuPF+WHnftt/sOhuVJtC 0+qUBvhf9ZAHswU= Received: (qmail 27089 invoked by alias); 6 Mar 2020 18:42:10 -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 27027 invoked by uid 89); 6 Mar 2020 18:42:09 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=sfinae, non-const, SFINAE, nonconst X-HELO: us-smtp-delivery-1.mimecast.com Received: from us-smtp-1.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; Fri, 06 Mar 2020 18:42:08 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583520127; 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=UjjAuXwiwdSc8N4W97CqKob9etrkTlZ+RonNIrgDeVs=; b=UjdK0FWtQHrkb0rDNWDSXG7ip7EzYIRbBYJWiFmAKcI+USjdy6jvChG5Z0vh6KrTh89ko8 RooKB686F5ddbQkbY3tIbadPnWLzCtXsXshdpdOi1zyXzjkscHk15r/ULfO4cmHYRsuzPP OlSmoF5Gy6VCeu+VxOZdD7xIeyc/LGI= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-27-TR4l0EpxMti7xeh6NYpGGA-1; Fri, 06 Mar 2020 13:42:05 -0500 Received: by mail-qt1-f197.google.com with SMTP id p12so1960494qtu.6 for ; Fri, 06 Mar 2020 10:42:05 -0800 (PST) Received: from localhost.localdomain (ool-457d493a.dyn.optonline.net. [69.125.73.58]) by smtp.gmail.com with ESMTPSA id u18sm3613088qtv.96.2020.03.06.10.42.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Mar 2020 10:42:04 -0800 (PST) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH] c++: Fix missing SFINAE when binding a bit-field to a reference (PR 93729) Date: Fri, 6 Mar 2020 13:41:37 -0500 Message-Id: <20200306184137.3926946-2-ppalka@redhat.com> In-Reply-To: <20200306184137.3926946-1-ppalka@redhat.com> References: <20200306184137.3926946-1-ppalka@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-IsSubscribed: yes We are unconditionally emitting an error here, without first checking complain. This is not a regression, though I guess it could loosely be considered to be a concepts bug, and the fix seems to be relatively harmless. Does this maybe look OK for trunk, or should it wait for stage 1? gcc/cp/ChangeLog: PR c++/93729 * call.c (convert_like_real): Check complain before emitting an error about binding a bit-field to a reference. gcc/testsuite/ChangeLog: PR c++/93729 * g++.dg/concepts/pr93729.C: New test. --- gcc/cp/call.c | 21 ++++++++++++--------- gcc/testsuite/g++.dg/concepts/pr93729.C | 15 +++++++++++++++ 2 files changed, 27 insertions(+), 9 deletions(-) create mode 100644 gcc/testsuite/g++.dg/concepts/pr93729.C diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 85bbd043a1d..c0340d96f3c 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -7730,15 +7730,18 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum, { /* If the reference is volatile or non-const, we cannot create a temporary. */ - if (lvalue & clk_bitfield) - error_at (loc, "cannot bind bit-field %qE to %qT", - expr, ref_type); - else if (lvalue & clk_packed) - error_at (loc, "cannot bind packed field %qE to %qT", - expr, ref_type); - else - error_at (loc, "cannot bind rvalue %qE to %qT", - expr, ref_type); + if (complain & tf_error) + { + if (lvalue & clk_bitfield) + error_at (loc, "cannot bind bit-field %qE to %qT", + expr, ref_type); + else if (lvalue & clk_packed) + error_at (loc, "cannot bind packed field %qE to %qT", + expr, ref_type); + else + error_at (loc, "cannot bind rvalue %qE to %qT", + expr, ref_type); + } return error_mark_node; } /* If the source is a packed field, and we must use a copy diff --git a/gcc/testsuite/g++.dg/concepts/pr93729.C b/gcc/testsuite/g++.dg/concepts/pr93729.C new file mode 100644 index 00000000000..7397edb311d --- /dev/null +++ b/gcc/testsuite/g++.dg/concepts/pr93729.C @@ -0,0 +1,15 @@ +// { dg-do compile { target c++2a } } + +// PR c++/93729 + +struct B +{ + int a:4; + int b:4; +}; + +template +concept c1 + = requires(T x, void(f)(int &)) { f(x.a); }; // { dg-bogus "cannot bind" } + +static_assert(!c1);