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

            Bug ID: 65619
           Summary: friend declaration with template template parameter
                    not recognized
           Product: gcc
           Version: 4.9.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: nathanm at outlook dot de

The following code:
template <class>
class foo
{
    int i;

    template <template <class> class T>
    friend foo<T<int>> func();
};

template <template <class> class T>
foo<T<int>> func()
{
    foo<T<int>> f;
    f.i = 3;
    return f;
}

template <class>
struct test {};

int main()
{
    func<test>();
}
does not compile with g++ 4.9.2. It is as far as I can tell, valid C++ code and
does compile with clang.
The error message is:
prog.cpp: In instantiation of 'foo<T<int> > func() [with T = test]':
prog.cpp:23:13:   required from here
prog.cpp:4:6: error: 'int foo<test<int> >::i' is private
  int i;
      ^
prog.cpp:14:6: error: within this context
  f.i = 3;
      ^
Changing the code, so T isn't a template template parameter any more makes it
compile. Also changing the return value to void.

Reply via email to