Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look
OK for trunk?
-- >8 --
Alias templates are weird in that their specializations can appear in
both decl_specializations and type_specializations. They appear in the
latter only at parse time via finish_template_type. This should probably
be revisited in GCC 15 since it seems sufficient to store them only in
decl_specializations. In the meantime, the below patch makes sure that
if a such a specialization is stored in both tables then we don't
overwrite in the type code path the TEMPLATE_INFO set by the decl code
path (which always runs first). That's because tsubst_template_decl
during partial instantiation of a member template sets TI_TEMPLATE of
the TYPE_DECL to point to the partially instantiated TEMPLATE_DECL
whereas lookup_template_class wants to always point to the most general
template. This ends up confusing modules in the testcase below for the
partial instantiation A<B>::key_arg<T> -- we decide to stream the
TYPE_DECL for this partial instantiation separately from the
corresponding TEMPLATE_DECL due to this incorrect TI_TEMPLATE setting.
PR c++/103994
gcc/cp/ChangeLog:
* pt.cc (lookup_template_class): Don't overwrite TEMPLATE_INFO
for an alias template specialization.
gcc/testsuite/ChangeLog:
* g++.dg/modules/tpl-alias-2_a.H: New test.
* g++.dg/modules/tpl-alias-2_b.C: New test.
---
gcc/cp/pt.cc | 7 ++++++-
gcc/testsuite/g++.dg/modules/tpl-alias-2_a.H | 15 +++++++++++++++
gcc/testsuite/g++.dg/modules/tpl-alias-2_b.C | 9 +++++++++
3 files changed, 30 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/g++.dg/modules/tpl-alias-2_a.H
create mode 100644 gcc/testsuite/g++.dg/modules/tpl-alias-2_b.C
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index c4bc54a8fdb..ce2d53fe762 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -10431,7 +10431,12 @@ lookup_template_class (tree d1, tree arglist, tree
in_decl, tree context,
}
/* Build template info for the new specialization. */
- SET_TYPE_TEMPLATE_INFO (t, build_template_info (found, arglist));
+ if (DECL_ALIAS_TEMPLATE_P (gen_tmpl))
+ /* Already properly set by instantiate_template (or
+ tsubst_template_decl). */
+ gcc_assert (DECL_TEMPLATE_INFO (TYPE_NAME (t)));
+ else
+ SET_TYPE_TEMPLATE_INFO (t, build_template_info (found, arglist));
elt.spec = t;
slot = type_specializations->find_slot_with_hash (&elt, hash, INSERT);
diff --git a/gcc/testsuite/g++.dg/modules/tpl-alias-2_a.H
b/gcc/testsuite/g++.dg/modules/tpl-alias-2_a.H
new file mode 100644
index 00000000000..76917f778e0
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/tpl-alias-2_a.H
@@ -0,0 +1,15 @@
+// PR c++/103994
+// { dg-additional-options -fmodule-header }
+// { dg-module-cmi {} }
+
+template<class>
+struct A {
+ template<class> using key_arg = int;
+};
+
+struct B {
+ template<class T>
+ void f() {
+ using type = A<B>::key_arg<T>;
+ }
+};
diff --git a/gcc/testsuite/g++.dg/modules/tpl-alias-2_b.C
b/gcc/testsuite/g++.dg/modules/tpl-alias-2_b.C
new file mode 100644
index 00000000000..44fa5f42757
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/tpl-alias-2_b.C
@@ -0,0 +1,9 @@
+// PR c++/103994
+// { dg-additional-options -fmodules-ts }
+
+import "tpl-alias-2_a.H";
+
+int main() {
+ B b;
+ b.f<int>();
+}
--
2.44.0.84.gb387623c12