Re: C++ PATCHes for c++/79549 and 79556 (ICE with auto parameter pack)

2017-05-10 Thread Jason Merrill
On Fri, Feb 17, 2017 at 1:41 PM, Jason Merrill  wrote:
> In 79556, we try to deduce an auto type from a dependent initializer
> with null TREE_TYPE, which doesn't work; fixed by catching that case
> in do_auto_deduction.
>
> In 79549, we try to tsubst into the type of a NONTYPE_ARGUMENT_PACK,
> which doesn't make sense for an auto parameter pack; in fact, it
> doesn't make sense for the argument pack to have a type at all.  For
> GCC 7 I'm fixing this by leaving the auto type in place; for GCC 8
> we'll do away with TREE_TYPE on all NONTYPE_ARGUMENT_PACKs.

And now I'm applying the GCC8 patch.

Jason


C++ PATCHes for c++/79549 and 79556 (ICE with auto parameter pack)

2017-02-17 Thread Jason Merrill
In 79556, we try to deduce an auto type from a dependent initializer
with null TREE_TYPE, which doesn't work; fixed by catching that case
in do_auto_deduction.

In 79549, we try to tsubst into the type of a NONTYPE_ARGUMENT_PACK,
which doesn't make sense for an auto parameter pack; in fact, it
doesn't make sense for the argument pack to have a type at all.  For
GCC 7 I'm fixing this by leaving the auto type in place; for GCC 8
we'll do away with TREE_TYPE on all NONTYPE_ARGUMENT_PACKs.

Tested x86_64-pc-linux-gnu, applying to trunk.
commit d6e7709acaafa96813a2eed1ca7cb51f7f9847a8
Author: Jason Merrill 
Date:   Thu Feb 16 17:24:19 2017 -0500

PR c++/79556 - C++17 ICE with non-type auto

* pt.c (do_auto_deduction): Don't try to deduce from null type.

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 73d6be3..093c0f9 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -25191,6 +25191,10 @@ do_auto_deduction (tree type, tree init, tree 
auto_node,
 /* C++17 class template argument deduction.  */
 return do_class_deduction (type, tmpl, init, flags, complain);
 
+  if (TREE_TYPE (init) == NULL_TREE)
+/* Nothing we can do with this, even in deduction context.  */
+return type;
+
   /* [dcl.spec.auto]: Obtain P from T by replacing the occurrences of auto
  with either a new invented type template parameter U or, if the
  initializer is a braced-init-list (8.5.4), with
diff --git a/gcc/testsuite/g++.dg/cpp1z/nontype-auto9.C 
b/gcc/testsuite/g++.dg/cpp1z/nontype-auto9.C
new file mode 100644
index 000..2daa346
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/nontype-auto9.C
@@ -0,0 +1,8 @@
+// PR c++/79556
+// { dg-options -std=c++1z }
+
+template  struct A;
+template  struct B;
+template  struct B {
+  static auto a = A::value;
+};
commit 1eeb6fca6149f32f711ab2b404ce442c4a40b550
Author: Jason Merrill 
Date:   Fri Feb 17 12:46:52 2017 -0500

PR c++/79549 - C++17 ICE with non-type auto template parameter pack

* pt.c (convert_template_argument): Just return an auto arg pack.
(tsubst_template_args): Don't tsubst an auto pack type.

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 093c0f9..04479d4 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -7612,6 +7612,10 @@ convert_template_argument (tree parm,
 
   if (tree a = type_uses_auto (t))
{
+ if (ARGUMENT_PACK_P (orig_arg))
+   /* There's nothing to check for an auto argument pack.  */
+   return orig_arg;
+
  t = do_auto_deduction (t, arg, a, complain, adc_unify, args);
  if (t == error_mark_node)
return error_mark_node;
@@ -11649,8 +11653,11 @@ tsubst_template_args (tree t, tree args, 
tsubst_flags_t complain, tree in_decl)
 new_arg = error_mark_node;
 
   if (TREE_CODE (new_arg) == NONTYPE_ARGUMENT_PACK) {
-TREE_TYPE (new_arg) = tsubst (TREE_TYPE (orig_arg), args,
-  complain, in_decl);
+   if (type_uses_auto (TREE_TYPE (orig_arg)))
+ TREE_TYPE (new_arg) = TREE_TYPE (orig_arg);
+   else
+ TREE_TYPE (new_arg) = tsubst (TREE_TYPE (orig_arg), args,
+   complain, in_decl);
 TREE_CONSTANT (new_arg) = TREE_CONSTANT (orig_arg);
 
 if (TREE_TYPE (new_arg) == error_mark_node)
diff --git a/gcc/testsuite/g++.dg/cpp1z/nontype-auto8.C 
b/gcc/testsuite/g++.dg/cpp1z/nontype-auto8.C
new file mode 100644
index 000..da4c88b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/nontype-auto8.C
@@ -0,0 +1,10 @@
+// PR c++/79549
+// { dg-options -std=c++1z }
+
+template 
+struct meow;
+
+template 
+struct meow { };
+
+meow<1> m;
commit 677e35c07a536344ce8bb74e97a72ab05cdb4da4
Author: Jason Merrill 
Date:   Thu Feb 16 16:31:26 2017 -0500

PR c++/79549 - C++17 ICE with non-type auto template parameter pack

* pt.c (convert_template_argument): Just return an argument pack.
(coerce_template_parameter_pack, template_parm_to_arg)
(extract_fnparm_pack, make_argument_pack, tsubst_template_args)
(tsubst_decl, tsubst, type_unification_real, unify_pack_expansion):
Don't set the type of a NONTYPE_ARGUMENT_PACK.
* parser.c (make_char_string_pack, make_string_pack): Likewise.

diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 060962d..7cba266 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -4150,7 +4150,6 @@ make_char_string_pack (tree value)
 
   /* Build the argument packs.  */
   SET_ARGUMENT_PACK_ARGS (argpack, charvec);
-  TREE_TYPE (argpack) = char_type_node;
 
   TREE_VEC_ELT (argvec, 0) = argpack;
 
@@ -4186,7 +4185,6 @@ make_string_pack (tree value)
 
   /* Build the argument packs.  */
   SET_ARGUMENT_PACK_ARGS (argpack, charvec);
-  TREE_TYPE (argpack) = str_char_type_node;
 
   TREE_VEC_ELT (argvec, 1) =