From: Nathan Sidwell <nathan@acm.org>
To: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: c++: Set more DECL_CONTEXTs
Date: Tue, 28 Jul 2020 12:01:19 -0400 [thread overview]
Message-ID: <82c3fb25-65ce-10db-c730-29cf97bdc3a4@acm.org> (raw)
[-- Attachment #1: Type: text/plain, Size: 412 bytes --]
I discovered we were not setting DECL_CONTEXT in a few cases, and
grokfndecl's control flow wasn't making it clear that we were doing it
in all cases.
gcc/cp/
* cp-gimplify.c (cp_genericize_r): Set IMPORTED_DECL's context.
* cp-objcp-common.c (cp_pushdecl): Set decl's context.
* decl.c (grokfndecl): Make DECL_CONTEXT setting clearer.
--
Nathan Sidwell
[-- Attachment #2: ctx.diff --]
[-- Type: text/x-patch, Size: 1899 bytes --]
diff --git i/gcc/cp/cp-gimplify.c w/gcc/cp/cp-gimplify.c
index 0e949e29c5c..f8695835684 100644
--- i/gcc/cp/cp-gimplify.c
+++ w/gcc/cp/cp-gimplify.c
@@ -1495,6 +1495,7 @@ cp_genericize_r (tree *stmt_p, int *walk_subtrees, void *data)
{
tree using_directive = make_node (IMPORTED_DECL);
TREE_TYPE (using_directive) = void_type_node;
+ DECL_CONTEXT (using_directive) = current_function_decl;
IMPORTED_DECL_ASSOCIATED_DECL (using_directive) = decl;
DECL_CHAIN (using_directive) = BLOCK_VARS (block);
diff --git i/gcc/cp/cp-objcp-common.c w/gcc/cp/cp-objcp-common.c
index dfd8be978b4..fecf8669880 100644
--- i/gcc/cp/cp-objcp-common.c
+++ w/gcc/cp/cp-objcp-common.c
@@ -332,11 +332,12 @@ cp_get_global_decls ()
return NAMESPACE_LEVEL (global_namespace)->names;
}
-/* Push DECL into the current scope. */
+/* Push DECL into the current (namespace) scope. */
tree
cp_pushdecl (tree decl)
{
+ DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace);
return pushdecl (decl);
}
diff --git i/gcc/cp/decl.c w/gcc/cp/decl.c
index 385b1f3a0c4..b4beaa94257 100644
--- i/gcc/cp/decl.c
+++ w/gcc/cp/decl.c
@@ -9560,7 +9560,9 @@ grokfndecl (tree ctype,
/* If this decl has namespace scope, set that up. */
if (in_namespace)
set_decl_namespace (decl, in_namespace, friendp);
- else if (!ctype)
+ else if (ctype)
+ DECL_CONTEXT (decl) = ctype;
+ else
DECL_CONTEXT (decl) = FROB_CONTEXT (current_decl_namespace ());
/* `main' and builtins have implicit 'C' linkage. */
@@ -9588,12 +9590,8 @@ grokfndecl (tree ctype,
if (deletedp)
DECL_DELETED_FN (decl) = 1;
- if (ctype)
- {
- DECL_CONTEXT (decl) = ctype;
- if (funcdef_flag)
- check_class_member_definition_namespace (decl);
- }
+ if (ctype && funcdef_flag)
+ check_class_member_definition_namespace (decl);
if (ctype == NULL_TREE && DECL_MAIN_P (decl))
{
reply other threads:[~2020-07-28 16:01 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=82c3fb25-65ce-10db-c730-29cf97bdc3a4@acm.org \
--to=nathan@acm.org \
--cc=gcc-patches@gcc.gnu.org \
/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).