PR c++/78894 - ICE with class deduction and default arg
authorJason Merrill <jason@redhat.com>
Wed, 18 Jan 2017 16:44:27 +0000 (11:44 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Wed, 18 Jan 2017 16:44:27 +0000 (11:44 -0500)
* pt.c (build_deduction_guide): Set DECL_PRIMARY_TEMPLATE.

From-SVN: r244582

gcc/cp/ChangeLog
gcc/cp/pt.c
gcc/testsuite/g++.dg/cpp1z/class-deduction24.C [new file with mode: 0644]

index 7e8c465aba9a044610d6afecf997b55efadebbc1..2fa2e1e65f990e5cf9a18095795cdeb54b97a1bd 100644 (file)
@@ -1,3 +1,8 @@
+2017-01-17  Jason Merrill  <jason@redhat.com>
+
+       PR c++/78894 - ICE with class deduction and default arg
+       * pt.c (build_deduction_guide): Set DECL_PRIMARY_TEMPLATE.
+
 2017-01-18  Markus Trippelsdorf  <markus@trippelsdorf.de>
 
        PR c++/77489
index 022ffda9ed28337676b4a70042e5a09c912180d7..6fd03a5379a42936d188774296f930ce1b88b16d 100644 (file)
@@ -24968,6 +24968,13 @@ build_deduction_guide (tree ctor, tree outer_args, tsubst_flags_t complain)
       current_template_parms = save_parms;
       --processing_template_decl;
     }
+  else
+    {
+      /* Copy the parms so we can set DECL_PRIMARY_TEMPLATE.  */
+      tparms = copy_node (tparms);
+      INNERMOST_TEMPLATE_PARMS (tparms)
+       = copy_node (INNERMOST_TEMPLATE_PARMS (tparms));
+    }
 
   tree fntype = build_function_type (type, fparms);
   tree ded_fn = build_lang_decl_loc (DECL_SOURCE_LOCATION (ctor),
@@ -24978,6 +24985,7 @@ build_deduction_guide (tree ctor, tree outer_args, tsubst_flags_t complain)
   DECL_TEMPLATE_RESULT (ded_tmpl) = ded_fn;
   TREE_TYPE (ded_tmpl) = TREE_TYPE (ded_fn);
   DECL_TEMPLATE_INFO (ded_fn) = build_template_info (ded_tmpl, targs);
+  DECL_PRIMARY_TEMPLATE (ded_tmpl) = ded_tmpl;
   if (ci)
     set_constraints (ded_tmpl, ci);
 
diff --git a/gcc/testsuite/g++.dg/cpp1z/class-deduction24.C b/gcc/testsuite/g++.dg/cpp1z/class-deduction24.C
new file mode 100644 (file)
index 0000000..ba2015a
--- /dev/null
@@ -0,0 +1,14 @@
+// PR c++/78894
+// { dg-options -std=c++1z }
+
+struct A
+{
+  A ();
+};
+template <typename T>
+struct C
+{
+  C (int, const T &, const A & = A ());
+};
+
+C a = { 0, 0 };