diff mbox

C++ PATCH for c++/59347 (ICE with ill-formed typedef in template)

Message ID 5307C876.9010003@redhat.com
State New
Headers show

Commit Message

Jason Merrill Feb. 21, 2014, 9:43 p.m. UTC
An earlier patch of mine changed the compiler to retain erroneous 
declarations to provide better error-recovery behavior.  But that's 
causing problems with nested typedefs, so let's not bother in that case.

Tested x86_64-pc-linux-gnu, applying to trunk.
diff mbox

Patch

commit 85cffc1cc3fe706d61a417cf6a1139f546a458e9
Author: Jason Merrill <jason@redhat.com>
Date:   Fri Feb 21 13:59:45 2014 -0500

    	PR c++/59347
    	* pt.c (tsubst_decl) [TYPE_DECL]: Don't try to instantiate an
    	erroneous typedef.

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 91a8840..2dc5f32 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -10824,6 +10824,9 @@  tsubst_decl (tree t, tree args, tsubst_flags_t complain)
 	tree type = NULL_TREE;
 	bool local_p;
 
+	if (TREE_TYPE (t) == error_mark_node)
+	  RETURN (error_mark_node);
+
 	if (TREE_CODE (t) == TYPE_DECL
 	    && t == TYPE_MAIN_DECL (TREE_TYPE (t)))
 	  {
diff --git a/gcc/testsuite/g++.dg/template/typedef41.C b/gcc/testsuite/g++.dg/template/typedef41.C
new file mode 100644
index 0000000..dc25518
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/typedef41.C
@@ -0,0 +1,8 @@ 
+// PR c++/59347
+
+template<int> struct A
+{
+  typedef int ::X;		// { dg-error "" }
+};
+
+A<0> a;