This is the mail archive of the gcc-patches@gcc.gnu.org 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]

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


On Feb 17, 2005, Alexandre Oliva <aoliva@redhat.com> wrote:

> 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

Here's the tested backport of the patch for 3.4.  In 3.4, we don't
actually crash, we just bail out confused by earlier errors, so we
could do without it, but it still feels better to recover and
proceed, so...  Ok for 3.4?

Index: gcc/cp/ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/ChangeLog,v
retrieving revision 1.3892.2.200
diff -u -p -r1.3892.2.200 ChangeLog
--- gcc/cp/ChangeLog	14 Feb 2005 19:00:22 -0000	1.3892.2.200
+++ gcc/cp/ChangeLog	17 Feb 2005 19:38:12 -0000
@@ -1,3 +1,9 @@
+2005-02-17  Alexandre Oliva  <aoliva@redhat.com>
+
+	PR c++/20028
+	* class.c (finish_struct): Initialize TYPE_SIZE_UNIT of a
+	template along with TYPE_SIZE.
+
 2005-02-14  Mark Mitchell  <mark@codesourcery.com>
 
 	* decl.c (reshape_init): Use explicit quotes in error message
Index: gcc/cp/class.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/class.c,v
retrieving revision 1.595.4.9
diff -u -p -r1.595.4.9 class.c
--- gcc/cp/class.c	12 Aug 2004 18:04:54 -0000	1.595.4.9
+++ gcc/cp/class.c	17 Feb 2005 19:38:17 -0000
@@ -1,6 +1,7 @@
 /* Functions related to building classes and their related objects.
    Copyright (C) 1987, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
-   1999, 2000, 2001, 2002, 2003, 2004  Free Software Foundation, Inc.
+   1999, 2000, 2001, 2002, 2003, 2004, 2005
+     Free Software Foundation, Inc.
    Contributed by Michael Tiemann (tiemann@cygnus.com)
 
 This file is part of GCC.
@@ -5217,6 +5218,7 @@ finish_struct (tree t, tree attributes)
     {
       finish_struct_methods (t);
       TYPE_SIZE (t) = bitsize_zero_node;
+      TYPE_SIZE_UNIT (t) = size_zero_node;
     }
   else
     finish_struct_1 (t);
Index: gcc/testsuite/ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/ChangeLog,v
retrieving revision 1.3389.2.363
diff -u -p -r1.3389.2.363 ChangeLog
--- gcc/testsuite/ChangeLog	16 Feb 2005 23:07:37 -0000	1.3389.2.363
+++ gcc/testsuite/ChangeLog	17 Feb 2005 19:38:27 -0000
@@ -1,3 +1,8 @@
+2005-02-17  Alexandre Oliva  <aoliva@redhat.com>
+
+	PR c++/20028
+	* g++.dg/template/crash34.C: New.
+
 2005-02-16  Eric Christopher  <echristo@redhat.com>
 
 	PR preprocessor/19077
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:38:27 -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             http://www.ic.unicamp.br/~oliva/
Red Hat Compiler Engineer   aoliva@{redhat.com, gcc.gnu.org}
Free Software Evangelist  oliva@{lsd.ic.unicamp.br, gnu.org}

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