C++0x: Mangling for variadic templates

Doug Gregor doug.gregor at gmail.com
Mon Jul 2 19:17:44 UTC 2007


Variadic templates are a part of the latest C++0x working paper. In
essence, variadic templates just allow one to write templates that
accept an arbitrary number of template arguments. This is handled
through a special type of template parameter called a "template
parameter pack", which binds to one or more template arguments.

GCC currently uses vendor extensions to mangle variadic templates, but
since no compiler with that mangling has been released, we can easily
standardize on something now. You can learn about variadic templates
here:

  http://www.generic-programming.org/~dgregor/cpp/variadic-templates.html

Or read the proposal here:

  http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2080.pdf

The only concern for mangling variadic templates is in mangling "pack
expansions", which essentially provide a pattern that will be expanded
several times, once for each argument bound to the parameter packs
used in the expansion. There are three places where this affects the
mangling:

  <type> ::= Dp <type>  # pack expansion of (C++0x)

That's a pack expansion of a type. It can show up in a function's
parameter type or in a template argument list.

Pack expansions can also show up to expand expression patterns in a
template argument list:

  <template-arg> ::= sp <expression>            # pack expansion of (C++0x)

Finally, there is a sizeof...(X) operator that returns the length of a
parameter pack X.

  <expression> ::= sZ <template-param>

It's an <expression>, not an <operator-name>, because the argument is
always a template parameter (type, non-type, or template).

A patch for the ABI document is attached.

  - Doug
-------------- next part --------------
A non-text attachment was scrubbed...
Name: variadic.patch
Type: application/octet-stream
Size: 4754 bytes
Desc: not available
URL: <http://sourcerytools.com/pipermail/cxx-abi-dev/attachments/20070702/4cd2e0ea/attachment.obj>


More information about the cxx-abi-dev mailing list