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

John McCall rjmccall at apple.com
Mon Aug 4 20:18:47 UTC 2014


On Aug 4, 2014, at 10:45 AM, Richard Smith <richardsmith at google.com> wrote:
> On 4 August 2014 06:50, David Vandevoorde <daveed at edg.com> wrote:
> 
> 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"?
> 
> I really wanted to replace the existing rules with sZ <template-arg>... but that's backwards-incompatible for function parameter packs and non-type template parameter packs.
> 
> Could we use a two-letter code instead?  E.g., "sP <template-arg>* E"?
> 
> Sure, works for me.
> 
> (And for clarity:
> 
>   template<typename ...T> using N = int[sizeof...(T)];
>   template<typename ...T> void f(N<T...> &);
> 
> ... should use the sZ mangling, not the sP mangling, since by 14.5.7/2, you can redeclare this template as 'f(int (&)[sizeof...(T)])’.)

This looks fine to me.  I’ll commit this in a week if there isn’t any further commentary.

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


More information about the cxx-abi-dev mailing list