* [pushed] c++/modules: export using across namespace [PR114683]
@ 2024-06-13 15:05 Jason Merrill
0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2024-06-13 15:05 UTC (permalink / raw)
To: gcc-patches; +Cc: Nathaniel Shead
Tested x86_64-pc-linux-gnu, applying to trunk.
-- 8< --
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.
---
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(-)
create mode 100644 gcc/testsuite/g++.dg/modules/using-22_a.C
create mode 100644 gcc/testsuite/g++.dg/modules/using-22_b.C
diff --git a/gcc/cp/name-lookup.cc b/gcc/cp/name-lookup.cc
index 71482db7b76..b57893116eb 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 00000000000..9eca9dacb46
--- /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 00000000000..0b66f4ad6b0
--- /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 *-*-* } }
+}
base-commit: 99e6cf404e37655be303e71f20df03c284c7989e
--
2.44.0
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2024-06-13 15:06 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-13 15:05 [pushed] c++/modules: export using across namespace [PR114683] Jason Merrill
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).