[cfe-dev] Examples of FriendTemplateDecl ?

John McCall rjmccall at apple.com
Mon Feb 15 01:19:57 PST 2010

On Feb 15, 2010, at 12:18 AM, Enea Zaffanella wrote:
> Hello.
> In the documentation of AST class FriendTemplateDecl it is said:
> 01221 /// Declaration of a friend template.  For example:
> 01222 ///
> 01223 /// template <typename T> class A {
> 01224 ///   friend class MyVector<T>; // not a friend template
> 01225 ///   template <typename U> friend class B; // friend template
> 01226 ///   template <typename U> friend class Foo<T>::Nested; // friend 
> template
> I tried the examples above and, as far as I can see, clang generates no 
> FriendTemplateDecl node at all.
> For the first friend template declaration
>     template <typename U> friend class B;
> it seems that a "normal" FriendDecl node is produced, containing a 
> NamedDecl node (shouldn't we get a Type node?), which is a 
> ClassTemplateDecl.
> For the second frined template declaration
>     template <typename U> friend class Foo<T>::Nested;
> we still obtain a "normal" FriendDecl node, but this time the node 
> contains a Type node (an ElaborateType). In this case there is no list 
> of template parameters.
> Is this a known issue or should we file a bug?
> Are there other examples where clang actually generates a 
> FriendTemplateDecl node?

I would not be surprised to hear than nothing is actually generating a friend template decl right now.  Friend declarations were hacked together to be good enough to support finding friend functions through ADL, but no better.  All the friend declaration classes are going to be reworked in the next few months as we start needing them for access control.

Put another way:  I would not recommend writing any code which relies on the current representation of friends, because that representation is known to be unsatisfactory and is scheduled to soon see large changes.


More information about the cfe-dev mailing list