This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
PATCH for template typedef crash
- To: Jason Merrill <jason at cygnus dot com>
- Subject: PATCH for template typedef crash
- From: Mark Mitchell <mmitchell at usa dot net>
- Date: Mon, 4 May 1998 22:32:08 -0700
- Cc: egcs-bugs at cygnus dot com
- Reply-to: mmitchell at usa dot net
Jason --
Here's a bug to fix crashes in templates introduced via the new
treat-typedefs-as-first-class types change. The test case is too
large too post; it involves memory corruption deep in template
instantiation, but I believe the changes are self-explanatory. Is
this OK?
--
Mark Mitchell <mmitchell@usa.net>
http://home.earthlink.net/~mbmitchell
Consulting Services Available
Mon May 4 10:01:48 1998 Mark Mitchell <mmitchell@usa.net>
* decl.c (grokdeclarator): Allocate TYPE_DECLS for template
functions on the permanent obstack.
Index: cp/decl.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/decl.c,v
retrieving revision 1.99
diff -c -p -r1.99 decl.c
*** decl.c 1998/05/03 02:30:56 1.99
--- decl.c 1998/05/04 15:57:30
*************** grokdeclarator (declarator, declspecs, d
*** 9403,9412 ****
if (IS_SIGNATURE (current_class_type) && opaque_typedef)
SIGNATURE_HAS_OPAQUE_TYPEDECLS (current_class_type) = 1;
}
- else if (current_lang_name == lang_name_java)
- decl = build_lang_decl (TYPE_DECL, declarator, type);
else
! decl = build_decl (TYPE_DECL, declarator, type);
/* If the user declares "struct {...} foo" then `foo' will have
an anonymous name. Fill that name in now. Nothing can
--- 9403,9438 ----
if (IS_SIGNATURE (current_class_type) && opaque_typedef)
SIGNATURE_HAS_OPAQUE_TYPEDECLS (current_class_type) = 1;
}
else
! {
! /* Unfortunately, we have to allocate the DECL on the
! permanent obstack if processing_template_decl. Consider
! the following:
!
! template <class T>
! void f()
! {
! typedef S<T> Type_t;
! Type_t::foo();
! }
!
! Here, we will create a SCOPE_REF with Type_t as its first
! argument, and save the SCOPE_REF for later, so that we
! can tsubst into it. But, that means we need to save the
! TYPE_DECL for Type_t. Another fix would be to mandate
! that on creation of a SCOPE_REF we use the original type
! (S<T> in this case) rather than the typedef'd equivalent. */
! if (processing_template_decl)
! push_obstacks (&permanent_obstack, &permanent_obstack);
!
! if (current_lang_name == lang_name_java)
! decl = build_lang_decl (TYPE_DECL, declarator, type);
! else
! decl = build_decl (TYPE_DECL, declarator, type);
!
! if (processing_template_decl)
! pop_obstacks ();
! }
/* If the user declares "struct {...} foo" then `foo' will have
an anonymous name. Fill that name in now. Nothing can