From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 2BED4394740E for ; Tue, 15 Nov 2022 23:22:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2BED4394740E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668554560; 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=FV2Ah54Gni6oISgIKpkvfKTGEqtaYWT/Ajbr9RBr7pc=; b=IBV+qbbHMdSGKzTB05owcypI7il0AIUXWWNW8yllVrRJo3FTkcOZ0i+CBj9W5XG2XAS0gW Ms05JUuNDQF5wbyasVSR+pv+CGKYzv8hSbIBof2f3eCttyiRqjWhxxjx4jZqU5bTs81Shl 7WV+FSCltQCFMFZPjuAnf4EZdFeaSS0= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-557-QBheF8JxOGOA190y9xOUqw-1; Tue, 15 Nov 2022 18:22:39 -0500 X-MC-Unique: QBheF8JxOGOA190y9xOUqw-1 Received: by mail-qv1-f70.google.com with SMTP id ln3-20020a0562145a8300b004b8c29a7d50so11833500qvb.15 for ; Tue, 15 Nov 2022 15:22:39 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=FV2Ah54Gni6oISgIKpkvfKTGEqtaYWT/Ajbr9RBr7pc=; b=Bdp0mb+LcMXdZzA7Uddkfy3qVvuE3n9pUVXJwYqpVL5GHihn4zxOpFCU68Hm/7zbSG X2ts5c6kmerPZB/Mg+JAUx6fCV9so4WgFfjgIBigWyQ9sK0HibLyRupOq+SYdamrunP6 HQIVw0b4xsKhWwx8Q+R4B7mMTU9JDzuSTnME9JYO/1xZHdt/jrky1MdUGBpR03knZibS x1QBNOdBlE/aIPZhcCUOetHoRDpAyn+XgrsHlq4j+cBBfDzMXHxieaKt+9G5tHFhjtFd z3QP+6KMvZuHe77FdHmptIN9k0ewtj0G2S1IbI0+4xGjs/t58GNLWEEcMKM3HsWv/JoW uG2A== X-Gm-Message-State: ANoB5pnA4/yAoyjS19yFpzz1b/9hef52gQvZc2YUTC5EEYrUMMBvgxQK mGavrVIiIeL0ENzoP1CFT+IrgqqA6/LmU1/E8CgWEb/EDu4GdWmrAKdVS2Ngt/N2pJHhkH3v/cg N0XAk0ge4QMHZkWTp3g== X-Received: by 2002:a0c:efd2:0:b0:4bb:76a0:62cd with SMTP id a18-20020a0cefd2000000b004bb76a062cdmr18967808qvt.46.1668554559170; Tue, 15 Nov 2022 15:22:39 -0800 (PST) X-Google-Smtp-Source: AA0mqf6oNEhUFeqS4v5blLvwnzVaw4MbvrR11BjYLtPIKddQQ2cDEW3mQzbwke7YhOnx7YwKPED8ug== X-Received: by 2002:a0c:efd2:0:b0:4bb:76a0:62cd with SMTP id a18-20020a0cefd2000000b004bb76a062cdmr18967792qvt.46.1668554558895; Tue, 15 Nov 2022 15:22:38 -0800 (PST) Received: from [192.168.1.101] (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id t19-20020ac865d3000000b003a527d29a41sm7810586qto.75.2022.11.15.15.22.37 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 15 Nov 2022 15:22:38 -0800 (PST) Message-ID: Date: Tue, 15 Nov 2022 18:22:36 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: [PATCH] c++, v2: Implement CWG2635 - Constrained structured bindings To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org References: From: Jason Merrill In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,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 List-Id: On 11/13/22 01:50, Jakub Jelinek wrote: > 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. Let's make the constrained auto case a pedwarn instead of an error. > * g++.dg/cpp2a/decomp5.C: New test. > * g++.dg/cpp2a/concepts-placeholder7.C: Adjust expected diagnostics. > * g++.dg/cpp2a/concepts-placeholder8.C: Likewise. > > --- 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<, >\\\]'" } > } > > > Jakub >