Another place in push_template_decl_real already uses this technique to avoid crashing in import_export_decl.

Tested x86_64-pc-linux-gnu, applying to trunk and 4.7.
commit f9e38d8e08b8602fe0264fd381d97bff495acc32
Author: Jason Merrill <ja...@redhat.com>
Date:   Fri Feb 22 12:52:04 2013 -0500

    	PR c++/40405
    	* pt.c (push_template_decl_real): Set DECL_INTERFACE_KNOWN
    	if we got the wrong number of template parms.

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index a39d114..5ff0821 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -4782,6 +4782,8 @@ push_template_decl_real (tree decl, bool is_friend)
 		  error ("got %d template parameters for %q#T",
 			 TREE_VEC_LENGTH (a), current);
 		error ("  but %d required", TREE_VEC_LENGTH (t));
+		/* Avoid crash in import_export_decl.  */
+		DECL_INTERFACE_KNOWN (decl) = 1;
 		return error_mark_node;
 	      }
 
diff --git a/gcc/testsuite/g++.dg/template/error49.C b/gcc/testsuite/g++.dg/template/error49.C
new file mode 100644
index 0000000..57789a7
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/error49.C
@@ -0,0 +1,10 @@
+// PR c++/40405
+
+template<int, int> struct A
+{
+  static int i;
+};
+
+template<int> int A<0,0>::i = 0; // { dg-error "" }
+
+int j = A<0,0>::i;

Reply via email to