public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jason Merrill <jason@redhat.com>
To: Nathaniel Shead <nathanieloshead@gmail.com>, gcc-patches@gcc.gnu.org
Cc: Nathan Sidwell <nathan@acm.org>
Subject: Re: [PATCH] c++: Ensure DECL_CONTEXT is set for temporary vars [PR114005]
Date: Fri, 1 Mar 2024 08:12:28 -0500	[thread overview]
Message-ID: <25f79249-6c7c-427b-986f-10a4a2aee35f@redhat.com> (raw)
In-Reply-To: <65e0f6e4.a70a0220.12e52.86bd@mx.google.com>

On 2/29/24 16:28, Nathaniel Shead wrote:
> Bootstrapped and regtested on x86_64-pc-linux-gnu, OK for trunk?
> 
> Alternatively we could update 'DECL_CONTEXT' only for
> 'make_temporary_var_for_ref_to_temp' in call.cc, as a more targetted
> fix, but I felt that this way it'd also fix any other similar issues
> that have gone uncaught so far.
> 
> -- >8 --
> 
> Modules streaming requires DECL_CONTEXT to be set for anything streamed.
> This patch ensures that 'create_temporary_var' does set a DECL_CONTEXT
> for these variables (such as the backing storage for initializer_lists)
> even if not inside a function declaration.
> 
> 	PR c++/114005
> 
> gcc/cp/ChangeLog:
> 
> 	* init.cc (create_temporary_var): Set DECL_CONTEXT to
> 	current_namespace if at namespace scope.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* g++.dg/modules/pr114005_a.C: New test.
> 	* g++.dg/modules/pr114005_b.C: New test.
> 
> Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
> ---
>   gcc/cp/init.cc                            | 2 ++
>   gcc/testsuite/g++.dg/modules/pr114005_a.C | 8 ++++++++
>   gcc/testsuite/g++.dg/modules/pr114005_b.C | 7 +++++++
>   3 files changed, 17 insertions(+)
>   create mode 100644 gcc/testsuite/g++.dg/modules/pr114005_a.C
>   create mode 100644 gcc/testsuite/g++.dg/modules/pr114005_b.C
> 
> diff --git a/gcc/cp/init.cc b/gcc/cp/init.cc
> index ac37330527e..e6fca7b3226 100644
> --- a/gcc/cp/init.cc
> +++ b/gcc/cp/init.cc
> @@ -4258,6 +4258,8 @@ create_temporary_var (tree type)
>     DECL_ARTIFICIAL (decl) = 1;
>     DECL_IGNORED_P (decl) = 1;
>     DECL_CONTEXT (decl) = current_function_decl;
> +  if (!DECL_CONTEXT (decl))
> +    DECL_CONTEXT (decl) = current_namespace;

Maybe always set it to current_scope () instead of current_function_decl?

OK with that change.

Jason


      reply	other threads:[~2024-03-01 13:12 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-29 21:28 Nathaniel Shead
2024-03-01 13:12 ` 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=25f79249-6c7c-427b-986f-10a4a2aee35f@redhat.com \
    --to=jason@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=nathan@acm.org \
    --cc=nathanieloshead@gmail.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).