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 490E8395A05A for ; Wed, 16 Nov 2022 13:12:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 490E8395A05A 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=1668604340; 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=nYPOuhy2gV5h+pti2q/F9dSvKhxJ0YKKrN84WEnueSA=; b=c0/a7ey/fTtPJ4BhKfgo5d0K6NB+xgP2qh0MMznE0w6VFsBxzeZWOu+8kRWoo7J61B7HJW cvHdxg6TZp52PYp79wLnMdFVEXkHihKL/gAusUPloUu0qvBW3LcYK3r3p0SohLxVZzLiOb m34Hp8H8Ku9tyjYu9v9DLSKRTRpcbJ0= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-115-KZzHTzCWO6qdrX30IMtCLA-1; Wed, 16 Nov 2022 08:12:19 -0500 X-MC-Unique: KZzHTzCWO6qdrX30IMtCLA-1 Received: by mail-qt1-f197.google.com with SMTP id y19-20020a05622a121300b003a526e0ff9bso12829703qtx.15 for ; Wed, 16 Nov 2022 05:12:19 -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=nYPOuhy2gV5h+pti2q/F9dSvKhxJ0YKKrN84WEnueSA=; b=5ds4VBwkS5apjIq184/9tH0Z3jyUdI6VIZm1l3lrxEcyqgQ4nV0swDttnXHmJhuvZb P+OHeE1jcPA1CFA080VKAVLGoTg9oZ28whz+AshGhgZDRu/y6WdoMKzGazXwVdRTgVw/ TO64h1S3uFlT0/3iT33hvLqv49ViUDLUixrn34pkduSLNr1xwKGrFCgc7eymWW+eZfrO P4k71FC1t2TOAoxES5Q+m33VzDVh5XPNreye8FBolzE4wdFgq+Mp1nJ+f/p9RdN6uH2B z9NGi3sqf1FspSgxsqMeyRl/D83ywdXosXMzRUUPH8fffUfaVUdKcsiRVxpNBD0mGAVy L/uQ== X-Gm-Message-State: ANoB5pnEQnkZEyPa18GNejvmxsXUrNChPVFg/j7KlGBvssQjXiprhy87 UG8Xe6K+hgY0+ifX4EArnUvs5+IGUXoDCdjvZGaimrswHGyzZViaYPOZp9Eho52yrw7MkaEA8K4 h5BKPK6zxxwqAgmiZ9A== X-Received: by 2002:a37:ad02:0:b0:6fa:16fe:93f6 with SMTP id f2-20020a37ad02000000b006fa16fe93f6mr13008142qkm.258.1668604339001; Wed, 16 Nov 2022 05:12:19 -0800 (PST) X-Google-Smtp-Source: AA0mqf5d5iJCE92t6W7WjzyrkSP4dlGH7qH7F9SLn3RXUa4IEdfEmhZRGzGutgsEKgGpURyMYSRzHg== X-Received: by 2002:a37:ad02:0:b0:6fa:16fe:93f6 with SMTP id f2-20020a37ad02000000b006fa16fe93f6mr13008117qkm.258.1668604338615; Wed, 16 Nov 2022 05:12:18 -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 t23-20020ac87617000000b003a586888a20sm8728927qtq.79.2022.11.16.05.12.17 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 16 Nov 2022 05:12:17 -0800 (PST) Message-ID: <7f8bee68-f9b9-3c28-cc3d-53d8dbf22198@redhat.com> Date: Wed, 16 Nov 2022 08:12:17 -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++, v3: 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/16/22 05:17, Jakub Jelinek wrote: > On Tue, Nov 15, 2022 at 06:22:36PM -0500, Jason Merrill wrote: >>> 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. > > So like this (i.e. just pedwarn but don't change the type and keep doing > what we were before)? OK. > 2022-11-16 Jakub Jelinek > > * decl.cc (grokdeclarator): Implement > CWG2635 - Constrained structured bindings. Emit a pedwarn on > constrained auto type. Add auto_diagnostic_group for error_at > and inform for non-auto type on structured bindings declaration. > > * g++.dg/cpp2a/decomp5.C: New test. > * g++.dg/cpp2a/decomp6.C: New test. > * g++.dg/cpp2a/decomp7.C: New test. > * g++.dg/cpp2a/concepts-placeholder7.C: Adjust expected diagnostics. > * g++.dg/cpp2a/concepts-placeholder8.C: Likewise. > * g++.dg/cpp2a/concepts-placeholder9.C: New test. > * g++.dg/cpp2a/concepts-placeholder10.C: New test. > > --- gcc/cp/decl.cc.jj 2022-11-16 07:29:11.603716748 +0100 > +++ gcc/cp/decl.cc 2022-11-16 11:07:05.169822071 +0100 > @@ -12664,6 +12664,7 @@ grokdeclarator (const cp_declarator *dec > { > if (type != error_mark_node) > { > + auto_diagnostic_group d; > error_at (loc, "structured binding declaration cannot have " > "type %qT", type); > inform (loc, > @@ -12673,6 +12674,10 @@ grokdeclarator (const cp_declarator *dec > type = build_qualified_type (make_auto (), type_quals); > declspecs->type = type; > } > + else if (PLACEHOLDER_TYPE_CONSTRAINTS_INFO (type)) > + pedwarn (loc, OPT_Wpedantic, > + "structured binding declaration cannot have constrained " > + "% type %qT", type); > inlinep = 0; > typedef_p = 0; > constexpr_p = 0; > --- gcc/testsuite/g++.dg/cpp2a/decomp5.C.jj 2022-11-16 10:39:20.469335601 +0100 > +++ gcc/testsuite/g++.dg/cpp2a/decomp5.C 2022-11-16 10:46:02.272896156 +0100 > @@ -0,0 +1,19 @@ > +// 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 constrained 'auto' type 'auto \\\[requires ::C<, >\\\]'" } > --- gcc/testsuite/g++.dg/cpp2a/decomp6.C.jj 2022-11-16 10:46:44.868319518 +0100 > +++ gcc/testsuite/g++.dg/cpp2a/decomp6.C 2022-11-16 10:47:07.485013348 +0100 > @@ -0,0 +1,20 @@ > +// CWG2635 - Constrained structured bindings > +// { dg-do compile { target c++20 } } > +// { dg-options "-pedantic" } > + > +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-warning "structured binding declaration cannot have constrained 'auto' type 'auto \\\[requires ::C<, >\\\]'" } > --- gcc/testsuite/g++.dg/cpp2a/decomp7.C.jj 2022-11-16 10:47:14.578917309 +0100 > +++ gcc/testsuite/g++.dg/cpp2a/decomp7.C 2022-11-16 10:47:32.061680633 +0100 > @@ -0,0 +1,20 @@ > +// CWG2635 - Constrained structured bindings > +// { dg-do compile { target c++20 } } > +// { dg-options "-Wno-pedantic" } > + > +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-bogus "structured binding declaration cannot have constrained 'auto' type 'auto \\\[requires ::C<, >\\\]'" } > --- gcc/testsuite/g++.dg/cpp2a/concepts-placeholder7.C.jj 2022-11-13 17:53:46.037681901 +0100 > +++ gcc/testsuite/g++.dg/cpp2a/concepts-placeholder7.C 2022-11-16 11:09:56.092513219 +0100 > @@ -7,16 +7,18 @@ 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 constrained 'auto' type 'auto \\\[requires ::C1<, >\\\]'" } > + C1 auto [c] = y; // { dg-error "structured binding declaration cannot have constrained 'auto' type 'auto \\\[requires ::C1<, >\\\]'" } > + // { dg-error "constraints" "" { target *-*-* } .-1 } > } > > 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 constrained 'auto' type 'auto \\\[requires ::C1<, >\\\]'" } > + C1 auto [c] = y; // { dg-error "structured binding declaration cannot have constrained 'auto' type 'auto \\\[requires ::C1<, >\\\]'" } > + // { dg-error "constraints" "" { target *-*-* } .-1 } > } > template void g(); > > @@ -27,6 +29,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 constrained 'auto' type 'const auto \\\[requires ::C2<, >\\\]'" } > } > template void h(); > --- gcc/testsuite/g++.dg/cpp2a/concepts-placeholder8.C.jj 2022-11-13 17:53:46.037681901 +0100 > +++ gcc/testsuite/g++.dg/cpp2a/concepts-placeholder8.C 2022-11-16 11:10:25.432116956 +0100 > @@ -5,6 +5,7 @@ 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 constrained 'auto' type 'const auto \\\[requires ::is_const<, >\\\]'" } > + // { dg-error "constraints" "" { target *-*-* } .-1 } > + const is_const auto [c] = y; // { dg-error "structured binding declaration cannot have constrained 'auto' type 'const auto \\\[requires ::is_const<, >\\\]'" } > } > --- gcc/testsuite/g++.dg/cpp2a/concepts-placeholder9.C.jj 2022-11-16 10:49:54.610750873 +0100 > +++ gcc/testsuite/g++.dg/cpp2a/concepts-placeholder9.C 2022-11-16 11:12:09.234715037 +0100 > @@ -0,0 +1,33 @@ > +// PR c++/99899 > +// { dg-do compile { target c++20 } } > +// { dg-options "-Wno-pedantic" } > + > +template concept C1 = sizeof(T) > sizeof(int[1]); > + > +template > +void f() { > + int x[] = {1,2}; > + int y[] = {3}; > + C1 auto [a,b] = x; > + C1 auto [c] = y; // { dg-error "constraints" } > +} > + > +template > +void g() { > + T x[] = {1,2}; > + T y[] = {3}; > + C1 auto [a,b] = x; > + C1 auto [c] = y; // { dg-error "constraints" } > +} > +template void g(); > + > + > +template concept C2 = sizeof...(Ts) > 1; > + > +struct S { int a, b; } s; > + > +template > +void h() { > + const C2 auto& [a, b] = s; > +} > +template void h(); > --- gcc/testsuite/g++.dg/cpp2a/concepts-placeholder10.C.jj 2022-11-16 10:49:54.610750873 +0100 > +++ gcc/testsuite/g++.dg/cpp2a/concepts-placeholder10.C 2022-11-16 10:50:16.757451058 +0100 > @@ -0,0 +1,11 @@ > +// { dg-do compile { target c++20 } } > +// { dg-options "-Wno-pedantic" } > + > +template concept is_const = __is_same(T, const T); > + > +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; > +} > > Jakub >