C++ PATCH for c++/79294 (ICE with invalid pointer-to-function template argument)

Jason Merrill jason@redhat.com
Fri Feb 3 19:43:00 GMT 2017


In this testcase, if we saw a value-dependent expression we were
leaving its type unchanged, leading to an abort at the end of the
function.  Instead, we should complain about an argument with the
wrong type.

Tested x86_64-pc-linux-gnu, applying to trunk.
-------------- next part --------------
commit 336288e5f6a35f54003b4d16e840cc2fd34bf115
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Feb 1 17:43:12 2017 -0500

            PR c++/79294 - ICE with invalid template argument
    
            * pt.c (convert_nontype_argument_function): Check value-dependence.
            (convert_nontype_argument): Don't check it here for function ptrs.

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index c69c270..4c4941a 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -5966,6 +5966,9 @@ convert_nontype_argument_function (tree type, tree expr,
   if (fn == error_mark_node)
     return error_mark_node;
 
+  if (value_dependent_expression_p (fn))
+    return fn;
+
   fn_no_ptr = strip_fnptr_conv (fn);
   if (TREE_CODE (fn_no_ptr) == ADDR_EXPR)
     fn_no_ptr = TREE_OPERAND (fn_no_ptr, 0);
@@ -6698,8 +6701,7 @@ convert_nontype_argument (tree type, tree expr, tsubst_flags_t complain)
 	/* Null pointer values are OK in C++11.  */
 	return perform_qualification_conversions (type, expr);
 
-      if (!value_dependent_expression_p (expr))
-	expr = convert_nontype_argument_function (type, expr, complain);
+      expr = convert_nontype_argument_function (type, expr, complain);
       if (!expr || expr == error_mark_node)
 	return expr;
     }
@@ -6723,8 +6725,7 @@ convert_nontype_argument (tree type, tree expr, tsubst_flags_t complain)
 	  return NULL_TREE;
 	}
 
-      if (!value_dependent_expression_p (expr))
-	expr = convert_nontype_argument_function (type, expr, complain);
+      expr = convert_nontype_argument_function (type, expr, complain);
       if (!expr || expr == error_mark_node)
 	return expr;
     }
diff --git a/gcc/testsuite/g++.dg/template/error57.C b/gcc/testsuite/g++.dg/template/error57.C
new file mode 100644
index 0000000..f67e0a6
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/error57.C
@@ -0,0 +1,5 @@
+// PR c++/79294
+
+template <int()> struct a;
+template <int(b)> a < b		// { dg-error "int" }
+// { dg-error "expected" "" { target *-*-* } .-1 }


More information about the Gcc-patches mailing list