From: Jason Merrill <jason@redhat.com>
To: Patrick Palka <ppalka@redhat.com>, gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] c++: decltype of capture proxy [PR79378, PR96917]
Date: Thu, 9 Nov 2023 19:40:42 -0500 [thread overview]
Message-ID: <34f89eb7-6b59-48b3-9d13-faace0efe598@redhat.com> (raw)
In-Reply-To: <20231107195237.1658753-1-ppalka@redhat.com>
On 11/7/23 14:52, Patrick Palka wrote:
> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
> trunk?
OK.
> -- >8 --
>
> We usually don't see capture proxies in finish_decltype_type because
> process_outer_var_ref is a no-op inside an unevaluated context and
> so a use of a capture inside decltype refers directly to the captured
> variable. But we can still see a capture proxy during decltype(auto)
> deduction and for decltype of an init-capture, which suggests we need
> to handle capture proxies specially within finish_decltype_type (since
> they're always implicitly const). This patch adds such handling.
>
> PR c++/79378
> PR c++/96917
>
> gcc/cp/ChangeLog:
>
> * semantics.cc (finish_decltype_type): Handle an id-expression
> naming a capture proxy specially.
>
> gcc/testsuite/ChangeLog:
>
> * g++.dg/cpp1y/decltype-auto7.C: New test.
> * g++.dg/cpp1y/lambda-init20.C: New test.
> ---
> gcc/cp/semantics.cc | 28 +++++++++--
> gcc/testsuite/g++.dg/cpp1y/decltype-auto7.C | 53 +++++++++++++++++++++
> gcc/testsuite/g++.dg/cpp1y/lambda-init20.C | 22 +++++++++
> 3 files changed, 98 insertions(+), 5 deletions(-)
> create mode 100644 gcc/testsuite/g++.dg/cpp1y/decltype-auto7.C
> create mode 100644 gcc/testsuite/g++.dg/cpp1y/lambda-init20.C
>
> diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
> index 4059e74bdb7..f583dedd6cf 100644
> --- a/gcc/cp/semantics.cc
> +++ b/gcc/cp/semantics.cc
> @@ -11643,12 +11643,30 @@ finish_decltype_type (tree expr, bool id_expression_or_member_access_p,
> /* Fall through for fields that aren't bitfields. */
> gcc_fallthrough ();
>
> - case FUNCTION_DECL:
> case VAR_DECL:
> - case CONST_DECL:
> - case PARM_DECL:
> - case RESULT_DECL:
> - case TEMPLATE_PARM_INDEX:
> + if (is_capture_proxy (expr))
> + {
> + if (is_normal_capture_proxy (expr))
> + {
> + expr = DECL_CAPTURED_VARIABLE (expr);
> + type = TREE_TYPE (expr);
> + type = non_reference (type);
> + }
> + else
> + {
> + expr = DECL_VALUE_EXPR (expr);
> + gcc_assert (TREE_CODE (expr) == COMPONENT_REF);
> + expr = TREE_OPERAND (expr, 1);
> + type = TREE_TYPE (expr);
> + }
> + break;
> + }
> + /* Fall through. */
> + case FUNCTION_DECL:
> + case CONST_DECL:
> + case PARM_DECL:
> + case RESULT_DECL:
> + case TEMPLATE_PARM_INDEX:
> expr = mark_type_use (expr);
> type = TREE_TYPE (expr);
> if (VAR_P (expr) && DECL_NTTP_OBJECT_P (expr))
> diff --git a/gcc/testsuite/g++.dg/cpp1y/decltype-auto7.C b/gcc/testsuite/g++.dg/cpp1y/decltype-auto7.C
> new file mode 100644
> index 00000000000..a37b9db38d4
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/cpp1y/decltype-auto7.C
> @@ -0,0 +1,53 @@
> +// PR c++/96917
> +// { dg-do compile { target c++14 } }
> +
> +int main() {
> + int x = 0;
> + int y = 0;
> + const int cx = 0;
> + const int cy = 0;
> +
> + [x, &y, cx, &cy] {
> + decltype(auto) a = x;
> + using ty1 = int;
> + using ty1 = decltype(x);
> + using ty1 = decltype(a);
> +
> + decltype(auto) b = y;
> + using ty2 = int;
> + using ty2 = decltype(y);
> + using ty2 = decltype(b);
> +
> + decltype(auto) ca = cx;
> + using ty3 = const int;
> + using ty3 = decltype(cx);
> + using ty3 = decltype(ca);
> +
> + decltype(auto) cb = cy;
> + using ty4 = const int;
> + using ty4 = decltype(cy);
> + using ty4 = decltype(cb);
> + };
> +
> + [x=x, &y=y, cx=cx, &cy=cy] {
> + decltype(auto) a = x;
> + using ty1 = int;
> + using ty1 = decltype(x);
> + using ty1 = decltype(a);
> +
> + decltype(auto) b = y;
> + using ty2 = int&;
> + using ty2 = decltype(y);
> + using ty2 = decltype(b);
> +
> + decltype(auto) ca = cx;
> + using ty3 = int;
> + using ty3 = decltype(cx);
> + using ty3 = decltype(ca);
> +
> + decltype(auto) cb = cy;
> + using ty4 = const int&;
> + using ty4 = decltype(cy);
> + using ty4 = decltype(cb);
> + };
> +}
> diff --git a/gcc/testsuite/g++.dg/cpp1y/lambda-init20.C b/gcc/testsuite/g++.dg/cpp1y/lambda-init20.C
> new file mode 100644
> index 00000000000..a06b77a664d
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/cpp1y/lambda-init20.C
> @@ -0,0 +1,22 @@
> +// PR c++/79378
> +// { dg-do compile { target c++14 } }
> +
> +int main() {
> + int x = 0;
> + [x=x, &r=x] {
> + using ty1 = int;
> + using ty1 = decltype(x);
> +
> + using ty2 = int&;
> + using ty2 = decltype(r);
> + };
> +
> + const int cx = 0;
> + [x=cx, &r=cx] {
> + using ty1 = int;
> + using ty1 = decltype(x);
> +
> + using ty2 = const int&;
> + using ty2 = decltype(r);
> + };
> +}
prev parent reply other threads:[~2023-11-10 0:40 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-07 19:52 Patrick Palka
2023-11-10 0:40 ` Jason Merrill [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=34f89eb7-6b59-48b3-9d13-faace0efe598@redhat.com \
--to=jason@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=ppalka@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).