[PATCH] Fix PR c++/32111: ICE declaring destructor as friend

Simon Martin simartin@users.sourceforge.net
Sat Jun 9 21:31:00 GMT 2007


Hello all.

The following invalid snippet currently triggers a segmentation fault:

=== cut here ===
struct A
{
          friend A::~A() {}
};
=== cut here ===

Due to the 'friend' qualifier, 'grokdeclarator' does not turn the
FUNCTION_TYPE for the destructor into a METHOD_TYPE (it does so in
decl.c:8521). As a consequence, 'grokfndecl' believes that the
destructor is a static function, and marks it as such.

When 'start_preparsed_function' is called, it sees a static function,
and therefore (see decl.c:10942) does not set 'current_class_ptr'
properly. We therefore end up calling 'initialize_vtbl_ptrs' with a null
argument in 'begin_function_body', which leads to the ICE.

The attached patch fixes this by resetting 'friendp' for methods that
are declared friend of their own class.

I've successfully regtested it on i386-apple-darwin8.9.1. Is it OK?

Best regards,
Simon

:ADDPATCH c++:

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: CL_32111
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20070609/f0ee41dd/attachment.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: pr32111.patch
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20070609/f0ee41dd/attachment-0001.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: CL_32111_testsuite
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20070609/f0ee41dd/attachment-0002.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: friend5.C
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20070609/f0ee41dd/attachment-0003.ksh>


More information about the Gcc-patches mailing list