diff options
author | Nathaniel Shead <nathanieloshead@gmail.com> | 2024-03-03 23:48:17 +1100 |
---|---|---|
committer | Nathaniel Shead <nathanieloshead@gmail.com> | 2024-03-05 10:32:57 +1100 |
commit | ad0f4ef6f74741ea6178a8b795e49effc2bc2a9c (patch) | |
tree | d93a0da5f7a2b2dff9b8b652c719c1bb81e89bc6 /gcc/cp | |
parent | d646db0e35ad9d235635b204349f5d960072f9fe (diff) | |
download | gcc-ad0f4ef6f74741ea6178a8b795e49effc2bc2a9c.zip gcc-ad0f4ef6f74741ea6178a8b795e49effc2bc2a9c.tar.gz gcc-ad0f4ef6f74741ea6178a8b795e49effc2bc2a9c.tar.bz2 |
c++: Support exporting using-decls in same namespace as target
Currently a using-declaration bringing a name into its own namespace is
a no-op, except for functions. This prevents people from being able to
redeclare a name brought in from the GMF as exported, however, which
this patch fixes.
Apart from marking declarations as exported they are also now marked as
effectively being in the module purview (due to the using-decl) so that
they are properly processed, as 'add_binding_entity' assumes that
declarations not in the module purview cannot possibly be exported.
gcc/cp/ChangeLog:
* name-lookup.cc (walk_module_binding): Remove completed FIXME.
(do_nonmember_using_decl): Mark redeclared entities as exported
when needed. Check for re-exporting internal linkage types.
gcc/testsuite/ChangeLog:
* g++.dg/modules/using-12.C: New test.
* g++.dg/modules/using-13.h: New test.
* g++.dg/modules/using-13_a.C: New test.
* g++.dg/modules/using-13_b.C: New test.
Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/name-lookup.cc | 50 |
1 files changed, 42 insertions, 8 deletions
diff --git a/gcc/cp/name-lookup.cc b/gcc/cp/name-lookup.cc index 6444db3..dce4caf 100644 --- a/gcc/cp/name-lookup.cc +++ b/gcc/cp/name-lookup.cc @@ -4189,7 +4189,7 @@ walk_module_binding (tree binding, bitmap partitions, void *data) { // FIXME: We don't quite deal with using decls naming stat hack - // type. Also using decls exporting something from the same scope. + // type. tree current = binding; unsigned count = 0; @@ -5238,13 +5238,36 @@ do_nonmember_using_decl (name_lookup &lookup, bool fn_scope_p, } else if (insert_p) { - value = lookup.value; - if (revealing_p && module_exporting_p ()) - check_can_export_using_decl (value); + if (revealing_p + && module_exporting_p () + && check_can_export_using_decl (lookup.value) + && lookup.value == value + && !DECL_MODULE_EXPORT_P (value)) + { + /* We're redeclaring the same value, but this time as + newly exported: make sure to mark it as such. */ + if (TREE_CODE (value) == TEMPLATE_DECL) + { + DECL_MODULE_EXPORT_P (value) = true; + + tree result = DECL_TEMPLATE_RESULT (value); + retrofit_lang_decl (result); + DECL_MODULE_PURVIEW_P (result) = true; + DECL_MODULE_EXPORT_P (result) = true; + } + else + { + retrofit_lang_decl (value); + DECL_MODULE_PURVIEW_P (value) = true; + DECL_MODULE_EXPORT_P (value) = true; + } + } + else + value = lookup.value; } /* Now the type binding. */ - if (lookup.type && lookup.type != type) + if (lookup.type) { if (type && !decls_match (lookup.type, type)) { @@ -5253,9 +5276,20 @@ do_nonmember_using_decl (name_lookup &lookup, bool fn_scope_p, } else if (insert_p) { - type = lookup.type; - if (revealing_p && module_exporting_p ()) - check_can_export_using_decl (type); + if (revealing_p + && module_exporting_p () + && check_can_export_using_decl (lookup.type) + && lookup.type == type + && !DECL_MODULE_EXPORT_P (type)) + { + /* We're redeclaring the same type, but this time as + newly exported: make sure to mark it as such. */ + retrofit_lang_decl (type); + DECL_MODULE_PURVIEW_P (type) = true; + DECL_MODULE_EXPORT_P (type) = true; + } + else + type = lookup.type; } } |