[gcc r14-6978] c++: Export usings referring to global module fragment [PR109679]

Nathaniel Shead nshead@gcc.gnu.org
Sun Jan 7 10:52:18 GMT 2024


https://gcc.gnu.org/g:63b531e6f8783e8624502d890dc422379de47a9a

commit r14-6978-g63b531e6f8783e8624502d890dc422379de47a9a
Author: Nathaniel Shead <nathanieloshead@gmail.com>
Date:   Wed Jan 3 15:29:51 2024 +1100

    c++: Export usings referring to global module fragment [PR109679]
    
    This patch stops 'add_binding_entity' from ignoring all names in the
    global module fragment, since they should still be exported if named
    in an exported using-declaration.
    
            PR c++/109679
    
    gcc/cp/ChangeLog:
    
            * module.cc (depset::hash::add_binding_entity): Don't skip names
            in the GMF if they've been exported with a using declaration.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/modules/using-11.h: New test.
            * g++.dg/modules/using-11_a.C: New test.
            * g++.dg/modules/using-11_b.C: New test.
    
    Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>

Diff:
---
 gcc/cp/module.cc                          | 6 ++++--
 gcc/testsuite/g++.dg/modules/using-11.h   | 2 ++
 gcc/testsuite/g++.dg/modules/using-11_a.C | 9 +++++++++
 gcc/testsuite/g++.dg/modules/using-11_b.C | 8 ++++++++
 4 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
index a947616ddd6..e0759a9f705 100644
--- a/gcc/cp/module.cc
+++ b/gcc/cp/module.cc
@@ -12832,8 +12832,10 @@ depset::hash::add_binding_entity (tree decl, WMB_Flags flags, void *data_)
       else if (TREE_CODE (inner) == TEMPLATE_DECL)
 	inner = DECL_TEMPLATE_RESULT (inner);
 
-      if (!DECL_LANG_SPECIFIC (inner) || !DECL_MODULE_PURVIEW_P (inner))
-	/* Ignore global module fragment entities.  */
+      if ((!DECL_LANG_SPECIFIC (inner) || !DECL_MODULE_PURVIEW_P (inner))
+	  && !(flags & (WMB_Using | WMB_Export)))
+	/* Ignore global module fragment entities unless explicitly
+	   exported with a using declaration.  */
 	return false;
 
       if (VAR_OR_FUNCTION_DECL_P (inner)
diff --git a/gcc/testsuite/g++.dg/modules/using-11.h b/gcc/testsuite/g++.dg/modules/using-11.h
new file mode 100644
index 00000000000..64c1b0ca335
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/using-11.h
@@ -0,0 +1,2 @@
+// PR c++/109679
+inline int foo() { return 42; }
diff --git a/gcc/testsuite/g++.dg/modules/using-11_a.C b/gcc/testsuite/g++.dg/modules/using-11_a.C
new file mode 100644
index 00000000000..b846bc79203
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/using-11_a.C
@@ -0,0 +1,9 @@
+// PR c++/109679
+// { dg-additional-options "-fmodules-ts" }
+// { dg-module-cmi M }
+
+module;
+#include "using-11.h"
+
+export module M;
+export using ::foo;
diff --git a/gcc/testsuite/g++.dg/modules/using-11_b.C b/gcc/testsuite/g++.dg/modules/using-11_b.C
new file mode 100644
index 00000000000..736a48c98f2
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/using-11_b.C
@@ -0,0 +1,8 @@
+// PR c++/109679
+// { dg-module-do link }
+// { dg-additional-options "-fmodules-ts" }
+
+import M;
+int main() {
+  return foo();
+}


More information about the Gcc-cvs mailing list