https://gcc.gnu.org/g:f0c761165929cded4ae08fd5151b483f786bb1b0

commit r16-3274-gf0c761165929cded4ae08fd5151b483f786bb1b0
Author: Nathaniel Shead <nathanielosh...@gmail.com>
Date:   Sun Aug 17 13:00:15 2025 +1000

    c++/modules: Fix exporting using-decls of unattached purview functions 
[PR120195]
    
    We have logic to adjust a function decl if it gets re-declared as a
    using-decl with different purviewness, but we also need to do the same
    if it gets redeclared with different exportedness.
    
            PR c++/120195
    
    gcc/cp/ChangeLog:
    
            * name-lookup.cc (do_nonmember_using_decl): Also handle change
            in exportedness of a function.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/modules/using-32_a.C: New test.
            * g++.dg/modules/using-32_b.C: New test.
    
    Signed-off-by: Nathaniel Shead <nathanielosh...@gmail.com>

Diff:
---
 gcc/cp/name-lookup.cc                     |  6 ++++--
 gcc/testsuite/g++.dg/modules/using-32_a.C | 13 +++++++++++++
 gcc/testsuite/g++.dg/modules/using-32_b.C |  9 +++++++++
 3 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/gcc/cp/name-lookup.cc b/gcc/cp/name-lookup.cc
index fa367214507e..46147905e041 100644
--- a/gcc/cp/name-lookup.cc
+++ b/gcc/cp/name-lookup.cc
@@ -5356,7 +5356,8 @@ do_nonmember_using_decl (name_lookup &lookup, bool 
fn_scope_p,
                        OVL_EXPORT_P (old.get_using ()) = true;
                    }
                  else if (!DECL_LANG_SPECIFIC (inner)
-                          || !DECL_MODULE_PURVIEW_P (inner))
+                          || !DECL_MODULE_PURVIEW_P (inner)
+                          || (exporting_p && !DECL_MODULE_EXPORT_P (inner)))
                    /* We need to re-insert this function as a revealed
                       (possibly exported) declaration.  We can't remove
                       the existing decl because that will change any
@@ -5378,7 +5379,8 @@ do_nonmember_using_decl (name_lookup &lookup, bool 
fn_scope_p,
                  found = true;
                  if (revealing_p
                      && (!DECL_LANG_SPECIFIC (inner)
-                         || !DECL_MODULE_PURVIEW_P (inner)))
+                         || !DECL_MODULE_PURVIEW_P (inner)
+                         || (exporting_p && !DECL_MODULE_EXPORT_P (inner))))
                    found = false;
                  break;
                }
diff --git a/gcc/testsuite/g++.dg/modules/using-32_a.C 
b/gcc/testsuite/g++.dg/modules/using-32_a.C
new file mode 100644
index 000000000000..2d51b3664fae
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/using-32_a.C
@@ -0,0 +1,13 @@
+// PR c++/120195
+// { dg-additional-options "-fmodules" }
+
+export module M;
+
+extern "C++" void foo() {}
+export using ::foo;
+
+namespace ns {
+  extern "C" void bar() {}
+}
+extern "C" void bar();
+export using ns::bar;
diff --git a/gcc/testsuite/g++.dg/modules/using-32_b.C 
b/gcc/testsuite/g++.dg/modules/using-32_b.C
new file mode 100644
index 000000000000..7e6af5e61231
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/using-32_b.C
@@ -0,0 +1,9 @@
+// PR c++/120195
+// { dg-additional-options "-fmodules" }
+
+import M;
+
+int main() {
+  foo();
+  bar();
+}

Reply via email to