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

David Vandevoorde daveed at edg.com
Mon Aug 4 13:50:52 UTC 2014


On Aug 3, 2014, at 11:31 PM, Richard Smith <richardsmith at google.com> wrote:

> 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?


It looks reasonable.  Any motivation for choosing "sZJ"?  Could we use a two-letter code instead?  E.g., "sP <template-arg>* E"?

	Daveed


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://sourcerytools.com/pipermail/cxx-abi-dev/attachments/20140804/77a6fa84/attachment.html>


More information about the cxx-abi-dev mailing list