[gcc r15-1297] c++/modules: export using across namespace [PR114683]
Jason Merrill
jason@gcc.gnu.org
Thu Jun 13 15:06:37 GMT 2024
https://gcc.gnu.org/g:609764a42f0cd3f6358562cab98fc220d3d2d9fd
commit r15-1297-g609764a42f0cd3f6358562cab98fc220d3d2d9fd
Author: Jason Merrill <jason@redhat.com>
Date: Wed Jun 12 18:24:35 2024 -0400
c++/modules: export using across namespace [PR114683]
Currently we represent a non-function using-declaration by inserting the
named declaration into the target scope. In general this works fine, but in
the case of an exported using-declaration we have nowhere to mark the
using-declaration as exported, so we mark the original declaration as
exported instead, and then treat all using-declarations that name it as
exported as well. We were doing this only if there was also a previous
non-exported using, so for this testcase the export got lost; this patch
broadens the workaround to also apply to the using that first brings the
declaration into the current scope.
This does not fully resolve 114683, but replaces a missing exports bug with
an extra exports bug, which should be a significant usability improvement.
The testcase has xfails for extra exports.
I imagine a complete fix should involve inserting a USING_DECL.
PR c++/114683
gcc/cp/ChangeLog:
* name-lookup.cc (do_nonmember_using_decl): Allow exporting
a newly inserted decl.
gcc/testsuite/ChangeLog:
* g++.dg/modules/using-22_a.C: New test.
* g++.dg/modules/using-22_b.C: New test.
Diff:
---
gcc/cp/name-lookup.cc | 5 ++---
gcc/testsuite/g++.dg/modules/using-22_a.C | 24 ++++++++++++++++++++++++
gcc/testsuite/g++.dg/modules/using-22_b.C | 13 +++++++++++++
3 files changed, 39 insertions(+), 3 deletions(-)
diff --git a/gcc/cp/name-lookup.cc b/gcc/cp/name-lookup.cc
index 71482db7b766..b57893116ebc 100644
--- a/gcc/cp/name-lookup.cc
+++ b/gcc/cp/name-lookup.cc
@@ -5316,14 +5316,13 @@ do_nonmember_using_decl (name_lookup &lookup, bool fn_scope_p,
/* FIXME: Handle exporting declarations from a different scope
without also marking those declarations as exported.
This will require not just binding directly to the underlying
- value; see c++/114863 and c++/114865. We allow this for purview
- declarations for now as this doesn't (currently) cause ICEs
+ value; see c++/114683 and c++/114685. We allow the extra exports
+ for now as this doesn't (currently) cause ICEs
later down the line, but this should be revisited. */
if (revealing_p)
{
if (module_exporting_p ()
&& check_can_export_using_decl (lookup.value)
- && lookup.value == value
&& !DECL_MODULE_EXPORT_P (lookup.value))
{
/* We're redeclaring the same value, but this time as
diff --git a/gcc/testsuite/g++.dg/modules/using-22_a.C b/gcc/testsuite/g++.dg/modules/using-22_a.C
new file mode 100644
index 000000000000..9eca9dacb46c
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/using-22_a.C
@@ -0,0 +1,24 @@
+// PR c++/114683
+// { dg-additional-options "-fmodules-ts -Wno-global-module" }
+
+module;
+
+namespace std
+{
+ inline namespace __cxx11
+ {
+ template <typename T>
+ struct basic_string{};
+ }
+}
+
+namespace foo {
+ using std::basic_string;
+}
+
+export module std;
+
+export namespace std
+{
+ using std::basic_string;
+}
diff --git a/gcc/testsuite/g++.dg/modules/using-22_b.C b/gcc/testsuite/g++.dg/modules/using-22_b.C
new file mode 100644
index 000000000000..0b66f4ad6b08
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/using-22_b.C
@@ -0,0 +1,13 @@
+// { dg-additional-options "-fmodules-ts" }
+
+import std;
+
+int main()
+{
+ std::basic_string<char> s;
+
+ // The inline namespace should not be exported, only the 'using' in std.
+ std::__cxx11::basic_string<char> s2; // { dg-error "has not been declared" "" { xfail *-*-* } }
+ // The non-exported using should also not be visible.
+ foo::basic_string<char> s3; // { dg-error "has not been declared" "" { xfail *-*-* } }
+}
More information about the Gcc-cvs
mailing list