c++: Register streamed-in decls when new [PR 99040]
authorNathan Sidwell <nathan@acm.org>
Fri, 12 Feb 2021 14:55:49 +0000 (06:55 -0800)
committerNathan Sidwell <nathan@acm.org>
Fri, 12 Feb 2021 21:50:03 +0000 (13:50 -0800)
commit0c27fe96f812df76ca07272d3c68765bd1f9dc08
tree674ead99157d3d8382dd112f2bd4fd8c519972aa
parent8f93e1b892850b00bf6b9cbc5711a7d5bc367967
c++: Register streamed-in decls when new [PR 99040]

With modules one can have using-decls refering to their own scope.  This
is the way to export things from the GMF or from an import.  The
problem was I was using current_ns == CP_DECL_CONTEXT (decl) to
determine whether a decl should be registered in a namespace level or
not.  But that's an inadequate check and we ended up reregistering
decls and creating a circular list.  We should be registering the decl
when first encountered -- whether we bind it is orthogonal to that.

PR c++/99040
gcc/cp/
* module.cc (trees_in::decl_value): Call add_module_namespace_decl
for new namespace-scope entities.
(module_state::read_cluster): Don't call add_module_decl here.
* name-lookup.h (add_module_decl): Rename to ...
(add_module_namespace_decl): ... this.
* name-lookup.c (newbinding_bookkeeping): Move into ...
(do_pushdecl): ... here.  Its only remaining caller.
(add_module_decl): Rename to ...
(add_module_namespace_decl): ... here.  Add checking-assert for
circularity. Don't call newbinding_bookkeeping, just extern_c
checking and incomplete var checking.
gcc/testsuite/
* g++.dg/modules/pr99040_a.C: New.
* g++.dg/modules/pr99040_b.C: New.
* g++.dg/modules/pr99040_c.C: New.
* g++.dg/modules/pr99040_d.C: New.
gcc/cp/module.cc
gcc/cp/name-lookup.c
gcc/cp/name-lookup.h
gcc/testsuite/g++.dg/modules/pr99040_a.C [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/pr99040_b.C [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/pr99040_c.C [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/pr99040_d.C [new file with mode: 0644]