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.133.124]) by sourceware.org (Postfix) with ESMTPS id A86C7385DDC6 for ; Tue, 25 Jun 2024 15:45:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A86C7385DDC6 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A86C7385DDC6 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719330339; cv=none; b=bcxEDcGXpOuC9nzcfIionEFZG0t1opNUpR6PfZrc5dtgu5rVkvV+2etQwTV6kb0u/Rwm5kt6qrgnig6M+yrUFIyFvS1YZ/ZF8WrChiGiGyTu25m4e3gdgBmj7DwfwGcEBpdSk+InArz6CC/TFoe1NKnTFa3E6E/9Q8YpCubTObk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719330339; c=relaxed/simple; bh=dnerxQOUjPVrqtvXgy6TLobXzC13aRRGyxFmdOY7LIw=; h=DKIM-Signature:From:Date:To:Subject:Message-ID:MIME-Version; b=jVNZG4DYqySjz+c98UA9JlG44BSoJOaTmbNsz6h649Vetr2WhzMYzy4XiKUGf9EwDQuCuZNSHrzT9NeNxlkFFkBRpRdHAqnJaFuNtMe5U3TdLj9Rv6wW+lGYAG0cVQHotlsnOkWZvbk9mKG1tb1KSSzl9c6c8jY5qmQCq4rPb74= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1719330336; 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: in-reply-to:in-reply-to:references:references; bh=6MSRaT0pGkGJcGaYAJ0pX5UarFh4EQfLWRRbBHDgRi4=; b=DpYnayNDK6QR6iH2e09GoOfJNH/D27Wk1qfPcbxrSSoT0TRtbTHypAZRTn2P/8oi+Lga1a 7TuCWU19vIqFpDOhDHjnsJWOuDY7vtHPnQ5TJoxOf7WBVE8/gh8r1KceaYTIa1pTcWAglI vgA+Er090N5r6hHtYwiJeaVfAr5Wuos= Received: from mail-oi1-f198.google.com (mail-oi1-f198.google.com [209.85.167.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-198-HZVmCMefPzm_rRXmA73fOA-1; Tue, 25 Jun 2024 11:45:34 -0400 X-MC-Unique: HZVmCMefPzm_rRXmA73fOA-1 Received: by mail-oi1-f198.google.com with SMTP id 5614622812f47-3d22b60d030so7939246b6e.3 for ; Tue, 25 Jun 2024 08:45:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719330334; x=1719935134; h=mime-version:references:message-id:in-reply-to:subject:cc:to:date :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=6MSRaT0pGkGJcGaYAJ0pX5UarFh4EQfLWRRbBHDgRi4=; b=m4usPraAmMUFDyR1Ypehulstfx7/+s2oR9nFswUHIwt0ONfIToykD1PJbaj7m6/dBo ggNM4R9ISbgVgznH4hr3PT/97BIn+v0FPGjify0DFrpRsSENWULjeKlNGVsHqgEcLn4Q NK6iFN7E5qq3z0K67EqAwQ0wfpmOY3XwJHDwc4i5x0weXhOzD99654twCkLMEOVrBgVo zxR+N8jmgTkkFFpbTtaEPvFjzr7yu6by6dpjTrBEAhcz5tNKP8rMsm48mhO3ZHIOzb9b xjLNgvI/Zm3x1BZdGJ/iPFpwwExU8aCe4NSL1EItjnQCpAc3dtjqmpmDeKJUMzi4ev2i WILA== X-Forwarded-Encrypted: i=1; AJvYcCV5p8B06zb3uQ7XnXruDYYrGFukk8DV1tr4/0JPKpTmo/6mxa6pChcl3WGVAbYuaYFgOPofRxP6m7ubwkCf3WxhfTaxY9w2Qw== X-Gm-Message-State: AOJu0YwHa6rX+wvy952EknnJWenfYp2j6G8VOcGkTM1xKRgy0Z/0dOah FGr58ivibfobkSaLEnLHDNgQ2HWW0h9ZSEVVMswQNIdswZ3YpGxJ+UK7AvEoJPA1MZwTdtDUrGM VCFk5k3Hc0Ru9deS+94lMIzeWkGqRdRF92OT5Zxld9ImatQ+JSpB1bNw= X-Received: by 2002:a05:6808:152b:b0:3d5:5eee:f377 with SMTP id 5614622812f47-3d55eeef76dmr669360b6e.4.1719330333876; Tue, 25 Jun 2024 08:45:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEHbcQrHoNt+C74Lwh6WXiH6EHPdnYeji2kGd6lfaKM6vICGlYNR7LYzEnXZgJaFu0yU81q4w== X-Received: by 2002:a05:6808:152b:b0:3d5:5eee:f377 with SMTP id 5614622812f47-3d55eeef76dmr669338b6e.4.1719330333373; Tue, 25 Jun 2024 08:45:33 -0700 (PDT) Received: from [192.168.1.130] (ool-18bb2a2e.dyn.optonline.net. [24.187.42.46]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-44501aa9f08sm2650421cf.33.2024.06.25.08.45.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jun 2024 08:45:32 -0700 (PDT) From: Patrick Palka X-Google-Original-From: Patrick Palka Date: Tue, 25 Jun 2024 11:45:32 -0400 (EDT) To: Jason Merrill cc: Patrick Palka , gcc-patches@gcc.gnu.org Subject: Re: [PATCH] c++: decltype of by-ref capture proxy of ref [PR115504] In-Reply-To: <135ed513-7642-476e-9e7c-1ba916ed3cc7@redhat.com> Message-ID: <1c41d032-e545-c299-964f-b6ff58673820@idea> References: <20240625010015.122204-1-ppalka@redhat.com> <65a73f98-0be3-44c5-b703-e369da48f459@redhat.com> <7182593d-7f2b-b842-1262-b94ab6c7599d@idea> <135ed513-7642-476e-9e7c-1ba916ed3cc7@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-13.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,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 Tue, 25 Jun 2024, Jason Merrill wrote: > On 6/25/24 11:03, Patrick Palka wrote: > > On Mon, 24 Jun 2024, Jason Merrill wrote: > > > > > On 6/24/24 21:00, Patrick Palka wrote: > > > > Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK > > > > for trunk/14? > > > > > > > > -- >8 -- > > > > > > > > The capture proxy handling in finish_decltype_type added in r14-5330 > > > > was stripping the reference type of a capture proxy's captured variable, > > > > which is desirable for a by-value capture, but not for a by-ref capture > > > > (of a reference). > > > > > > I'm not sure why we would want it for by-value, either; regardless of the > > > capture kind, decltype(x) is int&. > > > > Ah, makes sense. But I guess that means > > > > void f(int& x) { > > [x]() { > > decltype(auto) a = x; > > } > > } > > > > is ill-formed since decltype(x) is int& but the corresponding closure > > member is const? It works if we make the lambda mutable. > > Yes, and clang agrees. Let's also test that case. Like so? -- >8 -- Subject: [PATCH] c++: decltype of capture proxy of ref [PR115504] The capture proxy handling in finish_decltype_type added in r14-5330 was stripping the reference type of a capture proxy's captured variable. PR c++/115504 gcc/cp/ChangeLog: * semantics.cc (finish_decltype_type): Don't strip the reference type (if any) of a capture proxy's captured variable. gcc/testsuite/ChangeLog: * g++.dg/cpp1y/decltype-auto8.C: New test. --- gcc/cp/semantics.cc | 1 - gcc/testsuite/g++.dg/cpp1y/decltype-auto8.C | 22 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp1y/decltype-auto8.C diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 6c1813d37c6..6a383c0f7f9 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12071,7 +12071,6 @@ finish_decltype_type (tree expr, bool id_expression_or_member_access_p, { expr = DECL_CAPTURED_VARIABLE (expr); type = TREE_TYPE (expr); - type = non_reference (type); } else { diff --git a/gcc/testsuite/g++.dg/cpp1y/decltype-auto8.C b/gcc/testsuite/g++.dg/cpp1y/decltype-auto8.C new file mode 100644 index 00000000000..55135cecf72 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/decltype-auto8.C @@ -0,0 +1,22 @@ +// PR c++/115504 +// { dg-do compile { target c++14 } } + +void f(int& x, const int& y) { + [&x]() { + decltype(auto) a = x; + using type = decltype(x); + using type = decltype(a); + using type = int&; // not 'int' + }; + + [x]() { + decltype(auto) a = x; // { dg-error "discards qualifiers" } + }; + + [x]() mutable { + decltype(auto) a = x; + using type = decltype(x); + using type = decltype(a); + using type = int&; + }; +} -- 2.45.2.648.g1e1586e4ed Subject: [PATCH] c++: decltype of capture proxy of ref [PR115504] The capture proxy handling in finish_decltype_type added in r14-5330 was stripping the reference type of a capture proxy's captured variable. PR c++/115504 gcc/cp/ChangeLog: * semantics.cc (finish_decltype_type): Don't strip the reference type (if any) of a capture proxy's captured variable. gcc/testsuite/ChangeLog: * g++.dg/cpp1y/decltype-auto8.C: New test. --- gcc/cp/semantics.cc | 1 - gcc/testsuite/g++.dg/cpp1y/decltype-auto8.C | 22 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp1y/decltype-auto8.C diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 6c1813d37c6..6a383c0f7f9 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12071,7 +12071,6 @@ finish_decltype_type (tree expr, bool id_expression_or_member_access_p, { expr = DECL_CAPTURED_VARIABLE (expr); type = TREE_TYPE (expr); - type = non_reference (type); } else { diff --git a/gcc/testsuite/g++.dg/cpp1y/decltype-auto8.C b/gcc/testsuite/g++.dg/cpp1y/decltype-auto8.C new file mode 100644 index 00000000000..55135cecf72 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/decltype-auto8.C @@ -0,0 +1,22 @@ +// PR c++/115504 +// { dg-do compile { target c++14 } } + +void f(int& x, const int& y) { + [&x]() { + decltype(auto) a = x; + using type = decltype(x); + using type = decltype(a); + using type = int&; // not 'int' + }; + + [x]() { + decltype(auto) a = x; // { dg-error "discards qualifiers" } + }; + + [x]() mutable { + decltype(auto) a = x; + using type = decltype(x); + using type = decltype(a); + using type = int&; + }; +} -- 2.45.2.648.g1e1586e4ed Subject: [PATCH] c++: decltype of capture proxy of ref [PR115504] The capture proxy handling in finish_decltype_type added in r14-5330 was stripping the reference type of a capture proxy's captured variable. PR c++/115504 gcc/cp/ChangeLog: * semantics.cc (finish_decltype_type): Don't strip the reference type (if any) of a capture proxy's captured variable. gcc/testsuite/ChangeLog: * g++.dg/cpp1y/decltype-auto8.C: New test. --- gcc/cp/semantics.cc | 1 - gcc/testsuite/g++.dg/cpp1y/decltype-auto8.C | 22 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp1y/decltype-auto8.C diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 6c1813d37c6..6a383c0f7f9 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12071,7 +12071,6 @@ finish_decltype_type (tree expr, bool id_expression_or_member_access_p, { expr = DECL_CAPTURED_VARIABLE (expr); type = TREE_TYPE (expr); - type = non_reference (type); } else { diff --git a/gcc/testsuite/g++.dg/cpp1y/decltype-auto8.C b/gcc/testsuite/g++.dg/cpp1y/decltype-auto8.C new file mode 100644 index 00000000000..55135cecf72 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/decltype-auto8.C @@ -0,0 +1,22 @@ +// PR c++/115504 +// { dg-do compile { target c++14 } } + +void f(int& x, const int& y) { + [&x]() { + decltype(auto) a = x; + using type = decltype(x); + using type = decltype(a); + using type = int&; // not 'int' + }; + + [x]() { + decltype(auto) a = x; // { dg-error "discards qualifiers" } + }; + + [x]() mutable { + decltype(auto) a = x; + using type = decltype(x); + using type = decltype(a); + using type = int&; + }; +} -- 2.45.2.648.g1e1586e4ed Subject: [PATCH] c++: decltype of capture proxy of ref [PR115504] The capture proxy handling in finish_decltype_type added in r14-5330 was stripping the reference type of a capture proxy's captured variable. PR c++/115504 gcc/cp/ChangeLog: * semantics.cc (finish_decltype_type): Don't strip the reference type (if any) of a capture proxy's captured variable. gcc/testsuite/ChangeLog: * g++.dg/cpp1y/decltype-auto8.C: New test. --- gcc/cp/semantics.cc | 1 - gcc/testsuite/g++.dg/cpp1y/decltype-auto8.C | 22 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp1y/decltype-auto8.C diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 6c1813d37c6..6a383c0f7f9 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12071,7 +12071,6 @@ finish_decltype_type (tree expr, bool id_expression_or_member_access_p, { expr = DECL_CAPTURED_VARIABLE (expr); type = TREE_TYPE (expr); - type = non_reference (type); } else { diff --git a/gcc/testsuite/g++.dg/cpp1y/decltype-auto8.C b/gcc/testsuite/g++.dg/cpp1y/decltype-auto8.C new file mode 100644 index 00000000000..55135cecf72 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/decltype-auto8.C @@ -0,0 +1,22 @@ +// PR c++/115504 +// { dg-do compile { target c++14 } } + +void f(int& x, const int& y) { + [&x]() { + decltype(auto) a = x; + using type = decltype(x); + using type = decltype(a); + using type = int&; // not 'int' + }; + + [x]() { + decltype(auto) a = x; // { dg-error "discards qualifiers" } + }; + + [x]() mutable { + decltype(auto) a = x; + using type = decltype(x); + using type = decltype(a); + using type = int&; + }; +} -- 2.45.2.648.g1e1586e4ed Subject: [PATCH] c++: decltype of capture proxy of ref [PR115504] The capture proxy handling in finish_decltype_type added in r14-5330 was stripping the reference type of a capture proxy's captured variable. PR c++/115504 gcc/cp/ChangeLog: * semantics.cc (finish_decltype_type): Don't strip the reference type (if any) of a capture proxy's captured variable. gcc/testsuite/ChangeLog: * g++.dg/cpp1y/decltype-auto8.C: New test. --- gcc/cp/semantics.cc | 1 - gcc/testsuite/g++.dg/cpp1y/decltype-auto8.C | 22 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp1y/decltype-auto8.C diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 6c1813d37c6..6a383c0f7f9 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12071,7 +12071,6 @@ finish_decltype_type (tree expr, bool id_expression_or_member_access_p, { expr = DECL_CAPTURED_VARIABLE (expr); type = TREE_TYPE (expr); - type = non_reference (type); } else { diff --git a/gcc/testsuite/g++.dg/cpp1y/decltype-auto8.C b/gcc/testsuite/g++.dg/cpp1y/decltype-auto8.C new file mode 100644 index 00000000000..55135cecf72 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/decltype-auto8.C @@ -0,0 +1,22 @@ +// PR c++/115504 +// { dg-do compile { target c++14 } } + +void f(int& x, const int& y) { + [&x]() { + decltype(auto) a = x; + using type = decltype(x); + using type = decltype(a); + using type = int&; // not 'int' + }; + + [x]() { + decltype(auto) a = x; // { dg-error "discards qualifiers" } + }; + + [x]() mutable { + decltype(auto) a = x; + using type = decltype(x); + using type = decltype(a); + using type = int&; + }; +} -- 2.45.2.648.g1e1586e4ed Subject: [PATCH] c++: decltype of capture proxy of ref [PR115504] The capture proxy handling in finish_decltype_type added in r14-5330 was stripping the reference type of a capture proxy's captured variable. PR c++/115504 gcc/cp/ChangeLog: * semantics.cc (finish_decltype_type): Don't strip the reference type (if any) of a capture proxy's captured variable. gcc/testsuite/ChangeLog: * g++.dg/cpp1y/decltype-auto8.C: New test. --- gcc/cp/semantics.cc | 1 - gcc/testsuite/g++.dg/cpp1y/decltype-auto8.C | 22 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp1y/decltype-auto8.C diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 6c1813d37c6..6a383c0f7f9 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12071,7 +12071,6 @@ finish_decltype_type (tree expr, bool id_expression_or_member_access_p, { expr = DECL_CAPTURED_VARIABLE (expr); type = TREE_TYPE (expr); - type = non_reference (type); } else { diff --git a/gcc/testsuite/g++.dg/cpp1y/decltype-auto8.C b/gcc/testsuite/g++.dg/cpp1y/decltype-auto8.C new file mode 100644 index 00000000000..55135cecf72 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/decltype-auto8.C @@ -0,0 +1,22 @@ +// PR c++/115504 +// { dg-do compile { target c++14 } } + +void f(int& x, const int& y) { + [&x]() { + decltype(auto) a = x; + using type = decltype(x); + using type = decltype(a); + using type = int&; // not 'int' + }; + + [x]() { + decltype(auto) a = x; // { dg-error "discards qualifiers" } + }; + + [x]() mutable { + decltype(auto) a = x; + using type = decltype(x); + using type = decltype(a); + using type = int&; + }; +} -- 2.45.2.648.g1e1586e4ed