diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index abfc86abb8a0fbd845b00153a1a172f1fe9c2b1b..94f0d02e85193004110d3858c2a71e9cdb809a43 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,5 +1,8 @@
 2004-11-24  Mark Mitchell  <mark@codesourcery.com>
 
+	* pt.c (tsubst_function_type): Do not permit function types which
+	return arrays or functions.
+
 	PR c++/18586
 	* parser.c (cp_parser_init_declarator): Do not pop scope twice.
 
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 34fd27b59936cf42b254c719958c8af8ac091762..c171f31b083835b1fa82382c445e156aada3d3df 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -6732,6 +6732,22 @@ tsubst_function_type (tree t,
   return_type = tsubst (TREE_TYPE (t), args, complain, in_decl);
   if (return_type == error_mark_node)
     return error_mark_node;
+  /* The standard does not presently indicate that creation of a
+     function type with an invalid return type is a deduction failure.
+     However, that is clearly analagous to creating an array of "void"
+     or a reference to a reference.  This is core issue #486.  */ 
+  if (TREE_CODE (return_type) == ARRAY_TYPE
+      || TREE_CODE (return_type) == FUNCTION_TYPE)
+    {
+      if (complain & tf_error)
+	{
+	  if (TREE_CODE (return_type) == ARRAY_TYPE)
+	    error ("function returning an array");
+	  else
+	    error ("function returning a function");
+	}
+      return error_mark_node;
+    }
 
   /* Substitute the argument types.  */
   arg_types = tsubst_arg_types (TYPE_ARG_TYPES (t), args,
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index d569fb719fb9e4b7da95b726b46405ab2fea2b2c..f647b33ca03bc96b9378475b4c3945da26d667e7 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,7 @@
 2004-11-24  Mark Mitchell  <mark@codesourcery.com>
 
+	* g++.dg/template/deduce3.C: New test. 
+
 	PR c++/18586
 	* g++.dg/template/crash27.C: New test.