C++ PATCH for c++/84080, ICE with return type deduction and specialization

Message ID CADzB+2k0xCr1qSp5gV7x22xgXUCkQHwK5ruBQ0KFCOudbOOyRg@mail.gmail.com
State New
Headers show
Series
  • C++ PATCH for c++/84080, ICE with return type deduction and specialization
Related show

Commit Message

Jason Merrill Feb. 13, 2018, 3:56 p.m.
In this testcase, we were deducing T to be auto, which is nonsensical.

Tested x86_64-pc-linux-gnu, applying to trunk.
commit e8579febf0ce4e02b6b9c447c0f3adec56c66abc
Author: Jason Merrill <jason@redhat.com>
Date:   Tue Feb 13 10:09:38 2018 -0500

            PR c++/84080 - ICE with return type deduction and specialization.
    
            * pt.c (determine_specialization): Check uses_template_parms.

Patch

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 02d448e99b6..222084df4cb 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -2203,6 +2203,11 @@  determine_specialization (tree template_id,
 	       specialize TMPL will produce DECL.  */
 	    continue;
 
+	  if (uses_template_parms (targs))
+	    /* We deduced something involving 'auto', which isn't a valid
+	       template argument.  */
+	    continue;
+
           /* Remove, from the set of candidates, all those functions
              whose constraints are not satisfied. */
           if (flag_concepts && !constraints_satisfied_p (fn, targs))
diff --git a/gcc/testsuite/g++.dg/cpp1y/auto-fn47.C b/gcc/testsuite/g++.dg/cpp1y/auto-fn47.C
new file mode 100644
index 00000000000..7de2d9f9e5c
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/auto-fn47.C
@@ -0,0 +1,6 @@ 
+// PR c++/84080
+// { dg-do compile { target c++14 } }
+
+template <int i, typename T> T foo();
+
+template <> auto foo<0>() { return 42; } // { dg-error "does not match" }