public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c++ modules: stream non-trailing default targs [PR105045]
@ 2022-10-18 14:13 Patrick Palka
  2022-10-18 14:17 ` Nathan Sidwell
  0 siblings, 1 reply; 2+ messages in thread
From: Patrick Palka @ 2022-10-18 14:13 UTC (permalink / raw)
  To: gcc-patches; +Cc: jason, nathan, Patrick Palka

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-10-18 14:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-18 14:13 [PATCH] c++ modules: stream non-trailing default targs [PR105045] Patrick Palka
2022-10-18 14:17 ` Nathan Sidwell

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).