Improve deduction failure diagnostics.
authorJason Merrill <jason@redhat.com>
Sat, 31 Oct 2015 16:19:50 +0000 (12:19 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Sat, 31 Oct 2015 16:19:50 +0000 (12:19 -0400)
* pt.c (unify): Don't diagnose no common base if we already have
the same template.
(do_auto_deduction): Explain deduction failure.

From-SVN: r229627

gcc/cp/ChangeLog
gcc/cp/pt.c
gcc/testsuite/g++.old-deja/g++.pt/explicit77.C

index a995242621fd7eb2b9b3dc12d54c3f4850f8f9f4..592eb5d13da5662cbf7de5e1038c81fbda8f2f5c 100644 (file)
@@ -1,5 +1,9 @@
 2015-10-31  Jason Merrill  <jason@redhat.com>
 
+       * pt.c (unify): Don't diagnose no common base if we already have
+       the same template.
+       (do_auto_deduction): Explain deduction failure.
+
        * pt.c (hash_tmpl_and_args): Use iterative_hash_object on template
        uid.
 
index 243464dbb88b893e2cfb9bb3c7e450d4a23fc893..c6ef2f5906ed6d89ad3210d4bddc4fa57c9217ba 100644 (file)
@@ -19633,7 +19633,16 @@ unify (tree tparms, tree targs, tree parm, tree arg, int strict,
                                         explain_p, &t);
 
                  if (!t)
-                   return unify_no_common_base (explain_p, r, parm, arg);
+                   {
+                     /* Don't give the derived diagnostic if we're
+                        already dealing with the same template.  */
+                     bool same_template
+                       = (CLASSTYPE_TEMPLATE_INFO (arg)
+                          && (CLASSTYPE_TI_TEMPLATE (parm)
+                              == CLASSTYPE_TI_TEMPLATE (arg)));
+                     return unify_no_common_base (explain_p && !same_template,
+                                                  r, parm, arg);
+                   }
                }
            }
          else if (CLASSTYPE_TEMPLATE_INFO (arg)
@@ -23500,6 +23509,9 @@ do_auto_deduction (tree type, tree init, tree auto_node,
                error ("unable to deduce lambda return type from %qE", init);
              else
                error ("unable to deduce %qT from %qE", type, init);
+             type_unification_real (tparms, targs, parms, &init, 1, 0,
+                                    DEDUCE_CALL, LOOKUP_NORMAL,
+                                    NULL, /*explain_p=*/true);
            }
          return error_mark_node;
        }
index b97c1cd02237a75528c768f6711ea3f5ffeb75a0..d79ee7f05e5c6ea4c6766f10fb398e733a51a2dc 100644 (file)
@@ -15,5 +15,5 @@ void g() {
   
   f<0>(s0, s2);
   f(s0, s2); // { dg-error "" } no matching function
-  // { dg-message "(candidate|deduced conflicting types|ambiguous base class)" "candidate note" { target *-*-* } 17 }
+  // { dg-message "(candidate|deduced conflicting|ambiguous base class)" "candidate note" { target *-*-* } 17 }
 }