[cfe-dev] Template parameters of friend declarations.
John McCall
rjmccall at apple.com
Fri Jan 25 13:57:57 PST 2013
On Jan 25, 2013, at 9:44 AM, Enea Zaffanella <zaffanella at cs.unipr.it> wrote:
> On 01/23/2013 01:46 PM, Enea Zaffanella wrote:
>> On 01/23/2013 12:16 AM, John McCall wrote:
>>> On Jan 22, 2013, at 3:07 PM, Enea Zaffanella <zaffanella at cs.unipr.it>
>
> [...]
>
>>> These outer template parameter lists can be present for both cases of a
>>> friend declaration:
>>> template <class T> class A<T>::B;
>>> template <class T> void A<T>::B::foo();
>>>
>>> So I don't suggest adding this as ExtInfo in the FriendUnion.
>>> Fortunately,
>>> FriendDecl has no subclasses, and we know how many outer template
>>> parameter lists there are when parsing it, so you can actually just store
>>> the number of parameter lists in the class and tail-allocate the array of
>>> template parameter lists.
>>>
>>> John.
>>
>> For the second case
>>
>> template <class T> friend void A<T>::B::foo();
>>
>> the outer template parameter list(s) are already stored inside the
>> function declaration, namely in the QualifierInfo base class of
>> DeclaratorDecl::ExtInfo.
>>
>> I think that friend *types* are the only cases where these outer
>> template parameter lists are missing. Anyway, tail-allocation as
>> suggested will be fine.
>
> Please find attached a patch for review, including (de-)serialization and pretty printing of the new info attached to friend type declarations. On a second though, we kept the PointerUnion3 approach, which seems to be simpler (at least, to my eyes) when it comes to deserializing the declaration node.
Please do use post-storage. You can look at how the template parameter packs deserialize themselves for an example of how to get the information for how much extra space to allocate; it's really quite straightforward.
John.
More information about the cfe-dev
mailing list