[cxx-abi-dev] sizeof pack mangling vs alias templates

Richard Smith richardsmith at google.com
Mon Aug 4 03:31:44 UTC 2014


Alias templates allow the production of new forms of sizeof... for which we
have no specified mangling. Example:

struct A {
  template<typename...T> using N = int[sizeof...(T)];
  template<typename...A, typename B, typename...C>
      void f(N<A..., B, C...> &, B, C...);
};
void g(A a) { int arr[6]; a.f<int, int>(arr, 1, 2, 3, 4); }

No implementation I have access to produces anything reasonable here:

Clang currently produces a bogus RA3_i mangling for the type of the first
parameter.
GCC produces RAstDpT__i, that is, sizeof-type applied to pack expansion
applied to template-parameter-0, which seems to be exposing a detail of
their internal representation, and is in any case wrong since T_ is not
enough to specify which packs are relevant.
EDG rejects.

Also of note: through alias templates, arbitrary template argument
expressions can be incorporated into such a sizeof... expression (as can an
implicit test that multiple packs are the same length), so it's not
sufficient to merely encode a sequence of packs whose sizes should be
added, along with an additional constant for packs of known size.

Suggestion: extend the existing

  sZ <template-param>
  sZ <function-param>

with

  sZ J <template-arg>* E

for the case of a sizeof... that cannot be expressed as sizeof...(T). So
the above parameter would mangle as

sZ J DpT_ T0_ DpT1_ E

I've implemented this, and it seems to work fine. Does this seem OK?


(Minor bug noticed in passing: template-args uses <template-arg>+ where it
means <template-arg>*)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://sourcerytools.com/pipermail/cxx-abi-dev/attachments/20140803/3ea454a4/attachment.html>


More information about the cxx-abi-dev mailing list