This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PR c++/20028, obvious, RFA3.4] crash on use of template that redeclares class

The problem here was that we failed to set TYPE_SIZE_UNIT for the
template type.  We end up overriding the Foo non-template definition
with the given template definition, but since it's regarded as a
non-template, it never gets instantiated, and so TYPE_SIZE_UNIT
remains NULL.  Every time we set TYPE_SIZE to non-NULL, we have to set
TYPE_SIZE_UNIT accordingly; this was the only missing paired
assignment I could find.

I have second thoughts on the wisdom of using a template class
definition as a non-template, but I can see it can be a win in some
cases, so I'm leaving that alone, and just avoiding the crash by
making sure TYPE_SIZE_UNIT is initialized with some reasonable value.
What the exact value is shouldn't matter too much, since we've already
issued errors when we get to that point.

I'm checking this in mainline as obvious.  Tested in x86_64-linux-gnu
for mainline.  Ok for 3.4, if it applies?  It is a regression from 3.3

Index: gcc/cp/ChangeLog
from  Alexandre Oliva  <>
	PR c++/20028
	* class.c (finish_struct): Initialize TYPE_SIZE_UNIT of a
	template along with TYPE_SIZE.

Index: gcc/cp/class.c
RCS file: /cvs/gcc/gcc/gcc/cp/class.c,v
retrieving revision 1.705
diff -u -p -r1.705 class.c
--- gcc/cp/class.c 15 Feb 2005 19:39:26 -0000 1.705
+++ gcc/cp/class.c 17 Feb 2005 19:11:53 -0000
@@ -5111,6 +5111,7 @@ finish_struct (tree t, tree attributes)
       finish_struct_methods (t);
       TYPE_SIZE (t) = bitsize_zero_node;
+      TYPE_SIZE_UNIT (t) = size_zero_node;
       /* We need to emit an error message if this type was used as a parameter
 	 and it is an abstract type, even if it is a template. We construct
Index: gcc/testsuite/ChangeLog
from  Alexandre Oliva  <>
	PR c++/20028
	* g++.dg/template/crash34.C: New.

Index: gcc/testsuite/g++.dg/template/crash34.C
RCS file: gcc/testsuite/g++.dg/template/crash34.C
diff -N gcc/testsuite/g++.dg/template/crash34.C
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gcc/testsuite/g++.dg/template/crash34.C 17 Feb 2005 19:12:07 -0000
@@ -0,0 +1,12 @@
+// { dg-do compile }
+// PR c++/20028
+// We used to crash when referencing TYPE_SIZE_UNIT of the messed-up
+// type used for x, because it was not initialized.
+class Foo;
+template <typename T> class Foo { }; // { dg-error "not a template type" }
+Foo<int> x; // { dg-error "not a template" }
Alexandre Oliva   
Red Hat Compiler Engineer   aoliva@{,}
Free Software Evangelist  oliva@{,}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]