From: Patrick Palka <ppalka@redhat.com>
To: gcc-patches@gcc.gnu.org
Cc: jason@redhat.com, Patrick Palka <ppalka@redhat.com>
Subject: [PATCH] c++/modules: member alias tmpl partial inst [PR103994]
Date: Mon, 4 Mar 2024 17:26:53 -0500 [thread overview]
Message-ID: <20240304222654.1511204-1-ppalka@redhat.com> (raw)
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
next reply other threads:[~2024-03-04 22:27 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-04 22:26 Patrick Palka [this message]
2024-03-07 3:55 ` Jason Merrill
2024-03-07 16:06 ` Patrick Palka
2024-03-07 19:41 ` Patrick Palka
2024-03-07 20:43 ` Jason Merrill
2024-03-07 20:58 ` Patrick Palka
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240304222654.1511204-1-ppalka@redhat.com \
--to=ppalka@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jason@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).