Index: testsuite/g++.dg/template/crash103.C
===================================================================
--- testsuite/g++.dg/template/crash103.C	(revision 0)
+++ testsuite/g++.dg/template/crash103.C	(revision 0)
@@ -0,0 +1,4 @@
+// PR c++/45665
+
+template < typename > struct S;
+void (S <0>::*ptr) (); // { dg-error "type" }
Index: cp/decl.c
===================================================================
--- cp/decl.c	(revision 164279)
+++ cp/decl.c	(working copy)
@@ -8762,6 +8762,8 @@ grokdeclarator (const cp_declarator *declarator,
 	      type = build_memfn_type (type,
 				       declarator->u.pointer.class_type,
 				       memfn_quals);
+	      if (type == error_mark_node)
+		return error_mark_node;
 	      memfn_quals = TYPE_UNQUALIFIED;
 	    }
 
