https://gcc.gnu.org/g:2486d94bc45a9815395a36cc6dc1e9e3219a74b7

commit r15-9723-g2486d94bc45a9815395a36cc6dc1e9e3219a74b7
Author: Nathaniel Shead <nathanielosh...@gmail.com>
Date:   Sat May 24 00:51:49 2025 +1000

    c++/modules: Fix stream-in of member using-decls [PR120414]
    
    When streaming in a reference to a data member, we have an oversight
    where we did not consider USING_DECLs, despite otherwise handling them
    here the same as fields.  This patch corrects that mistake.
    
            PR c++/120414
    
    gcc/cp/ChangeLog:
    
            * module.cc (trees_in::tree_node): Allow reading a USING_DECL
            when streaming tt_data_member.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/modules/using-31_a.C: New test.
            * g++.dg/modules/using-31_b.C: New test.
    
    Signed-off-by: Nathaniel Shead <nathanielosh...@gmail.com>
    Reviewed-by: Jason Merrill <ja...@redhat.com>
    (cherry picked from commit 43dddeef7a870ce4db7407f73660504b67a0a919)

Diff:
---
 gcc/cp/module.cc                          |  3 ++-
 gcc/testsuite/g++.dg/modules/using-31_a.C | 18 ++++++++++++++++++
 gcc/testsuite/g++.dg/modules/using-31_b.C |  5 +++++
 3 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
index f8fa7f14b033..e66f725c20d3 100644
--- a/gcc/cp/module.cc
+++ b/gcc/cp/module.cc
@@ -10522,7 +10522,8 @@ trees_in::tree_node (bool is_use)
              res = lookup_field_ident (ctx, u ());
 
            if (!res
-               || TREE_CODE (res) != FIELD_DECL
+               || (TREE_CODE (res) != FIELD_DECL
+                   && TREE_CODE (res) != USING_DECL)
                || DECL_CONTEXT (res) != ctx)
              res = NULL_TREE;
          }
diff --git a/gcc/testsuite/g++.dg/modules/using-31_a.C 
b/gcc/testsuite/g++.dg/modules/using-31_a.C
new file mode 100644
index 000000000000..75bd87285e19
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/using-31_a.C
@@ -0,0 +1,18 @@
+// PR c++/120414
+// { dg-additional-options "-fmodules" }
+// { dg-module-cmi m }
+
+export module m;
+
+template <int n>
+struct Base {
+  static constexpr int base_static_mbr_n = n;
+};
+
+template <int n>
+struct Derived : Base<n> {
+  using Base<n>::base_static_mbr_n;
+  static constexpr int go(int x = base_static_mbr_n) { return x; }
+};
+
+template struct Derived<1>;
diff --git a/gcc/testsuite/g++.dg/modules/using-31_b.C 
b/gcc/testsuite/g++.dg/modules/using-31_b.C
new file mode 100644
index 000000000000..e913a77aaf96
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/using-31_b.C
@@ -0,0 +1,5 @@
+// PR c++/120414
+// { dg-additional-options "-fmodules" }
+
+module m;
+static_assert(Derived<1>::go() == 1);

Reply via email to