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]

Mangling and operator new

The following code causes an ICE in gcc-3.0.3 in write_expression() in

  template <unsigned int> struct helper {};
  template <class T> static void check( helper< sizeof( new T ) > * );

  int main()

The problem occurs whilst trying to mangle the new expression part of
the name of the class

  helper< sizeof( new T ) >

The NEW_EXPR tree node takes three parameters: the placement list (NULL
in this example), the type declarator (a template_type_parm corresponding
to T), and an initializer list (also NULL in this case).  The segfault
occurs when it attempts to recursively call write_expression on the NULL
placement list.

I've looked in the draft Itanium ABI on the codesourcery web page and this
gives no guidance as to how this should be handled.

I have attached a patch which fixes the problem by mangling calls to
new and new[], schematically, as

  <expression> ::= <new operator-name> <placement expression-list>
                           <type> <initializer expression-list>

  <expression-list> ::= <expression>+ _

I'm not particularly keen on this mangling of <expression-list> -- I'd
prefer something like [random lettter] <expression>+ E, but this syntax
doesn't take any new letters, and uses '_' consistently with, say,

The same problem occurs with function calls, although my patch doesn't
address this.  It wouldn't surprise me if there wasn't a similar problem
with delete and delete[], but I haven't yet been able to coax the
compiler into attempting to mangle either of these.

It would be good if this (or a similar) patch could find it's way into
the 3.1 release because there has been a lot of interest in the last
week or so about using this technique to simplify various parts of the
Boost library, which is on the list of real-world applications used to
test gcc.

I have not done a complete bootstrap re-build with the patch applied, nor
have I run the testsuites.

Richard Smith

Attachment: new_mangle.patch
Description: Patch to cp/mangle.c

Description: Test case 1

Description: Test case 2

Description: Test case 3

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