Bug in g++ error report function

Kriang Lerdsuwanakij lerdsuwa@scf-fs.usc.edu
Fri Sep 19 21:11:00 GMT 1997


Hi,

I found a bug in g++ (both egcs-970917 and gcc-2.7.2.2).  The dump_decl
function causes segmentation fault when it is generating error message
for templates with missing identifiers in template parameter list.  For
example:
	template <class T, class> ...

Here is a simple test code:

template <class> class C
{
};

int main ()
{
	C<1> a;
}

Error message before the patch:

err.cc: In function `int main()':
err.cc:8: Internal compiler error.
err.cc:8: Please submit a full bug report to `egcs-bugs@cygnus.com'.

After the patch:

err.cc: In function `int main()':
err.cc:8: type/value mismatch at argument 0 in template parameter list
for `template <class {anon}> class C'
err.cc:8:   expected a type, got `1'

I also changed the error message from

	`template <class > C<{anonymous template type parm}>'

which has the parameter list shown twice to

	`template <class {anon}> class C'


Kriang

--

Fri Sep 19 20:29:13 1997  Kriang Lerdsuwanakij  <lerdsuwa@scf.usc.edu>

* error.c (dump_decl): Don't crash when template parameter has no 
identifier.  Clean up error message for class templates.

--- cp-old/error.c	Fri Sep 19 17:48:24 1997
+++ cp/error.c	Fri Sep 19 20:29:13 1997
@@ -740,7 +740,10 @@
 		if (TREE_CODE (arg) == TYPE_DECL)
 		  {
 		    OB_PUTS ("class ");
-		    OB_PUTID (DECL_NAME (arg));
+		    if (DECL_NAME (arg))
+		      OB_PUTID (DECL_NAME (arg));
+		    else
+		      OB_PUTS ("{anon}");
 		  }
 		else
 		  dump_decl (arg, 1);
@@ -760,7 +763,12 @@
 	nreverse(orig_args);
 
 	if (TREE_CODE (DECL_TEMPLATE_RESULT (t)) == TYPE_DECL)
-	  dump_type (TREE_TYPE (t), v);
+	  {
+	    OB_PUTCP (aggr_variety (TREE_TYPE (t)));
+	    OB_PUTC (' ');
+	    /* Print class name without the template parameter list */
+	    dump_type (DECL_NAME (t), v);
+	  }
 	else if (TREE_TYPE (t) == NULL_TREE)
 	   my_friendly_abort (353);
 	else switch (NEXT_CODE (t))



More information about the Gcc mailing list