]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++/modules: Ensure deduction guides for imported types are reachable [PR120023]
authorNathaniel Shead <nathanieloshead@gmail.com>
Wed, 30 Apr 2025 13:35:51 +0000 (23:35 +1000)
committerNathaniel Shead <nathanieloshead@gmail.com>
Wed, 30 Apr 2025 23:51:41 +0000 (09:51 +1000)
In the linked PR, because the deduction guides depend on an imported
type, we never walk the type and so never call add_deduction_guides.
This patch ensures that we make bindings for deduction guides if we saw
any deduction guide at all.

PR c++/120023

gcc/cp/ChangeLog:

* module.cc (depset::hash::find_dependencies): Also call
add_deduction_guides when walking one.

gcc/testsuite/ChangeLog:

* g++.dg/modules/dguide-7_a.C: New test.
* g++.dg/modules/dguide-7_b.C: New test.
* g++.dg/modules/dguide-7_c.C: New test.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
gcc/cp/module.cc
gcc/testsuite/g++.dg/modules/dguide-7_a.C [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/dguide-7_b.C [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/dguide-7_c.C [new file with mode: 0644]

index 7e3b24e2e42e9af6eb0e9b7a68c83257838acf15..f562bf8cd9158498a83b70035b8261047e882a44 100644 (file)
@@ -14823,9 +14823,16 @@ depset::hash::find_dependencies (module_state *module)
                }
              walker.end ();
 
+             /* If we see either a class template or a deduction guide, make
+                sure to add all visible deduction guides.  We need to check
+                both in case they have been added in separate modules, or
+                one is in the GMF and would have otherwise been discarded.  */
              if (!is_key_order ()
                  && DECL_CLASS_TEMPLATE_P (decl))
                add_deduction_guides (decl);
+             if (!is_key_order ()
+                 && deduction_guide_p (decl))
+               add_deduction_guides (TYPE_NAME (TREE_TYPE (TREE_TYPE (decl))));
 
              if (!is_key_order ()
                  && TREE_CODE (decl) == TEMPLATE_DECL
diff --git a/gcc/testsuite/g++.dg/modules/dguide-7_a.C b/gcc/testsuite/g++.dg/modules/dguide-7_a.C
new file mode 100644 (file)
index 0000000..8d0eb80
--- /dev/null
@@ -0,0 +1,9 @@
+// PR c++/120023
+// { dg-additional-options "-fmodules" }
+// { dg-module-cmi M.S }
+
+export module M.S;
+
+namespace ns {
+  export template <typename T> struct S;
+}
diff --git a/gcc/testsuite/g++.dg/modules/dguide-7_b.C b/gcc/testsuite/g++.dg/modules/dguide-7_b.C
new file mode 100644 (file)
index 0000000..85246b2
--- /dev/null
@@ -0,0 +1,10 @@
+// PR c++/120023
+// { dg-additional-options "-fmodules" }
+// { dg-module-cmi M.D }
+
+export module M.D;
+import M.S;
+
+namespace ns {
+  S(int) -> S<int>;
+}
diff --git a/gcc/testsuite/g++.dg/modules/dguide-7_c.C b/gcc/testsuite/g++.dg/modules/dguide-7_c.C
new file mode 100644 (file)
index 0000000..9579d9d
--- /dev/null
@@ -0,0 +1,12 @@
+// PR c++/120023
+// { dg-additional-options "-fmodules" }
+
+import M.S;
+import M.D;
+
+template <> struct ns::S<int> { S(int) {} };
+
+int main() {
+  ns::S s(123);
+  ns::S<int> s2 = s;
+}