From: Patrick Palka <ppalka@redhat.com>
To: gcc-patches@gcc.gnu.org
Cc: jason@redhat.com, nathan@acm.org, Patrick Palka <ppalka@redhat.com>
Subject: [PATCH] c++ modules: stream non-trailing default targs [PR105045]
Date: Tue, 18 Oct 2022 10:13:10 -0400 [thread overview]
Message-ID: <20221018141310.3139378-1-ppalka@redhat.com> (raw)
This fixes the below testcase in which we neglect to stream the default
argument for T only because the subsequent parameter U doesn't also have
a default argument.
Tested on x86_64-pc-linux-gnu, does this look OK for trunk?
PR c++/105045
gcc/cp/ChangeLog:
* module.cc (trees_out::tpl_parms_fini): Don't assume default
template arguments are all trailing.
(trees_in::tpl_parms_fini): Likewise.
gcc/testsuite/ChangeLog:
* g++.dg/modules/pr105045_a.C: New test.
* g++.dg/modules/pr105045_b.C: New test.
---
gcc/cp/module.cc | 20 ++++++--------------
gcc/testsuite/g++.dg/modules/pr105045_a.C | 7 +++++++
gcc/testsuite/g++.dg/modules/pr105045_b.C | 6 ++++++
3 files changed, 19 insertions(+), 14 deletions(-)
create mode 100644 gcc/testsuite/g++.dg/modules/pr105045_a.C
create mode 100644 gcc/testsuite/g++.dg/modules/pr105045_b.C
diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
index 999ff3faafc..2c2f9a9a8cb 100644
--- a/gcc/cp/module.cc
+++ b/gcc/cp/module.cc
@@ -10034,15 +10034,11 @@ trees_out::tpl_parms_fini (tree tmpl, unsigned tpl_levels)
tree vec = TREE_VALUE (parms);
tree_node (TREE_TYPE (vec));
- tree dflt = error_mark_node;
for (unsigned ix = TREE_VEC_LENGTH (vec); ix--;)
{
tree parm = TREE_VEC_ELT (vec, ix);
- if (dflt)
- {
- dflt = TREE_PURPOSE (parm);
- tree_node (dflt);
- }
+ tree dflt = TREE_PURPOSE (parm);
+ tree_node (dflt);
if (streaming_p ())
{
@@ -10072,19 +10068,15 @@ trees_in::tpl_parms_fini (tree tmpl, unsigned tpl_levels)
tpl_levels--; parms = TREE_CHAIN (parms))
{
tree vec = TREE_VALUE (parms);
- tree dflt = error_mark_node;
TREE_TYPE (vec) = tree_node ();
for (unsigned ix = TREE_VEC_LENGTH (vec); ix--;)
{
tree parm = TREE_VEC_ELT (vec, ix);
- if (dflt)
- {
- dflt = tree_node ();
- if (get_overrun ())
- return false;
- TREE_PURPOSE (parm) = dflt;
- }
+ tree dflt = tree_node ();
+ if (get_overrun ())
+ return false;
+ TREE_PURPOSE (parm) = dflt;
tree decl = TREE_VALUE (parm);
if (TREE_CODE (decl) == TEMPLATE_DECL)
diff --git a/gcc/testsuite/g++.dg/modules/pr105045_a.C b/gcc/testsuite/g++.dg/modules/pr105045_a.C
new file mode 100644
index 00000000000..597f9294185
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/pr105045_a.C
@@ -0,0 +1,7 @@
+// PR c++/105045
+// { dg-additional-options -fmodules-ts }
+// { dg-module-cmi pr105045 }
+
+export module pr105045;
+
+export template<int T=0, class U> void f(U) { }
diff --git a/gcc/testsuite/g++.dg/modules/pr105045_b.C b/gcc/testsuite/g++.dg/modules/pr105045_b.C
new file mode 100644
index 00000000000..77c94d4c473
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/pr105045_b.C
@@ -0,0 +1,6 @@
+// PR c++/105045
+// { dg-additional-options -fmodules-ts }
+
+import pr105045;
+
+int main() { f(0); }
--
2.38.0.118.g4732897cf0
next reply other threads:[~2022-10-18 14:13 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-18 14:13 Patrick Palka [this message]
2022-10-18 14:17 ` Nathan Sidwell
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=20221018141310.3139378-1-ppalka@redhat.com \
--to=ppalka@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jason@redhat.com \
--cc=nathan@acm.org \
/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).