From patchwork Sun Nov 13 11:50:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 19352 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1646888wru; Sun, 13 Nov 2022 03:51:04 -0800 (PST) X-Google-Smtp-Source: AA0mqf7p1YvMoOlQkmBoVNpcirCRIYOOcYZnihlIhPHIK5A1cbRkM/S5EFy31F0rYZFS9tMJDjBo X-Received: by 2002:a50:9f8b:0:b0:458:fa8f:f82c with SMTP id c11-20020a509f8b000000b00458fa8ff82cmr7773597edf.246.1668340263895; Sun, 13 Nov 2022 03:51:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668340263; cv=none; d=google.com; s=arc-20160816; b=RQQ+aoPJjMi/OXhynSU2en8+sRhAG+of5T2iQcH4QSn6qt+9onBU4nHD2MR6K7ic3+ BwBrVes9uDFP/C5xo4lhCV/ekMXNvyw8mdQdsyfNeDT7Gs0pKmWIBlAKbUrOBxBbG/IC 79ZgEA1Qyls+510b3KqMA3cSZHcBS0AxkMK7qTOWyF2SS8q5m31jnkknc8wzaFvnZtCA jCevM5aGkPcV+kgm5VSzEptSO2VWk1U8GiWinaIl2ksxOY31S5fbRbPfQ02iimajC0ne ImXj+8EHARTB5lZmWnX/lCcxlfWJesHmupBybSj0eso6UCKPOtRZ4ZUB+gAz3BqfbJ1o /o+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-disposition:in-reply-to:mime-version:references:message-id :subject:cc:to:date:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=f7mplHAjxIk8kJPZlnyuAOrIeav05MvRFZwIZd1y5sQ=; b=YdzqGQKMv/jXQa5FzKtPWizCGxk2nEIgg/PZXiGecenCBVmUzlpT9KUZaEi0yKYRYI g2YRnS7WrR3jXJFZz++p+clhQwslzPza42OvXIcoy/9QNloJnl1TgWnxsiMpZD/Syoyh pClf6o2rSfTVpi6g6+thB99v0raPACg6qibSsW9M1J82CcwaaKSUulP2a+5B5NKKLOPY gJTu4uKC9mJdd7HXuLly4aq0cSR4YzR25aitwrdaFBAkYOyN/gFEQg9r45O9f7JsF+OS xVJIyiC7qjlfKFkmM4DeYB1sQTO0kcPZCXmprqwMOj6XmM6qRTIhHRp37AgkFaPNrHhB oMfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=o5hCn8zE; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id dm5-20020a170907948500b007822665aa36si7367433ejc.430.2022.11.13.03.51.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Nov 2022 03:51:03 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=o5hCn8zE; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AB63B38438D5 for ; Sun, 13 Nov 2022 11:50:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AB63B38438D5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1668340259; bh=f7mplHAjxIk8kJPZlnyuAOrIeav05MvRFZwIZd1y5sQ=; h=Date:To:Cc:Subject:References:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=o5hCn8zEB0Z5pu/9i32ktU3h1E5GwQ1UlfrL+dmZLqnnyxz+P0J4U15fIYMuRDuQk S39Gey/85E/Nuq7p+1tCwo36ZkVhHwAMiuzU562oyBQ7ez1/ghXt/8ipFbK6u/JgMa 8k9WCgJPzql9hcrL36czGSL7ANlnRopmw77Y7wdA= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id DB75D3858436 for ; Sun, 13 Nov 2022 11:50:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DB75D3858436 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-537-7i5uQ0UwMByIqS14ANri_w-1; Sun, 13 Nov 2022 06:50:14 -0500 X-MC-Unique: 7i5uQ0UwMByIqS14ANri_w-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0ECC2800B23 for ; Sun, 13 Nov 2022 11:50:14 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.38]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C4A642166B2B; Sun, 13 Nov 2022 11:50:13 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 2ADBo9ce2803531 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sun, 13 Nov 2022 12:50:09 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 2ADBo8WR2803530; Sun, 13 Nov 2022 12:50:08 +0100 Date: Sun, 13 Nov 2022 12:50:08 +0100 To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] c++, v2: Implement CWG2635 - Constrained structured bindings Message-ID: References: MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749381560173841906?= X-GMAIL-MSGID: =?utf-8?q?1749381560173841906?= On Sat, Nov 12, 2022 at 12:23:56PM +0100, Jakub Jelinek wrote: > The following patch implements CWG2635. > > So far tested on > GXX_TESTSUITE_STDS=98,11,14,17,20,2b make check-g++ RUNTESTFLAGS="dg.exp=decomp*" > ok for trunk if it passes full bootstrap/regtest and it is voted in? Here is another version of the patch that passed bootstrap/regtest, the only change are tweaks to 2 further testcases. 2022-11-13 Jakub Jelinek * decl.cc (grokdeclarator): Implement CWG2635 - Constrained structured bindings. Diagnose constrained auto type. * g++.dg/cpp2a/decomp5.C: New test. * g++.dg/cpp2a/concepts-placeholder7.C: Adjust expected diagnostics. * g++.dg/cpp2a/concepts-placeholder8.C: Likewise. Jakub --- gcc/cp/decl.cc.jj 2022-11-11 17:14:33.103869977 +0100 +++ gcc/cp/decl.cc 2022-11-12 12:13:52.217239729 +0100 @@ -12660,7 +12660,8 @@ grokdeclarator (const cp_declarator *dec gcc_unreachable (); } if (TREE_CODE (type) != TEMPLATE_TYPE_PARM - || TYPE_IDENTIFIER (type) != auto_identifier) + || TYPE_IDENTIFIER (type) != auto_identifier + || PLACEHOLDER_TYPE_CONSTRAINTS_INFO (type)) { if (type != error_mark_node) { --- gcc/testsuite/g++.dg/cpp2a/decomp5.C.jj 2022-11-12 12:17:21.024392082 +0100 +++ gcc/testsuite/g++.dg/cpp2a/decomp5.C 2022-11-12 12:20:00.700214521 +0100 @@ -0,0 +1,20 @@ +// CWG2635 - Constrained structured bindings +// { dg-do compile { target c++20 } } + +namespace std { + template struct tuple_size; + template struct tuple_element; +} + +struct A { + int i; + A(int x) : i(x) {} + template int& get() { return i; } +}; + +template<> struct std::tuple_size { static const int value = 2; }; +template struct std::tuple_element { using type = int; }; + +template concept C = true; +C auto [x, y] = A{1}; // { dg-error "structured binding declaration cannot have type 'auto \\\[requires ::C<, >\\\]'" } + // { dg-message "type must be cv-qualified 'auto' or reference to cv-qualified 'auto'" "" { target *-*-* } .-1 } --- gcc/testsuite/g++.dg/cpp2a/concepts-placeholder7.C.jj 2021-04-06 23:49:08.288882716 +0200 +++ gcc/testsuite/g++.dg/cpp2a/concepts-placeholder7.C 2022-11-13 12:17:38.570047510 +0100 @@ -7,16 +7,16 @@ template void f() { int x[] = {1,2}; int y[] = {3}; - C1 auto [a,b] = x; - C1 auto [c] = y; // { dg-error "constraints" } + C1 auto [a,b] = x; // { dg-error "structured binding declaration cannot have type 'auto \\\[requires ::C1<, >\\\]'" } + C1 auto [c] = y; // { dg-error "structured binding declaration cannot have type 'auto \\\[requires ::C1<, >\\\]'" } } template void g() { T x[] = {1,2}; T y[] = {3}; - C1 auto [a,b] = x; - C1 auto [c] = y; // { dg-error "constraints" } + C1 auto [a,b] = x; // { dg-error "structured binding declaration cannot have type 'auto \\\[requires ::C1<, >\\\]'" } + C1 auto [c] = y; // { dg-error "structured binding declaration cannot have type 'auto \\\[requires ::C1<, >\\\]'" } } template void g(); @@ -27,6 +27,6 @@ struct S { int a, b; } s; template void h() { - const C2 auto& [a, b] = s; + const C2 auto& [a, b] = s; // { dg-error "structured binding declaration cannot have type 'const auto \\\[requires ::C2<, >\\\]'" } } template void h(); --- gcc/testsuite/g++.dg/cpp2a/concepts-placeholder8.C.jj 2021-04-06 23:49:08.288882716 +0200 +++ gcc/testsuite/g++.dg/cpp2a/concepts-placeholder8.C 2022-11-13 12:19:17.034684881 +0100 @@ -5,6 +5,6 @@ template concept is_const = __ void f() { int x[] = {1,2}; const int y[] = {3}; - const is_const auto [a,b] = x; // { dg-error "constraints" } - const is_const auto [c] = y; + const is_const auto [a,b] = x; // { dg-error "structured binding declaration cannot have type 'const auto \\\[requires ::is_const<, >\\\]'" } + const is_const auto [c] = y; // { dg-error "structured binding declaration cannot have type 'const auto \\\[requires ::is_const<, >\\\]'" } }