public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [pushed] c++/modules: multiple usings of the same decl [PR115194]
@ 2024-06-13 14:59 Jason Merrill
  0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2024-06-13 14:59 UTC (permalink / raw)
  To: gcc-patches; +Cc: Nathaniel Shead

Tested x86_64-pc-linux-gnu, applying to trunk.

-- 8< --

add_binding_entity creates an OVERLOAD to represent a using-declaration in
module purview of a declaration in the global module, even for
non-functions, and we were failing to merge that with the original
declaration in name lookup.

It's not clear to me that building the OVERLOAD is what should be happening,
but let's work around it for now pending an overhaul of using-decl handling
for c++/114683.

	PR c++/115194

gcc/cp/ChangeLog:

	* name-lookup.cc (name_lookup::process_module_binding): Strip an
	OVERLOAD from a non-function.

gcc/testsuite/ChangeLog:

	* g++.dg/modules/using-23_a.C: New test.
	* g++.dg/modules/using-23_b.C: New test.
---
 gcc/cp/name-lookup.cc                     | 11 +++++++++++
 gcc/testsuite/g++.dg/modules/using-23_a.C | 19 +++++++++++++++++++
 gcc/testsuite/g++.dg/modules/using-23_b.C |  7 +++++++
 3 files changed, 37 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/modules/using-23_a.C
 create mode 100644 gcc/testsuite/g++.dg/modules/using-23_b.C

diff --git a/gcc/cp/name-lookup.cc b/gcc/cp/name-lookup.cc
index 3d3e20f48cb..71482db7b76 100644
--- a/gcc/cp/name-lookup.cc
+++ b/gcc/cp/name-lookup.cc
@@ -827,6 +827,17 @@ name_lookup::process_module_binding (tree new_val, tree new_type,
       marker |= 2;
     }
 
+  /* add_binding_entity wraps decls brought in by 'using' in an OVERLOAD even
+     for non-functions; strip it now.
+     ??? Why isn't it represented with a USING_DECL?  Or do we want to use
+     OVERLOAD for using more widely to address 114683?  */
+  if (new_val && TREE_CODE (new_val) == OVERLOAD
+      && !DECL_DECLARES_FUNCTION_P (OVL_FUNCTION (new_val)))
+    {
+      gcc_checking_assert (OVL_USING_P (new_val) && !OVL_CHAIN (new_val));
+      new_val = OVL_FUNCTION (new_val);
+    }
+
   if (new_type || new_val)
     marker |= process_binding (new_val, new_type);
 
diff --git a/gcc/testsuite/g++.dg/modules/using-23_a.C b/gcc/testsuite/g++.dg/modules/using-23_a.C
new file mode 100644
index 00000000000..e7e6fecbea6
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/using-23_a.C
@@ -0,0 +1,19 @@
+// PR c++/115194
+// { dg-additional-options "-fmodules-ts -Wno-global-module" }
+
+module;
+
+namespace NS1 {
+  namespace NS2 {
+    class Thing {};
+  } // NS2
+  using NS2::Thing;
+} // NS1
+
+export module modA;
+
+export
+namespace NS1 {
+  using ::NS1::Thing;
+  namespace NS2 { }
+}
diff --git a/gcc/testsuite/g++.dg/modules/using-23_b.C b/gcc/testsuite/g++.dg/modules/using-23_b.C
new file mode 100644
index 00000000000..6502c476b9b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/using-23_b.C
@@ -0,0 +1,7 @@
+// { dg-additional-options "-fmodules-ts" }
+
+import modA;
+
+using NS1::Thing;
+using namespace NS1::NS2;
+Thing thing;

base-commit: 99e6cf404e37655be303e71f20df03c284c7989e
-- 
2.44.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-06-13 14:59 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-13 14:59 [pushed] c++/modules: multiple usings of the same decl [PR115194] 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).