re PR c++/84768 (ICE with failed class template argument deduction because of invalid...
authorPaolo Carlini <paolo.carlini@oracle.com>
Tue, 3 Apr 2018 17:53:05 +0000 (17:53 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Tue, 3 Apr 2018 17:53:05 +0000 (17:53 +0000)
/cp
2018-04-03  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/84768
* pt.c (rewrite_template_parm): If the first argument is
error_mark_node return it immediately.
(build_deduction_guide): Check the return value of the
latter for error_mark_node.
(do_class_deduction): Check the return value of the latter.

/testsuite
2018-04-03  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/84768
* g++.dg/cpp1z/class-deduction52.C: New.

From-SVN: r259049

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

index 8759dc26642e4d62d94e7a0d1a42e374980d8fdf..505b2257be294d1c87041081cdda3df25c2511c1 100644 (file)
@@ -1,3 +1,12 @@
+2018-04-03  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/84768
+       * pt.c (rewrite_template_parm): If the first argument is
+       error_mark_node return it immediately.
+       (build_deduction_guide): Check the return value of the
+       latter for error_mark_node.
+       (do_class_deduction): Check the return value of the latter.
+
 2018-04-03  Jason Merrill  <jason@redhat.com>
 
        * semantics.c (finish_if_stmt_cond): Use
index 4c0d298cfcc58af357af92a48a43ff51f2569f2d..80670a4826b6ebe73a03f4518e9162b04a16c791 100644 (file)
@@ -25834,6 +25834,9 @@ static tree
 rewrite_template_parm (tree olddecl, unsigned index, unsigned level,
                       tree tsubst_args, tsubst_flags_t complain)
 {
+  if (olddecl == error_mark_node)
+    return error_mark_node;
+
   tree oldidx = get_template_parm_index (olddecl);
 
   tree newtype;
@@ -25969,6 +25972,7 @@ build_deduction_guide (tree ctor, tree outer_args, tsubst_flags_t complain)
   else
     {
       ++processing_template_decl;
+      bool ok = true;
 
       fn_tmpl
        = (TREE_CODE (ctor) == TEMPLATE_DECL ? ctor
@@ -26039,6 +26043,8 @@ build_deduction_guide (tree ctor, tree outer_args, tsubst_flags_t complain)
              tree olddecl = TREE_VALUE (oldelt);
              tree newdecl = rewrite_template_parm (olddecl, index, level,
                                                    tsubst_args, complain);
+             if (newdecl == error_mark_node)
+               ok = false;
              tree newdef = tsubst_template_arg (TREE_PURPOSE (oldelt),
                                                 tsubst_args, complain, ctor);
              tree list = build_tree_list (newdef, newdecl);
@@ -26060,7 +26066,10 @@ build_deduction_guide (tree ctor, tree outer_args, tsubst_flags_t complain)
 
          current_template_parms = save_parms;
        }
+
       --processing_template_decl;
+      if (!ok)
+       return error_mark_node;
     }
 
   if (!memtmpl)
@@ -26187,6 +26196,8 @@ do_class_deduction (tree ptype, tree tmpl, tree init, int flags,
   for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (type)); iter; ++iter)
     {
       tree guide = build_deduction_guide (*iter, outer_args, complain);
+      if (guide == error_mark_node)
+       return error_mark_node;
       if ((flags & LOOKUP_ONLYCONVERTING)
          && DECL_NONCONVERTING_P (STRIP_TEMPLATE (guide)))
        elided = true;
@@ -26238,6 +26249,8 @@ do_class_deduction (tree ptype, tree tmpl, tree init, int flags,
       if (gtype)
        {
          tree guide = build_deduction_guide (gtype, outer_args, complain);
+         if (guide == error_mark_node)
+           return error_mark_node;
          cands = lookup_add (guide, cands);
        }
     }
index 70fd513d469c18db49dba587b68e61eea85c435f..220fd8f3e8dbfa3ff3e3d171eaf627a7c0dc02c9 100644 (file)
@@ -1,3 +1,8 @@
+2018-04-03  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/84768
+       * g++.dg/cpp1z/class-deduction52.C: New.
+
 2018-04-03  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/85147
diff --git a/gcc/testsuite/g++.dg/cpp1z/class-deduction52.C b/gcc/testsuite/g++.dg/cpp1z/class-deduction52.C
new file mode 100644 (file)
index 0000000..db786ce
--- /dev/null
@@ -0,0 +1,11 @@
+// PR c++/84768
+// { dg-additional-options -std=c++17 }
+
+template<typename> struct A {};
+
+template<typename T> struct B
+{
+  template<X Y> B(A<T>);  // { dg-error "declared" }
+};
+
+B b = A<void>();