https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86876

            Bug ID: 86876
           Summary: friend typedef'ed class in template class can not
                    compile
           Product: gcc
           Version: 7.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rockeet at gmail dot com
  Target Milestone: ---

// code:
#include <stdio.h>
template<class T>
struct A {
    template<class U>
    struct X {
        void foo(U* p) { printf("p->a = %d\n", p->a); }
    };
};
template<class T>
struct B {
    typedef typename A<T>::template X<B<T> > X;
//  friend typename    X; // g++ fail
    friend typename B::X; // g++ ok
private:
    int a = 1234;
};
int main() {
    B<int> a;
    B<int>::X().foo(&a);
    return 0;
}

/*
 Compile error:
template_friend.cpp:12:21: error: expected nested-name-specifier before ‘X’
  friend typename    X; // g++ fail
                     ^
template_friend.cpp:12:21: error: ‘X’ is neither function nor member function;
cannot be declared friend
template_friend.cpp:12:21: error: ‘int B<T>::X’ conflicts with a previous
declaration
template_friend.cpp:11:43: note: previous declaration ‘typedef typename
A<T>::X<B<T> > B<T>::X’
  typedef typename A<T>::template X<B<T> > X;
                                           ^
template_friend.cpp: In instantiation of ‘void A<T>::X<U>::foo(U*) [with U =
B<int>; T = int]’:
template_friend.cpp:19:20:   required from here
template_friend.cpp:6:45: error: ‘int B<int>::a’ is private within this context
   void foo(U* p) { printf("p->a = %d\n", p->a); }
                                          ~~~^
template_friend.cpp:15:10: note: declared private here
  int a = 1234;
          ^~~~
*/

Reply via email to