This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/13495] Friendship to class nested withint a template is broken


------- Additional Comments From giovannibajo at libero dot it  2003-12-27 09:03 -------
It's been clarified by DR180 that the form:

friend class A<T>::B;

is the only allowed. In fact, the name is implicitily a type because of 
the 'class' keyword put in front of it, so a typename is not needed (and it is 
not allowed by syntax either). This has been correctly implemented by the new 
parser in GCC 3.4.

Then you must understand the difference between:

template<class T> class OtherClass {
   friend class A<T>::B;
};

and:

template<class T> class OtherClass {
   template <class Q>
   friend class A<Q>::B;
};

In the first case, you're saying that, for each OtherClass<X>, A<X>::B is a 
friend (only for the same X!). In the second, you're saying that for each 
OtherClass<X>, any A<Y>::B is a friend (for any Y).

Nonetheless, there is indeed a bug in GCC. I propose this testcase:

--------------------------------------------
template<typename T>
class A{
public:
    class B
    {
        void func1(void);
        void func2(void);
    };
};

template<typename Q>
class F1
{
    friend class A<Q>::B;
    enum { foo = 0 };
};

template<typename Q>
class F2
{
    template<typename T>
    friend class A<T>::B;
    enum { foo = 0 };
};

template <typename T>
void A<T>::B::func1(void)
{
    (void)F1<T>::foo;        // OK, A<T>::B is a friend for this T (#1)
    (void)F2<T>::foo;        // OK, any A<K>::B is a friend (#2)
}

template <typename T>
void A<T>::B::func2(void)
{
    (void)F1<double>::foo;   // ERROR, A<double>::T is not a friend (#3)
    (void)F2<double>::foo;   // OK, any A<K>::B is a friend (#4)
}

template class A<void>;
--------------------------------------------

Thus, GCC should emit an error only for #3. Instead it emits an error for #2 
and not for #3. This is clearly a bug (but not a regression, since the previous 
versions of GCC were even more broken wrt friendships to nested classes or 
specializations of templates).

This is a job for Kriang :)


-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
           Keywords|                            |accepts-invalid, rejects-
                   |                            |valid
   Last reconfirmed|0000-00-00 00:00:00         |2003-12-27 09:03:43
               date|                            |
            Summary|Impossible "friend"-ship to |Friendship to class nested
                   |nested template             |withint a template is broken
            Version|3.3                         |3.4.0


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13495


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]