* c++: duplicate block-scope extern [PR 97877]
@ 2020-11-17 21:22 Nathan Sidwell
0 siblings, 0 replies; only message in thread
From: Nathan Sidwell @ 2020-11-17 21:22 UTC (permalink / raw)
To: GCC Patches
[-- Attachment #1: Type: text/plain, Size: 740 bytes --]
We ICED with a duplicated block-scope extern, as duplicate_decls was
dropping the decl_lang_specific of olddecl. Simplys adding
appropriate retrofitting and copying turned out to be insufficient
because you can get a block-scope using decl also matching the extern.
The latter seems a little suspicious and I have asked CWG for advice.
While there robustified the assert about releasing olddecls'
lang-specific -- if it had one, the new decl better have one.
PR c++/97877
gcc/cp/
* decl.c (duplicate_decls): Deal with duplicated DECL_LOCAL_DECL_P
decls. Extend decl_lang_specific checking assert.
gcc/testsuite/
* g++.dg/lookup/pr97877.C: New.
pushing to trunk
--
Nathan Sidwell
[-- Attachment #2: pr97877.diff --]
[-- Type: text/x-patch, Size: 1319 bytes --]
diff --git i/gcc/cp/decl.c w/gcc/cp/decl.c
index 89bae06cd6b..d90e9840f40 100644
--- i/gcc/cp/decl.c
+++ w/gcc/cp/decl.c
@@ -2452,6 +2452,20 @@ duplicate_decls (tree newdecl, tree olddecl, bool hiding, bool was_hidden)
if (! DECL_COMDAT (olddecl))
DECL_COMDAT (newdecl) = 0;
+ if (VAR_OR_FUNCTION_DECL_P (newdecl) && DECL_LOCAL_DECL_P (newdecl))
+ {
+ if (!DECL_LOCAL_DECL_P (olddecl))
+ /* This can happen if olddecl was brought in from the
+ enclosing namespace via a using-decl. The new decl is
+ then not a block-scope extern at all. */
+ DECL_LOCAL_DECL_P (newdecl) = false;
+ else
+ {
+ retrofit_lang_decl (newdecl);
+ DECL_LOCAL_DECL_ALIAS (newdecl) = DECL_LOCAL_DECL_ALIAS (olddecl);
+ }
+ }
+
new_template_info = NULL_TREE;
if (DECL_LANG_SPECIFIC (newdecl) && DECL_LANG_SPECIFIC (olddecl))
{
@@ -2735,8 +2749,9 @@ duplicate_decls (tree newdecl, tree olddecl, bool hiding, bool was_hidden)
with that from NEWDECL below. */
if (DECL_LANG_SPECIFIC (olddecl))
{
- gcc_assert (DECL_LANG_SPECIFIC (olddecl)
- != DECL_LANG_SPECIFIC (newdecl));
+ gcc_checking_assert (DECL_LANG_SPECIFIC (newdecl)
+ && (DECL_LANG_SPECIFIC (olddecl)
+ != DECL_LANG_SPECIFIC (newdecl)));
ggc_free (DECL_LANG_SPECIFIC (olddecl));
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-11-17 21:22 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-17 21:22 c++: duplicate block-scope extern [PR 97877] Nathan Sidwell
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).